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();
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…
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.
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?