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…
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.
-
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?
-
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.
-
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?
- How does all this relate to type hints?
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
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.
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.
Hi @dale ,
I have tried some solutions with C# and Python, but I can’t get it to display “Line-like Curve” or “LineCurve” or “Line” for straight lines. I only get “Curve” or “NurbsCurve” for straight lines.
How can I output that a “Line-like Curve” is a “Line-like Curve” and not a “NurbsCurve”?
Screenshot 1:
Screenshot 2:
GH-File:
CurveType.gh (29.1 KB)
Update:
If I draw a line in Rhino and reference it in Grasshopper, it is recognised as a “Polyline”.
But this does not work with the first line. This does not solve the problem that the other “Line-like Curve” is not recognised as a line.
I found this in the attached Python script, but I don’t understand if this could be a solution, as I am currently mainly scripting in C#:
# Is curve a NurbsCurve that looks like a line?
if not rc:
if isinstance(curve, Rhino.Geometry.NurbsCurve):
rc, polyline = curve.TryGetPolyline()
if rc:
rc = polyline.Count == 2
If there is a solution, I would like to thank in advance.
This works with both line-like curves. I assume that this is a solution. So we can successfully differentiate between these curve types with “.IsPolyline()”:
I’m not sure if this helps, but I didn’t see it mentioned yet: The Curve
class has the following methods (i.e. in addition to IsPolyline
): IsLinear
. IsArc
, IsCircle
, IsEllipse
etc. That might simplify things quite a bit:
240725_CurveTypes_00.gh (10.2 KB)