#1
  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
    ........newEndPt1 = rs.VectorAdd(endPt,vec1)
    ........newEndPt2 = rs.VectorAdd(endPt,vec2)
    ........#Draw a new line between our original line endPt and our new line endPt
    ........line1 = rs.AddLine (endPt,newEndPt1)
    ........line2 = rs.AddLine (endPt,newEndPt2)
    ........#Call our branch function
    ........Branch(line1,ang,scale,minLength)
    ........Branch(line2,ang,scale,minLength)


    It generates a tree successfully. I want to draw a sphere on the end point of each of the final/smallest curves in the script (the point at which the script stops).
    Im having trouble defining those smallest curves.
    How would I go about isolating them so I can find their end point and draw my sphere?
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    As much as I'd love to install rhinopy, my operating system is neither OS/X nor Windows. Have you submitted your question to a rhinopy group?
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo