Subclassing Rhino.Geometry.Curve

Hello,

I’m trying to write a subclass of Rhino.Geometry.Curve called Airfoil. Essentially, I want Airfoil objects to have all the functionality of Curve but with a few of my methods that are specific to airfoils, like getLeadingEdge, getChord, etc.

One problem I have is converting Curve objects into Airfoil objects. I tried doing an explicit cast like this:

Airfoil airfoil = (Airfoil)Curve.CreateInterpolatedCurve(points, 3);

but I get an invalid cast error.

What would be the best way to do this conversion?

Hi @hkit.yong ,
The Curve.CreateInterpolatedCurve() returns a Curve object, so you cannot explicitly cast it to Airfoil. Inheriting the Curve class might not work. Even if you successfully manage to do it, once you add the Curve to the Rhino Document, it will be just a Curve (not Airfoil).

One way to do it is by inheriting CursomCurveObject, the other way is by using Custom UserData

But as mentioned in this post, using UserData might be a better option.

you can find the sample here

Thanks @Darryl_Menezes! I ended up inheriting NurbsCurve as I only needed to use Curve functionality in some simple scripts and so wasn’t too concerned with preserving Airfoil objects in the Rhino document. Your suggestion was very helpful though, much appreciated!