Nurbs definition

Hello, forum!

I’m working with Rhino 4 and Rhino.net plug-in sdk (.net 2.0) in c#. I’m not able to define a nurbs properly, when I do it the behavior is unexpected.

I want to draw a very simple nurbs defined by 3 points (p1, p2 and p3), being tangent to p0-p1 and p1-p2 at the ends, and control the proximity of the curve to p1 by its weight, w1.

My code is:

On4dPoint p0 = new On4dPoint(2, 1, 0, 1);
On4dPoint p1 = new On4dPoint(4, 3, 0, 1);
On4dPoint p2 = new On4dPoint(5, 2, 0, 1);

OnNurbsCurve nc0 = new OnNurbsCurve(3, true, 3, 3);
nc0.SetKnot(0, 0);
nc0.SetKnot(1, 0);
nc0.SetKnot(2, 1);
nc0.SetKnot(3, 1);
bool p00OK = nc0.SetCV(0, p0);
bool p10OK = nc0.SetCV(1, p1);
bool p20OK = nc0.SetCV(2, p2);
bool w00OK = nc0.SetWeight(0, 1.0);
bool w10OK = nc0.SetWeight(1, 1.0);
bool w20OK = nc0.SetWeight(2, 1.0);

OnNurbsCurve nc1 = new OnNurbsCurve(3, true, 3, 3);
nc1.SetKnot(0, 0);
nc1.SetKnot(1, 0);
nc1.SetKnot(2, 1);
nc1.SetKnot(3, 1);
bool p01OK = nc1.SetCV(0, p0);
bool p11OK = nc1.SetCV(1, p1);
bool p21OK = nc1.SetCV(2, p2);
bool w01OK = nc1.SetWeight(0, 1.0);
bool w11OK = nc1.SetWeight(1, 0.5);
bool w21OK = nc1.SetWeight(2, 1.0);

Which means that the first curve (white) has all weights equal to 1 and it is visually correct. The second (red) has w1=0.6, then it should have basically the basic shape and tangent properties of the white one but should be less close to p1 vertex.

The problem is that what I see is not what I was expecting. The red curve is no longer tangent to p0-p1 and p1-p2 and its convexity is no longer “attracted” by p1.

I’ve read that Rhino uses a shorter knot notation, in fact in this case the classical “Piegl, Tiller, The nurbs book” knot vector should be [0,0,0,1,1,1], but Rhino apparently doesn’t need both end values and then I used [0,0,1,1] by analyzing the properties of similar curves drawn by hand. Is the problem around here?

Thanks. L

Rhino uses homogeneous coordinates for control points in rational NURBS. That is, if you want P1 to be at (4,3,0) with weight 0.5, then the 4d representation of the middle control polint should be (2, 1.5, 0, 0.5). SetWeight just sticks the weight in the 4th spot and does not adjust the other coordinates.

So, either you should use On4dPoint p1 = new On4dPoint(2, 1.5, 0, 1) before your call to SetWeight (1,0.5) or just do On4dPoint p1 = new On4dPoint(2, 1.5, 0, 0.5); and don’t call SetWeight() at all.

Chuck,

great, problem solved! Thanks a lot.

Bye. L