TryGetCircle fails with PolyCurve of 4 arcs

Well this sure looks like a Circle but Curve.TryGetCircle method (rhino3d.com) says that it is not :frowning:

image
NotACircle.3dm (45.4 KB)

Geometry:
    Valid curve.
    Closed polycurve with 4 curve segments.
      Segment 1:
        Arc
          start = (4.208,4.379,0.000)
          end = (4.458,4.129,0.000)
          center = (4.208,4.129,0.000)
          radius = 0.250
          angle = 90 degrees
      Segment 2:
        Arc
          start = (4.458,4.129,0.000)
          end = (4.208,3.879,0.000)
          center = (4.208,4.129,0.000)
          radius = 0.250
          angle = 90 degrees
      Segment 3:
        Arc
          start = (4.208,3.879,0.000)
          end = (3.958,4.129,0.000)
          center = (4.208,4.129,0.000)
          radius = 0.250
          angle = 90 degrees
      Segment 4:
        Arc
          start = (3.958,4.129,0.000)
          end = (4.208,4.379,0.000)
          center = (4.208,4.129,0.000)
          radius = 0.250
          angle = 90 degrees


This disqualifies the curve from the arc/circle test. The SimplifyCrv command will fix.

This also works:

import Rhino
import scriptcontext as sc

def main():
    filter = Rhino.DocObjects.ObjectType.Curve
    rc, objref = Rhino.Input.RhinoGet.GetOneObject("Select curve", False, filter)
    if not objref or rc != Rhino.Commands.Result.Success:
        return
    
    curve = objref.Curve()
    if not curve:
        return
        
    if isinstance(curve, Rhino.Geometry.PolyCurve):
        curve = curve.ToNurbsCurve()
        
    tol = sc.doc.ModelAbsoluteTolerance
    rc, circle = curve.TryGetCircle(tol)
    print(rc)

if __name__ == "__main__":
    main()        

– Dale

1 Like