Creating Curves

NURBS curves are a mathematical model used for representing a curve in three dimensional space that is flexible and precise. NURBS curves are the basis of creating NURBS surfaces and volumes. The NurbsCurve class models the behavior of these curves.

Control Points & Knot Vectors

You can easily create a new curve using the NurbsCurve constructor. This constructor takes in a list of control points and a parameter that defines how the endpoints behave. The degree of the curve and the knot vector are determined automatically. The second parameter of this constructor, which take a NurbsPinning value, controls the pinning for the curve. This affects the generated knot vector. PinStart will ensure that the curve passes through the first control point, PinEnd will ensure the curve passes through the last control point, and PinBoth ensures the curve passes through the first and last control points.

var curve = new NurbsCurve(
    new NurbsControlPoint[]{
        new NurbsControlPoint(new Vec3(-4, -4, 0), 1),
        new NurbsControlPoint(new Vec3(-2, 4, 0), 1),
        new NurbsControlPoint(new Vec3(2, -4, 0), 1),
        new NurbsControlPoint(new Vec3(4, 4, 0), 1)
    }, 
    NurbsPinning.PinBoth
);

For more precise control over the curve's behaviour, there is a second constructor in which the degree and knot vector are explicitly provided.

var w = Math.Sqrt(2) / 2;
var controls = new NurbsControlPoint[]{
    new NurbsControlPoint(center + new Vec3(1, 0, 0), 1),
    new NurbsControlPoint(center + new Vec3(1, 1, 0), w),
    new NurbsControlPoint(center + new Vec3(0, 1, 0), 1),
    new NurbsControlPoint(center + new Vec3(-1, 1, 0), w),
    new NurbsControlPoint(center + new Vec3(-1, 0, 0), 1),
    new NurbsControlPoint(center + new Vec3(-1, -1, 0), w),
    new NurbsControlPoint(center + new Vec3(0, -1, 0), 1),
    new NurbsControlPoint(center + new Vec3(1, -1, 0), w),
    new NurbsControlPoint(center + new Vec3(1, 0, 0), 1),
};
var knots = new double[]{
    0, 
    0, 
    0, 
    Math.PI / 2, 
    Math.PI / 2,
    Math.PI,
    Math.PI, 
    3 * Math.PI / 2,
    3 * Math.PI / 2,
    2 * Math.PI,
    2 * Math.PI,
    2 * Math.PI
};
return new NurbsCurve(2, controls, knots);

Evaluating Points

With a NURBS curve created you can evaluate points on that curve using an interpolation parameter. To support this, the NurbsCurve class provided an indexor property which can be used. Provide a value between 0 and 1 as a parameter and the three dimension vector representing that point on the curve will be returned.

NurbsCurve curve = ...;
var midpoint = curve[0.5];