Nurbs curve control points transformation

Hi

i’m trying to transform the location of some control points within a nurbs curve.

        Circle cr2 = new Circle(pl1,pt1,1.0);
        NurbsCurve cv2 = NurbsCurve.CreateFromCircle(cr2);
        cv2 = cv2.Rebuild(8, 2, false);

        var dir = new Vector3d(2, 5, 8);
        var xform = Transform.Translation(dir);

        cv2.Points[0].Location.Transform(xform);
        cv2.Points[3].Location.Transform(xform);
        cv2.Points[4].Location.Transform(xform);
        cv2.Points[7].Location.Transform(xform);

        doc.Objects.AddCurve(cv2);
        doc.Views.Redraw();

But the transformation is not happening…
Do i have to “update” the transformed points?

i did try using

cv2.Points.SetPoint()

on the existing curve instead, but ended up with extra points.

thanks!

ControlPoint and Point3d are value-types (struct). That means that you get a copy when you request its value, and not a reference. In other words, you are transforming a copy, without re-assigning the transformed copy. The code below should work.

Circle cr2 = new Circle(pl1, pt1, 1.0);
NurbsCurve cv2 = NurbsCurve.CreateFromCircle(cr2);
cv2 = cv2.Rebuild(8, 2, false);

var dir = new Vector3d(2, 5, 8);
var xform = Transform.Translation(dir);

foreach (var idx in new[] {0, 3, 4, 7})
{
  ControlPoint cp = cv2.Points[idx];
  Point3d at = cp.Location;
  at.Transform(xform);
  cp.Location = at;
  cv2.Points[idx] = cp;
}

doc.Objects.AddCurve(cv2);
doc.Views.Redraw();
1 Like

Hi @menno
thanks for the reply! You are right about the struct thing and now the location is moving.
But i still end up with an open curve and it has 10 control points instead of 8. Same as with the SetPoints. This also happens when i only move one point. I don’t understand this behavior…

If you add the rebuilt curve to the document and use the What command on it, you’ll see the folllowing:

curve  
  
  ID: dacef556-d8b5-4536-999e-49f2fd9b99f9 (56)
  Object name: (not named)
  Layer name: Default
  Render Material: 
    source = from layer
    index = -1
  
  Geometry:
    Valid curve.
    Periodic NURBS curve
      start = (0.997,-0.000,0.000)
      end = (0.997,-0.000,0.000)
      degree = 2
      control points: non-rational, count=10 (2 duplicates)
      knots: uniform (delta=1.000), domain = 0.000 to 8.000

It may look like it has only 8 control points, but there are 2 duplicates.

More information from the List Command:

  
  Rhino object: curve
  DEVELOPER DEBUGGING INFORMATION ONLY
  Use the Rhino "What" command.
  Runtime serial number: 56
  name: ""
  id: DACEF556-D8B5-4536-999E-49F2FD9B99F9
  layer index: 0
  render material index: -1 (from layer)
  ON_NurbsCurve dim = 3 is_rat = 0
          order = 3 cv_count = 10
  Knot Vector ( 11 knots )
  index                     value  mult       delta
      0                       -1     1
      1                        0     1           1
      2                        1     1           1
      3                        2     1           1
      4                        3     1           1
      5                        4     1           1
      6                        5     1           1
      7                        6     1           1
      8                        7     1           1
      9                        8     1           1
     10                        9     1           1
  Control Points  10 non-rational points
    index               value
    CV[ 0] (0.99687394400558749, -0.41291868639861756, 0)
    CV[ 1] (0.99687396098036096, 0.41291864541788414, 0)
    CV[ 2] (0.41291868639861967, 0.99687394400558671, 0)
    CV[ 3] (-0.41291864541788492, 0.99687396098036118, 0)
    CV[ 4] (-0.99687394400558671, 0.41291868639861939, 0)
    CV[ 5] (-0.99687396098036141, -0.4129186454178847, 0)
    CV[ 6] (-0.41291868639861895, -0.99687394400558738, 0)
    CV[ 7] (0.41291864541788526, -0.99687396098036118, 0)
    CV[ 8] (0.99687394400558749, -0.41291868639861756, 0)
    CV[ 9] (0.99687396098036096, 0.41291864541788414, 0)

What you’re looking at is a periodic nurbs curve, in other words, a closed curve “without beginning or end”. This is done using non-multiple knots at the beginning and end and duplicate control points at beginning and end. When you “open” the curve with the transformed control points you will see that the curve does not end at a control point! This is because of the periodic knot values.

1 Like

mhh… i still don’t get why the curve becomes a different type (non periodic) by moving a control point? Or is .Points not the same as an control point?

O.K. i think i got it :slight_smile:
As long as i don’t move the first or last two (duplicate) points it works! Not ideal, but i´ll try to get to it.
Thanks @menno

Or move the duplicates together, that should work too.