How to identify if something is a curve, polyline, polycurve, etc

I see in the RhinoCommon API that some things I expect to be curves don’t have inheritance from the Curve class, while others do. Is there a way I can figure out if a curve is a “Line,” “LineCurve,” “PolyCurve,” “Polyline,” “PolylineCurve,” “ArcCurve”?

Depends if you’re going to use code or not…

With just Rhino components, you can plug a bunch of curves into a line component. The output contains only lines but as a downside the line component goes red. So maybe not the solution.

You can count the number of control points the curve has.

A line has two points and the mid point lies on the line between the end points.

A polyline has more than one segment and all segments are linear.

An arc has a center point…

1 Like

Hi @andreaw,

Do you have some code you can share?

– Dale

I guess this is more just, I’m trying to make a good faith effort to understand how the different “types” are related as they are shown to me in Grasshopper and the scripting. There’s a few things that confuse me.

Before I read the RhinoCommon API, I was under the impression that all the 2D curves/lines belonged to a same bigger class, and and that all the other stuff Grasshopper shows as type hints like “Line,” “Circle,” “Arc,” “Polyline,” etc. were subclasses that inherited from it. It’s not immediately obvious to me what hierarchy exists.

  1. Are all curves Rhino.Geometry.NurbsCurves? That is, are Rhino.Geometry.ArcCurves, or Rhino.Geometry.PolyCurves etc. all just subclasses which inherit from it? If not, how are they related? As an informal question - will printing type(x) give me the “most specific” label?

  2. What actually ARE lines? When I try to select curves and put them in a Grasshopper ‘Line’ component, this is a no-go. When I select a line I drew with the Line tool, and try and put them in a Grasshopper ‘Line’ component, this also doesn’t work, and it prompts me to draw a line instead. But when I connect the Line component to the script, it prints it out to show it is a “Rhino.Geometry.LineCurve.” This suggests to me that all lines are curves.

  3. What’s doing thing behind the scenes that gives me the Grasshopper result (yellow panel)? I noticed that it also describes stuff as “Closed” or “Periodic” or “Planar.” I know there are methods in the documentation such as “IsArc,” “IsCircle,” “IsPlanar,” or “IsPolyline” but again am confused about hierarchy. For example, the documentation says,

ArcCurve class Represents arcs and circles. ArcCurve.IsCircle returns True if the curve is a complete circle.

I can individually check if something is an arc, and if its an arc, check if it is a circle, but is that the best way?

  1. How does all this relate to type hints?
1 Like

crvs.3dm (92.4 KB)
line_confusion.gh (17.8 KB)

The files here contain some different curves and lines I drew, to test, as well as the botched Python script.

Hi @andreaw,

A couple of samples to review.

fun-with-curves.gh (6.0 KB)

test_classify_curve.py (3.9 KB)

– Dale

2 Likes

how do i find the ellipse in it which shows as nurbs curve only
@mohammed_dahodwala

See the sample code is test_classify_curve.py, posted above.

1 Like

Hello, I was wondering about the Python script - I understand that it checks if something is a line, if it’s not then if it’s a polyline, if it’s not then if it’s a polycurve, etc. - but I am wondering how Grasshopper identifies something that is like one but isn’t actually.

The top one is the script, the bottom one is what I get when I simply connect the curves to a panel.

:point_up: