### Thread: Recursive algorithms - Rhino

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Apr 2013
Posts
1
Rep Power
0

#### Recursive algorithms - Rhino

I have made a recursive branching script in Rhino

#Main function - user input calls the recersive function
#def main = main function
def main():
....#Get line object within Rhino interface - User specified
....line = rs.GetObject("Select first branch",4)
....#Get angle within Rhino interface - User specified
....ang = rs.GetReal("Angle of branch",20)
....#Get scale within Rhino interface
....scale = rs.GetReal("Scale of branch",0.9)
....#Define minlength of our branch
....minLength = rs.GetReal("Min length",8)
....#Branch (line, angle, scale, minlength)
....Branch (line,ang,scale,minLength)

#recursive function - Calls itself
def Branch (line, ang, scale, minLength):
....#Get curve length so that we can tell our branching script to stop when it reaches the limit
....length = rs.CurveLength(line)
....#Condition for the script to stop calling itself using minlength
....if length > minLength:
........# If our line length is greater than our minlength then do the following
........#determine the startPt and endPt of the line
........startPt = rs.CurveStartPoint(line)
........#make a vector from the startPt to the endPt
........endPt = rs.CurveEndPoint(line)
........#Make a vector from the startPt to the endPt
........vec = rs.VectorCreate(endPt, startPt)
........#Scale the new vector
........vec = rs.VectorScale(vec,scale)
........#Rotate the new vector
........vec1 = rs.VectorRotate(vec,ang,[0,0,1])
........vec2 = rs.VectorRotate(vec,-ang,[0,0,1])
........#endPt + New Vector 1
........#Add the new vector to the endPt of our 'original' line