ArcCurve from Ellipse

Hi Everyone!

My program converts back and forth between some curves/surfaces and their corresponding primitive shapes, when possible. I am looking for a means of converting an Ellipse back to the ArcCurve it originated from. Is that even possible?

For example, with a circle I would do:

_, circle = curve.TryGetCircle()
curve = ArcCurve(circle)  # this gives me back the original curve

Then for Ellipse:

_, ellipse = curve.TryGetEllipse()
curve = ?

Thanks!
Chen

Hi @Chen_Kasirer,

In Rhino, an Ellipse is represented as degree=2 rational NURBS curve. If a curve has elliptical form but is not closed, then Rhino will report the curve as being an Elliptical Arc.

And unlike arcs and circles, for which there is an ArcCurve class, there is no “ElliipseCurve” class in RhinoCommon. However, if you want to convert back and forth, you can do this:

rc, ellipse = curve.TryGetEllipse()
if rc and ellipse:
    new_curve = ellipse.ToNurbsCurve()

This works too:

rc, ellipse = curve.TryGetEllipse()
if rc and ellipse:
    new_curve = Rhino.Geometry.NurbsCurve.CreateFromEllipse(ellipse)

Hope this helps.

– Dale

Hi @dale!

Thanks for helping me out.

I guess what confuses me is that my ArcCurve “identifies” as an ellipse but not as a circle.
Since both radii are equal, what makes this curve an ellipse rather than a circle? is it just because it’s not closed?

is_circle, circle = curve.TryGetCircle()
is_ellipse, ellipse = curve.TryGetEllipse()
print(curve.__class__)
print("is_circle: {}".format(is_circle))
print("is_ellipse: {} is closed: {}".format(is_ellipse, curve.IsClosed))
print("radius1: {} radius2: {}".format(ellipse.Radius1, ellipse.Radius2))

Outputs:

<type 'ArcCurve'>
is_circle: False
is_ellipse: True is closed: False
radius1: 0.3 radius2: 0.3  

Thanks!
Chen

Use TryGetArc; a circle is closed by definition