C#: Reconstructing a NURBS Curve from another NURBS Curve's Properties?

hey guys,

i’d like to reconstruct a NURBS curve from another NURBS curve’s properties.

Since NurbsCurve.Create() only asks for rationality, degree and a list of control point locations, this cannot be easily done for e.g. a circle, because (at least) weight information is missing.

How would you completely and safely reconstruct a NURBS curve from its properties like control point locations, rationality, knot vectors, etc?

cheers, Heinz

1 Like

Iv’e asked a similar question not so long ago…it is possible

HI @lungenstrudel,

I am thinking something like this should do it.

public static NurbsCurve CopyNurbsCurve(NurbsCurve src)
{
  if (null == src || !src.IsValid)
    return null;

  var dimension = src.Dimension;
  var order = src.Order;
  var rational = src.IsRational;
  var point_count = src.Points.Count;

  var nc = new NurbsCurve(dimension, rational, order, point_count);
      
  for (var i = 0; i < src.Points.Count; i++)
    nc.Points[i] = src.Points[i];

  for (var i = 0; i < src.Knots.Count; i++)
    nc.Knots[i] = src.Knots[i];

  return nc.IsValid ? nc : null;
}

Does this help?

– Dale

1 Like

Hi @dale ,

I’m having a very similar problem and tried your solution. However, I can’t make it work for a closed curve. Is there an additional step for closed curves that I’m missing?

Thanks,
Thomas

Hi @thomas.gust,

Can you post the curve and the source code that isn’t working for you?

– Dale

I tried to copy a circle, to later be able to generate a deformed one from control points as input. However, the copied curve wasn’t closed and its last section bent outward - very weird behavior. But after a restart of Rhino the problem seems to have disappeared and I can’t reproduce it. So unfortunately I can’t present a picture of my strange results.

Anyway, here is the code I used:
copy_nurbs.py (444 Bytes)