GetLength on Bezier Curve


Hi there, was just trying to get the length of a bezier curve inside a GH component. I convert it first to NurbsCurve but it always returns 0. If I output the curve and use the built in GH curve length component it works fine. Here’s the code I’m using, am I doing something wrong? Thank you!

    Dim pt(3) As Point3d
    pt(0) = New Point3d(0, 0, 0)
    pt(1) = New Point3d(1, 0, 0)
    pt(2) = New Point3d(1, 2, 0)
    pt(3) = New Point3d(2, 2, 0)

    Dim bez As New beziercurve(pt)
    Dim crv As Nurbscurve = Nothing
    crv = bez.ToNurbsCurve

    A = crv

(Menno Deij - van Rijswijk) #2

That looks like a bug to me. If I call bez.ToNurbsCurve().ToNurbsCurve() the length is not zero. One call (bez.ToNurbsCurve()) and the curve has zero length.

@dale could you take a look at this?

My C# code, tested in a Rhino command:

Point3d[] pt = new Point3d[4];
pt[0] = new Point3d(0, 0, 0);
pt[1] = new Point3d(1, 0, 0);
pt[2] = new Point3d(1, 2, 0);
pt[3] = new Point3d(2, 2, 0);

BezierCurve bez = new BezierCurve(pt);
NurbsCurve crv = bez.ToNurbsCurve(); // first call to .ToNurbsCurve()

RhinoApp.WriteLine("1. Bezier curve length {0}", crv.GetLength()); // output zero

crv = crv.ToNurbsCurve(); // second call to .ToNurbsCurve()

RhinoApp.WriteLine("2. Bezier curve length {0}", crv.GetLength()); // output non-zero

Guid crvId = doc.Objects.AddCurve(crv);
var obj = doc.Objects.Find(crvId);
var crvFromDoc = obj.Geometry as Curve;

if (null != crvFromDoc)
    RhinoApp.WriteLine("Curve from doc length {0}", crvFromDoc.GetLength());

return Result.Success;

(Dale Fugier) #3

Hi @Steven, @menno: I have confirmed this is a bug - thanks for reporting and our apologies for any inconvenience.

I am fixing the bug in the WIP, but I am unsure it will make it into this week’s release. If not, it will definitely appear in next week’s release.

– Dale


Thanks guys!