IsCircle behaves differently between Rhinoscript and Python


#1

It’s probably something I’m doing wrong, but here it goes anyway:

I have some objects which were created by extracting edgecurves and joining then together. They appear to be circles even though they technically aren’t.

With Rhinoscript, the IsCircle method recognizes these objects as circles, and I can determine a diameter using the CircleRadius method. That’s what I need to do.

In Python, is seems that the IsCircle definition is now stricter, and these objects are not recognized as circles (or even arcs). I need to determine the diameter of these objects, so this is not a good twist.

I will attach a Rhino file and 2 scripts (one Rhinoscript and one Python) for testing. Maybe this change is intentional, and there is a simple workaround?

Thanks,

Dan

IsItACircle.py (344 Bytes)
IsItACircle.rvb (348 Bytes)
Are these circles or not.3dm (74.9 KB)


#2

Hi Dan
I have the same problem from last two months . For me the command is buggy.
Steve can you verify?
Ciao Vittorio


(Dale Fugier) #3

Hi Dan,

These are not circles in that they are not curves that are represented by our internal ON_ArcCurve geometry class.

But, Rhino is capable of detecting whether or not a curve looks enough like a circle that we can obtain circle parameters (e.g. origin, plane, radius). The tolerance used by RhinoScript, when asking Rhino to determine this, is pretty loose (i.e. the document’s tolerance) which is why the What command says they are polycurves and RhinoScript reports them as circles.

Python determines whether or not a curve passes this test with the Rhino.Geometry.Curve.IsCircle function. The default tolerance for this function is pretty tight. There is an override for this that allows you to provide your own tolerance, if needed.


(Steve Baer) #4

So… it sounds like I need to tweak the python function to match the tolerances used by RhinoScript.


#5

Thanks Dale. Is this tolerance override something that I can apply or do I need to wait for a future upgrade?

Thanks,

Dan


(Dale Fugier) #6

I have not tested this, but it should work.

def IsCircleEx(curve_id, segment_index=-1):
    rc = False;
    curve = rhutil.coercecurve(curve_id, segment_index, True)
    if curve is not None:
        tol = rs.UnitAbsoluteTolerance();
        rc = curve.IsCircle(tol);
    return rc;

(Steve Baer) #7

The tolerance addition will be in SR9 (we’re already too close to SR8 to have it included there.)


#8

Great!!

Thanks Dale and Steve.

Dan