(n)certainties – Columbia – Fall 2008

EM_Main Trajectory

Option Explicit

Call Main()

Sub Main()

Rhino.AddLayer(“Cloud”)
Rhino.CurrentLayer(“Cloud”)

Dim arrPts : arrPts = Rhino.GetObjects(“Select Cloud of Points”,1)
Dim StPt : StPt = Rhino.GetPoint(“Select Starting Point”)
Dim nGen : nGen = Rhino.GetInteger(“Input Number of Generations”)

Call funcTrajectory(arrPts, StPt, nGen, 1)

‘Call Rhino.ObjectLayer(arrPts, Cloud)
‘Rhino.LayerVisible Cloud, False
Call Rhino.HideObjects(arrPts)

Rhino.AddLayer(“Trajectory”)
Rhino.CurrentLayer(“Trajectory”)
Rhino.Command “_CurveThroughPolyline”

Call Rhino.GetObjects(“Select Voronoi1 Points”, 1)
Rhino.AddLayer(“Voronoi1″)
Rhino.CurrentLayer(“Voronoi1″)
Rhino.Command (“Voronoi _enter”)
Rhino.Command(“_Ungroup”)

Call funcVoronoi()

Call Rhino.GetObjects(“Select Voronoi2 Points”, 1)
Rhino.AddLayer(“Voronoi2″)
Rhino.CurrentLayer(“Voronoi2″)
Rhino.Command (“Voronoi”)
Rhino.Command(“_Ungroup”)

End Sub

Function funcTrajectory(arrPts, StPt, nGen, minNGen)

Rhino.AddLayer(“Path”)
Rhino.CurrentLayer(“Path”)

If minNGen < nGen Then

Dim d1 : d2 = funcRnd(5000, 4000)
Dim d2 : d2 = funcRnd(5000, 4000)
Dim AuxLine1 : AuxLine1 = Rhino.AddLine(StPt, array(StPt(0)+d1,StPt(1)+d2,StPt(2)))

Call Rhino.RotateObject(AuxLine1,StPt,funcRnd(200,0))
Dim EndPt1 : EndPt1 = Rhino.CurveEndPoint(AuxLine1)

Dim i, DistTest, ClosestDist, ClosestPt, arrPtsCoord()

ClosestDist = 0

For i = 0 To UBound(arrPts)

ReDim Preserve arrPtsCoord(i) : arrPtsCoord(i) = Rhino.PointCoordinates(arrPts(i))
DistTest = Rhino.Distance(EndPt1, arrPtsCoord(i))

If DistTest = 5 Then

sCrv = Rhino.AddCurve(array(aCtrlPts(0),aCtrlPts(1),aCtrlPts(2),aCtrlPts(3), aCtrlPts(0)))
aptsdiv = Rhino.DivideCurveLength(scrv,200,True)
aptsdiv = Rhino.DivideCurveLength(scrvs(j),200,True)
Else
sCrv = Rhino.AddCurve(array(aCtrlPts(0),aCtrlPts(1),aCtrlPts(2), aCtrlPts(0)))
aptsdiv = Rhino.DivideCurveLength(scrv,200,True)
aptsdiv = Rhino.DivideCurveLength(scrvs(j),200,True)

For k = 0 To UBound(aptsdiv)

aparam = Rhino.CurveClosestPoint(sCrv,aptsdiv(k))
apttemp = Rhino.EvaluateCurve(sCrv,aparam)
scrvmid = Rhino.AddLine(aptsdiv(k), apttemp)
aptmid = Rhino.CurveMidPoint(scrvmid)

Call Rhino.AddPoint(aptmid)
Call Rhino.DeleteObject(scrvmid)

Next
End If
Next

End Function

Function funcRnd(max,min)

Randomize
funcRnd = (max-min)*rnd+min

End Function

Leave a Comment

0 responses so far ↓

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

Leave a Comment