Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5806

Call a recursive function in python as long as a condition is met?

$
0
0

@flokart wrote:

Hi all,

i tried to create a recursive function with python that choose a random point from a nearest points group.
It works but now i want analyze the result and depending on some conditions i want to recall the function.

How can a function can be called again till the conditions is met?

import scriptcontext
import rhinoscriptsyntax as rs
import ghpythonlib.components as gc
import random
import Rhino

visiblept = [startpt]
cullindexin.remove(startpt)



def path(closestpt,cullist):

    # 1
    # choose a random point from nearest points and do this process recursiv
    # store these random points in a list called visiblept
    
    i = gc.ListItem(closestpt,random.choice(closestpt),True)
    visiblept.append(i)
    L = cullist
    L.remove(i)
    P = gc.ClosestPoints(i,L,5)[0]
    
    
    if len(visiblept) <= iterator:
        return path(P,L)

path(closestptin,cullindexin)

# 2
# create a polyline from visiblept and check for self intersection

Curveguid = rs.AddPolyline(visiblept)
Curve = rs.coercecurve(Curveguid)
events = Rhino.Geometry.Intersect.Intersection.CurveSelf(Curve,0.001)


# 3
# if self intersection is True do 1 again till selfintersection is False
# if len(events) > 0:
    # HOW CAN I CALL THE PATH FUNCTION AGAIN

Any help is welcome.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 5806

Trending Articles