C# CurvatureAt method outputs only 0-vectors

Hello everybody!

Whenever I calculate the curvature via CurvatureAt method in C#, the curvature vector equals 0.

This is my code:

            for (double incr = 0; incr < 1; incr += 0.05)
            {
                Point3d pt = curve.PointAtNormalizedLength(incr);
                curve.ClosestPoint(pt, out double t);
                Vector3d curvature = curve.CurvatureAt(t);
            }

If I do the same calculation with the DerivativeAt method, it works out fine. Why is the CurvatureAt method not working here?

Thanks for your help.
Thomas

Hello
it is a pitty you didn’t post some script because as it works very well, it is hard to tell where is your error.

curve curvature.gh (6.7 KB)

private void RunScript(Curve curve, ref object A, ref object B)
  {
    List<Point3d> pts = new List<Point3d> ();
    List<Vector3d> vts = new List<Vector3d> ();
    for (double incr = 0; incr < 1; incr += 0.05)
    {
      Point3d pt = curve.PointAtNormalizedLength(incr);
      double t = 0.0;
      curve.ClosestPoint(pt, out  t);
      Vector3d curvature = curve.CurvatureAt(t);
      pts.Add(pt);
      vts.Add(curvature);
    }

    A = pts;
    B = vts;
  }
1 Like

I think the for loop could be refactored to directly loop over the curve domain, thus getting rid of some lines of code.

for (double t = curve.Domain.T0; t <= curve.Domain.T1; t += 0.05) {
    Point3d pt = curve.PointAt(t);
    pts.Add(pt);
    Vector3d curvature = curve.CurvatureAt(t);
    vts.Add(curvature);
}

T0 and T1 should be the minimum and maximum of the curve domain.
I haven’t tested this, since I have no clue how the C# component works on macOS. It’s a super weird thing. What does all of this even mean…

Hello Laurent,

thanks for your reply! I now figured out what my problem was. I calculated the Curvature of a NurbsCurve (which should be doable according to NurbsCurve Class). However, it always resulted in zero vectors. Now that I changed the NurbsCurve to be a normal Curve, it works.

Why isn’t it possible to calculate the curvature of NurbsCurves?

It is. Check the documentation. NurbsCurve also has the CurvatureAt method, as it inherits from Curve. If you’re getting a zero vector again, there’s probably a bug in your code.