Is it possible to get the length of a curve (approximately) using Rhino3dm?
I can evaluate the curve no problem, I also have the domain range of the curve, but now need to get the length of the curve. Is this possible using rhino3dm?
I found this in the documentation regarding IsCloseable, which IS part of Rhino3dm. It seems like it is at least crudely calculating the length of the curve, but not outputting it. Is that correct?
I noticed that the domain range of a curve in simple cases is equal to the length, but in many cases it is not.
What other ways of getting the length of the curve would there be, short of literally just evaluating like 100 points along it and getting the approximate length that way?
Hi @seltzdesign ,
Are you using python version of rhino3dm?
In the NET version, there is a curve.TryGetPolyline() method. I imagine it also exists in the python rhino3dm.
Once you get a polyline from it, you can use the polyline.Length property.
I know it is a workaround, but I think you can’t get the length in other way.
Thanks for the reply. I am using the .NET version (or rather I am using vvvv gamma, but in that I use the .NET version of rhino3dm) and tried this exact approach, but it didn’t seem to work. I got an error when using the TryGetPolyline. I need something that works reliably for any curve, really.
Can you attach some example of your curve in a .3dm file please?
Or you don’t know how the curve looks like inside vvvv?
I don’t see why curve.TryGetPolyline() would fail if it is valid.
Yes, sure, I will attach the file. When I passed the curve to TryGetPolyline I get an instance not set error in the next node, which is the polyline.Length. That means TryGetPolyline didn’t output anything.
The curve is a closed nurbs curve.
I will try with some other curves tomorrow and see if its a general thing or something about this curve. If it’s the only way to get the length, but should work, then I’ll spend some time debugging tomorrow.
You need to get Rhino3dm.Geometry.Curve, in order to be able to use the TryGetPolyline method.
Maybe you can create a new interpolated curve by using nurbs curve GrevillePoints() points.
Then make the interpolated curve with Rhino3dm.Geometry.Curve.CreateControlPointCurve and on result of this method call the TryGetPolyline.
I assume the length of this interpolated curve will be slightly different than the length of your initial nurbs curve, but I don’t see any other way how you could get the length.
Thanks so much for the suggestion. I gave it a go, but I think the problem is that CreateControlPointCurve outputs a NurbsCurve again. TryGetPolyline’s success output is false.
Thanks for the effort. I went with a somewhat brute-force method now of just sampling a 100 points along any given curve and measuring the distance between them to get a total.
That’s how that looks in vvvv. Yeah the new(ish) gamma version of vvvv is super nice. Basically you get all the benefits of visual programming like in Grasshopper, but its all just C# code getting compiled on the fly, so its super fast and you can do a ton more like “proper code” stuff like caching, etc.
You can fully use Nuget and use basically any C# project basically without doing anything other than referencing it.
We are using the rhino3dm library extensively to load and save to .3dm and do a few things with geometry coming from Rhino.
Yeah, the new gamma is really quite different to the old vvvv. The old one was basically like Grasshopper. Very simple, but once you get a little more complex everything just slows down. Grasshopper has this even more, because it is doing even more high level things.
This is really why I love working with it. It makes it even more universal than it already was.
Also the new and included FUSE is simply amazing. You are basically doing shader programming, but without the code.
I love Grasshopper to bits, but having things you are working on run at 100fps is so much more satisfying than waiting 10 seconds for a solution to complete. Sure, it can do a lot of things you can’t do with this, but I find between the 2 we can realize pretty much any of the software-based ideas we have without writing code and the challenges that brings along with it.
Yes, I think TryGetPolyline only works if the Curve happens to be a polyline. PointAt should work with all curves.
Since the curves and surfaces we use in our software are created in Rhino anyways, I could also get the length in Rhino and save it as user key or something.
Either way, this sort of brute force method works well enough in our case to get the length. We only need the approximate length and nothing super accurate.