maspack.geometry
Class NURBSCurve2d

java.lang.Object
  extended by maspack.geometry.NURBSObject
      extended by maspack.geometry.NURBSCurveBase
          extended by maspack.geometry.NURBSCurve2d
All Implemented Interfaces:
GLRenderable, GLSelectable, HasRenderProps, Renderable

public class NURBSCurve2d
extends NURBSCurveBase

Implements a NURBS curve


Field Summary
 
Fields inherited from class maspack.geometry.NURBSCurveBase
CLOSED, init, OPEN
 
Fields inherited from interface maspack.render.GLRenderable
TRANSLUCENT, TWO_DIMENSIONAL
 
Constructor Summary
NURBSCurve2d()
          Creates an empty NURBS curve.
NURBSCurve2d(int d, int type, Vector4d[] ctrlPnts, double[] knots)
          Creates an open or closed NURBS curve with a specified degree, knots, and control points.
NURBSCurve2d(NURBSCurve2d curve)
          Creates a NURBS curve that is a copy of another curve.
 
Method Summary
 void addControlPoint(Vector4d pnt, double knotSpacing)
          Add an additional control point and knot to the end of this curve.
 void eval(Point3d pnt, double u)
          Evaluates the point on this curve for parameter u.
 Point2d[] evalPoints(int npnts)
          Returns a set of points evaluated along the curve at intervals which are evenly spaced with respect to the curve parameter.
 double findPoint(Point2d pnt, double umin, double umax)
          Finds a u value for a given curve point within a specified interval of the curve.
 int getOrientation()
          For closed curves, return 1 if it is oriented counter-clockwise and -1 if clockwise.
 void set(int d, int type, Vector4d[] ctrlPnts, double[] knots)
          Sets this NURBS curve to either an open or closed curve with a specified degree, knots, and control points.
 void set(NURBSCurve2d curve)
           
 
Methods inherited from class maspack.geometry.NURBSCurveBase
computeControlPolygonLength, convertToBezier, createRenderProps, createUniformKnots, getDegree, getKnot, getKnotIndex, getKnots, getRange, getResolution, getType, insertKnot, isBezier, isBSpline, isClosed, numKnots, read, read, removeControlPoint, render, reset, set, set, setBezier, setCircle, setRange, setResolution, setUniformCubic, write, write
 
Methods inherited from class maspack.geometry.NURBSObject
controlPointIsSelected, getControlPoint, getControlPoints, getDrawControlShape, getLineWidth, getObjToWorld, getObjToWorld, getPointSize, getRenderHints, getRenderProps, getSelection, isSelectable, numControlPoints, numSelectionQueriesNeeded, prerender, render, selectControlPoint, setDrawControlShape, setLineWidth, setObjToWorld, setPointSize, setRenderProps, transform, updateBounds, write, write
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NURBSCurve2d

public NURBSCurve2d()
Creates an empty NURBS curve.


NURBSCurve2d

public NURBSCurve2d(NURBSCurve2d curve)
Creates a NURBS curve that is a copy of another curve.


NURBSCurve2d

public NURBSCurve2d(int d,
                    int type,
                    Vector4d[] ctrlPnts,
                    double[] knots)
Creates an open or closed NURBS curve with a specified degree, knots, and control points. For more information on these arguments, see set.

Parameters:
d - degree of the curve
type - curve type, which must be either OPEN or CLOSED.
knots - knot values
ctrlPnts - control points
Throws:
java.lang.IllegalArgumentException - if constraints on the arguments are violated
See Also:
set(int,int,Vector4d[],double[])
Method Detail

evalPoints

public Point2d[] evalPoints(int npnts)
Returns a set of points evaluated along the curve at intervals which are evenly spaced with respect to the curve parameter.

Parameters:
npnts - number of points to create
Returns:
array of evaluated points

getOrientation

public int getOrientation()
For closed curves, return 1 if it is oriented counter-clockwise and -1 if clockwise. Returns 0 is the curve is open, or the orientation can't be determined because of self-intersection.


set

public void set(int d,
                int type,
                Vector4d[] ctrlPnts,
                double[] knots)
Sets this NURBS curve to either an open or closed curve with a specified degree, knots, and control points.

Let d, numk, and numc be the degree of the curve, the number of knots, and the number of control points. The degree must be 1 or greater. For open curves,

numc = numk - d + 1
and for closed curves,
numc = numk - 2*d + 1

The knots argument may be set to null, in which case an appropriate number of uniformly spaced knots will be created, in the range [0, 1]. Otherwise, if knots is specified, the ctrlPnts argument must contain at least numc elements.

This method automatically sets ustart and uend (see setRange) to knots[d-1] and knots[numk-d].

The control points are specified as 4-vectors, where their spatial location is given by x, y, and z and their weight is given by w. The points should not be in homogeneous form; i.e., x, y, and z should not be premultipled by w.

Overrides:
set in class NURBSCurveBase
Parameters:
d - degree of the curve
type - curve type, which must be either OPEN or CLOSED.
ctrlPnts - control points
knots - knot values

addControlPoint

public void addControlPoint(Vector4d pnt,
                            double knotSpacing)
Description copied from class: NURBSCurveBase
Add an additional control point and knot to the end of this curve. The knot spacing can be given by h. If this is specified as -1, then the default uniform knot spacing (typically 1) is used.

Overrides:
addControlPoint in class NURBSCurveBase

eval

public void eval(Point3d pnt,
                 double u)
Evaluates the point on this curve for parameter u. If necessary, u is clipped to the range [ustart, uend].

Specified by:
eval in class NURBSCurveBase
Parameters:
pnt - returns the curve point value
u - curve parameter value

findPoint

public double findPoint(Point2d pnt,
                        double umin,
                        double umax)
Finds a u value for a given curve point within a specified interval of the curve. If the point is not actually on the specified interval, this routine attempts to return the u value for the nearest curve point. It should be noted that one point may correspond to multiple u values.

This routine uses an iterative golden section search, and so is not particularly fast.

Parameters:
pnt - point to search for
umin - minimum u valu for the interval
umax - maximum u valu for the interval
Returns:
u value for the point closest to pnt within the interval.

set

public void set(NURBSCurve2d curve)