I am trying to duplicate the function of Grasshopper’s Discontinuity component with Python/Rhinocommon. (I know I can just script the component, but I’m looking at applications where GH might not be present, like Mac)
I’ve hacked something together that works, but I’m not really sure it’s correct. In particular, how to determine when I’ve found all the discontinuities and break out of the loop. The
GetNextDiscontinuity method returns a tuple with a boolean value and a number (parameter), it’s not explained exactly what the boolean represents, but I noticed it appeared to switch to False when I had found all discontinuities… At this point, it also returns a parameter of “virtual negative infinity” (-1.23432101234321E+308) - funny number! But I don’t know if I’m using the method correctly.
Anyway, code I hacked below… It just creates a square polycurve with two extraneous points which should not be found as discontinuous.
import Rhino import scriptcontext as sc pts= pts.append(Rhino.Geometry.Point3d(0,0,0)) pts.append(Rhino.Geometry.Point3d(5,0,0)) pts.append(Rhino.Geometry.Point3d(10,0,0)) pts.append(Rhino.Geometry.Point3d(10,10,0)) pts.append(Rhino.Geometry.Point3d(5,10,0)) pts.append(Rhino.Geometry.Point3d(0,10,0)) pts.append(Rhino.Geometry.Point3d(0,0,0)) #create a polycurve pc=Rhino.Geometry.PolyCurve() for i in range(len(pts)-1): pc.Append(Rhino.Geometry.Line(pts[i],pts[i+1])) sc.doc.Objects.AddCurve(pc) #find discontinuities dom=pc.Domain cornerParams= t=dom cont=Rhino.Geometry.Continuity.C1_locus_continuous while True: result=pc.GetNextDiscontinuity(cont,t,dom) if not result: break t=result cornerParams.append(t) #add points to see for t in cornerParams: sc.doc.Objects.AddPoint(pc.PointAt(t)) sc.doc.Views.Redraw()