(n)certainties/LAB M4

USC / 2010-2011

(n)certainties/LAB M4 header image 3

Irragular spiral growing_to Ani & Zhaochen

Option Explicit
‘Script written by <suqi>
‘Script copyrighted by <suqi>
‘Script version  19:58:56

Call Main()
Sub Main()
Dim arrcircles
arrcircles = Rhino.getobjects(“pick all the circles”,4) ‘ declares arrcircles and prompts to pick the cirles in rhino
Dim arrattractors ‘ declares set of attractor points
arrattractors = Rhino.getobjects(“pick all the attractors”,1)
Dim p
For p = 0 To UBound(arrattractors)
arrattractors(p) = Rhino.pointcoordinates(arrattractors(p))
Next

Dim i ‘ declares variable i
Dim center ‘ declares center
Dim arrcurve ‘ declares arrcurve

Dim arrpoint1
Dim arrpoint2 ‘ declares second point array
Dim arrpoint3 ‘ declares third point array
ReDim arrcurve(UBound(arrcircles))

For i = 0  To UBound (arrcircles) ‘ i equals anywhere from 0 to the amount of circles

Dim a ‘declare a to be a random number multiplied by 55

a = -10 + Rnd * 15
Dim c
c = Rnd*50
center = Rhino.CurveAreaCentroid (arrcircles(i)) ‘declares the center as the center of the circles defined as arrcircles

‘arrcurve(i) = Rhino.Addline(center(0),Rhino.pointadd(center(0),Array(0,0,-a))) ‘ arrcurve adds a line from a starting point at the center and the end point at a in the z axis

arrpoint1 = center(0)
arrpoint2 = Rhino.pointadd(center(0),Array(0,0,c))
arrpoint3 = Rhino.pointadd(arrpoint2,Array(a,a,c))

arrcurve(i)= Rhino.addcurve(Array(arrpoint1,arrpoint2,arrpoint3))

‘ arrcurve adds a curve from an array of points begininng at the center of the cicle then  follows a stochastic trajectory

Next ‘script moves to next set

‘this portion generates a spiral from the curves
‘generated through the arrcircles

Dim j ‘declares return j

‘ bottom portion demonstrates function statement of i

For i = 0  To UBound (arrcircles) ‘ i equals anywhere from 0 to the amount of circles

Dim b ‘ delares the variable b

b =  20 + Rnd * 10 ‘ b is equal to a random number multiplied by 15 and added to 15

‘  If b < 5 Then ‘if b is less than 3 then b will equal 2
‘   b = 5

‘  End If ‘ closes function statement of i

Dim radius ‘ declares radius to be the radius of the arrcirclesselected for the value of i
‘ Dim k
‘  k = 15 + rnd * 10

‘  If k < 2 Then

‘   k = 2

‘ End If

radius = Rhino.CircleRadius(arrcircles(i))

Dim arrpoints ‘ declares arrpoints to divide the line a series of control points governed by the value of i
arrpoints = Rhino.dividecurve(arrcurve(i),CInt(b))

Dim startpoint ‘ declares startpoint (startpoint of a curve)
Dim arrsubcircles ‘ delares arrsubcircles

ReDim arrsubcircles(UBound(arrpoints)) ‘ declares that arrsubcircles is an array of the upper boundry of control points

Dim arrpt1 ‘declares first point array
Dim arrpt2 ‘ declares second point array
Dim arrpt3 ‘ declares third point array

ReDim arrpt1(UBound(arrpoints)) ‘ declares array of points to be placed on the divisions of the curve arrcurve(i)
ReDim arrpt2(UBound(arrpoints)) ‘ declares array of points to be placed on the divisions of the curve arrcurve(i)
ReDim arrpt3(UBound(arrpoints)) ‘ declares array of points to be placed on the divisions of the curve arrcurve(i)

‘ bottom portion demonstrates function statement of J

For j =0 To UBound(arrpoints) ‘ j is defined as the upper limit of the value of arrpoints

Dim strPoncurve
strPoncurve = Rhino.CurveClosestPoint(arrcurve(i), arrPoints(j)) ‘ declares strPoncurve and returns the closest point on the curve to arrcurve(i) and array pointsof j
Dim index,closeattractor, attdistance
index = Rhino.PointArrayClosestPoint(arrattractors,arrpoints(j))
closeattractor = arrattractors(index)
attdistance = Rhino.Distance(closeattractor,arrpoints(j))
Dim strframe
strframe = Rhino.Curveperpframe(arrcurve(i),strPoncurve) ‘ declares strframe and  returns the perpendicular plane at a parameter of arrcurve i and strPoncurve
Dim tang
tang = Rhino.curvetangent(arrcurve(i), strPoncurve) ‘ delcares tang and defines it as a 3d vector that is tangent to the curve arrcurve

Dim t
t = 1+0.3*Rnd
‘set below creates the tube on which are placed by points

arrsubcircles(j) = Rhino.addcircle(strframe,attdistance*0.2)
arrsubcircles(j) = Rhino.RotateObject(arrsubcircles(j),arrpoints(j),25*j,tang)  ‘ reorients the circles to the tanjent vector of the curve
arrpt1(j) = Rhino.curvestartpoint(arrsubcircles(j)) ‘ declares arrpt1 to be the start point at the value of j

Dim domain ‘ declares a domain
domain = Rhino.CurveDomain(arrsubcircles(j)) ‘ defines domain to return the domain of arrsubcircles with the value j

Dim domainlength ‘ declares domain length
domainlength = domain(1) – domain(0) ‘ domain length is equal to the subtraction of the domain arrays

Dim pt2para,pt3para ‘declares pt2para, pt3para

pt2para = domainlength/3 ‘ defines pt2para as the domainlength /3
pt3para = domainlength*2/3 ‘ defines pt2para as the (domainlength * 2)/3

arrpt2(j) = Rhino.EvaluateCurve(arrsubcircles(j),pt2para) ‘EVALUATES CURVE AT reoriented tangent vectors arrsubcircles(j) and the paramter of arrpt2 (arrpnt2para)
arrpt3(j) = Rhino.EvaluateCurve(arrsubcircles(j),pt3para) ‘EVALUATES CURVE AT reoriented tangent vectors arrsubcircles(j) and the paramter of arrpt3 (arrpnt3para)

‘set below reevaluates the curve for arrpoint1, adds a blackck curve into a layer called “spiral”
‘then reevaluates the curve for arrpoints 2 and 3 then deletes the excess curves arrsubcircles
‘then deletes the original straight line arrcurve

Next

Dim interpcurve1

interpcurve1 = Rhino.AddInterpCurve (arrpt1)

Call Rhino.AddLayer(“spiral”,RGB(0,0,0))
Call Rhino.objectlayer(interpcurve1,”spiral”)

Dim interpcurve2

interpcurve2 = Rhino.AddInterpCurve (arrpt2)

Call Rhino.AddLayer(“spiral2″,RGB(0,0,0))
Call Rhino.objectlayer(interpcurve2,”spiral2”)

Dim interpcurve3

interpcurve3 = Rhino.AddInterpCurve (arrpt3)

Call Rhino.AddLayer(“spiral3″,RGB(0,0,0))
Call Rhino.objectlayer(interpcurve3,”spiral3”)

Call Rhino.deleteobjects(arrsubcircles)

Next

Call Rhino.deleteobjects(arrcurve)

End Sub ‘ ends the script