(n)certainties – Columbia – Fall 2008

AN_sweep_tool

Option Explicit
‘Adolfo Nadal -Archiologics

Call Main()
Sub Main()
Dim strObj : strObj = Rhino.GetObject(“obj”,4)
Dim strCrvs : strCrvs = Rhino.GetObjects(“crvs”,4)

Dim arrCtPt : arrCtPt = Rhino.CurveAreaCentroid(strObj)

‘let’s try to get the fckg normal vector to the curve
Dim strdecide: strdecide = Rhino.GetString(“wanna try to select points on your own?”,”yes”,array(“yes”,”no”))
Dim objDom : objDom = CurveDomain(strObj)
Dim xP
Dim yP

If strdecide = “no” Then
xP = Rhino.EvaluateCurve(strObj,0)
yP = Rhino.EvaluateCurve(strObj,(objDom(1)-objDom(0))/4)
Else
arrCtPt(0) = Rhino.GetPoint (“center Pt”)
xP = Rhino.GetPoint(,,”pt 1 on X dir”)
yP = Rhino.GetPoint(,,”pt 1 on Y dir”)
End If

Dim vNormal : vNormal = Rhino.VectorAdd (Rhino.VectorUnitize(Rhino.VectorCrossProduct(xP,yP)),arrCtPt(0))

Dim arrPerpPlane : arrPerpPlane = Rhino.PlaneFromFrame(arrCtPt(0),xP,yP)

‘let’s try to do the same with the curves…
Dim strCrv
Dim crvPt, crvTangent, crvPerp, crvNormal
Dim crvCurvature
Dim t

Dim orientObj()
Rhino.EnableRedraw False
For Each strCrv In strCrvs

Dim crvDom : crvDom = Rhino.CurveDomain(strCrv)

Dim arrStPt : arrStPt = Rhino.CurveStartPoint(strCrv)
Dim arrEnPt : arrEnPt = Rhino.CurveEndPoint(strCrv)
Dim m : m=0

For t =0 To crvDom(1) Step (crvDom(1)-crvDom(0))/2
crvCurvature = Rhino.CurveCurvature(strCrv,t)
If IsNull (crvCurvature) Then
crvPt = Rhino.EvaluateCurve(strCrv,t)
crvTangent = Rhino.VectorUnitize(Rhino.CurveTangent(strCrv,t))
crvPerp = Array(0,0,1)
Else
crvPt = crvCurvature(0)
crvTangent = Rhino.VectorUnitize(crvCurvature(1))
crvPerp = Rhino.VectorUnitize(crvCurvature(4))
End If

crvNormal = Rhino.VectorAdd(Rhino.VectorUnitize(Rhino.VectorCrossProduct(crvTangent,crvPerp)),crvPt)
Dim CrossSectionPlane : CrossSectionPlane = Rhino.PlaneFromFrame(crvPt,crvPerp,crvNormal)
Dim xPtgt : xPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(1)),crvPt)
Dim zPtgt : zPtgt = Rhino.VectorAdd(Rhino.VectorUnitize(CrossSectionPlane(2)),crvPt)

Dim strObj2 : strObj2 = Rhino.CopyObject(strObj,array(0,0,0),array(0,0,0))

‘We orient the object
ReDim Preserve orientObj(m)
orientObj(m) = Rhino.OrientObject (strObj2,array(arrCtPt(0),xP,yP),array(crvPt,xPtgt,crvNormal),1)

‘we scale the object
‘for the scalefactor we need to “unitize” the domain
Dim scalefactor, n
Dim unitize : unitize = crvDom(1)-crvDom(0)
n = 180*(t-crvDom(0))/unitize
Rhino.Print(n)
If n = 0 Or n Mod 180 =0 Then
scalefactor =.5
Else
scalefactor = (1/(2*sin(n)))+1/2
End If

Rhino.ScaleObject orientObj(m),crvPt,array(scalefactor,scalefactor,scalefactor)
Rhino.DeleteObject(strObj2)
m =m+1
Next
Rhino.Command “Sweep1 _SelID ” & strCrv & ” _SelID ” & orientObj(0) & ” _SelID ” & orientObj(1) & ” _SelID ” & orientObj(2) & “_enter _enter Natural enter enter”

Next
Rhino.EnableRedraw True
End Sub

Leave a Comment

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment