Splines#
Generally speaking, a spline is a piecewise polynomial curve that approaches, in a sense to be specified, an ordered list of points. The simplest one is the spline of degree 1 (linear spline) which connects the points by segments. XLiFE++ provides the Hermite cubic spline (C2), the Catmull-Row spline (C1), the B-spline and rational B-Spline (Ck) and the Bézier curve (Ck). The two first ones are interpolation splines while the last ones are approximation spline. Combining two rational B-splines in two directions gives a surface approximation, named NURBS acronym of Non Uniform Rational B-Spline.
C2 spline#
Let
The spline is said to be clamped because derivatives at ends are imposed.

Other boundary conditions are usual :

or periodicity conditions :

To interpolate any set of points
where
The usual choices of parametrization are
the x-parametrization:
(gives the original C2 spline).the uniform parametrization:
.the chordal parametrization:
.the centripetal parametrization:
.
Hint
To make the user life easier, the parameter is pullback to the interval
XLiFE++ provides the C2Spline
class. There are two ways to construct a C2 spline, either by giving two vectors of reals
the type of parametrization : one of _xParametrization, _uniformParametrization, _chordalParametrization, _centripetalParametrization
the boundary conditions : two of _naturalBC, _clampedBC, _periodicBC
the derivatives at end points (vector of reals) required when using clamped conditions
Number n=5;
Real x=0, dx=pi_/n;
vector<Point> points(n+1);
for(Number i=0;i<=n;i++, x+=dx) points[i]=Point(x,sin(x));
C2Spline csn(points,_xParametrization); //natural spline
C2Spline csc(points,_xParametrization,_clampedBC,_clampedBC,
Reals(1.,1.),Reals(1.,-1.)); //clamped spline
C2Spline csp(points, _xParametrization, _periodicBC); //periodic spline

Warning
When _xParametrization
is selected, the curve is regarded as
Warning
Be cautious with periodic conditions. For a periodic open curve (e.g _xParametrization
mode and for a closed periodic curve use other parametrization mode.
Once a C2Spline
object is constructed, using either the function evaluate or the operator (), it can be evaluated at any parameter
...
C2Spline csn(points,_xParametrization);
Real t=0.5; //midle parameter
Point P=csn(t); //value
Point dP=csn(t,_dt); //first derivative (vector as a point)
Point d2P=csn(t,_dt2); //second derivative (vector as a point)
C2Spline
allocates also a Parametrization
object related to the spline parametrization.
Using this object, other quantities such as curvilinear abscissa, normal or tangent vector, curvatures are available (see The Parametrization class and Parametrization
class):
...
C2Spline csn(points,_xParametrization);
Real t=0.5; //midle parameter
const Parametrization& pa=csn.parametrization();
Real c=pa.curvature(t);
Real s=pa.curabc(t);
Reals no=pa.normal(t);
Reals ta=pa.tangent(t);
Catmull-Rom spline#
Another way to construct interpolation spline consists in imposing also the tangent vectors
where
: the standard Catmull-Rom spline, : the chordal Catmull-Rom spline, : the centripetal Catmull-Rom spline.
The Catmull-Rom spline are local (moving a point modifies only the curve in the neighborhood of the point),
the approximation is
Note that to close a curve, it is sufficient to add the two last points at the beginning and the two first points at the end:
and build Catmull-Rom spline on segments
On the next figure, the influence of the parameter

XLiFE++ provides the CatmullRomSpline
class.
It has only one constructor from a vector of points
the type of parametrization : one of
_xParametrization
,_uniformParametrization
,_chordalParametrization
,_centripetalParametrization
the tension parameter
(default value: )the boundary conditions : two of
_undefBC
,_naturalBC
,_clampedBC
,_periodicBC
the tangent vectors at end points (vector of reals) required when using clamped conditions
In this example, as the last point is the same as the first point, the curve will be automatically closed.

Once a CatmullRomSpline
object is constructed, using either the function evaluate
or the operator ()
,
it can be evaluated at any parameter
...
CatmullRomSpline cat(pts);
Real t=0.5 //midle parameter
Point P=cat(t); //value
Point dP=cat(t,_dt); //first derivative (vector as a point)
Point d2P=cat(t,_dt2); //second derivative (vector as a point)
CatmullRomSpline
allocates also a Parametrization
object related to the spline parametrization.
Using this object, other quantities such as curvilinear abscissa, normal or tangent vector, curvatures are available (see The Parametrization class and Parametrization
class):
...
CatmullRomSpline cat(pts);
Real t=0.5 //midle parameter
const Parametrization& pa=cat.parametrization();
Real c=pa.curvature(t);
Real s=pa.curabc(t);
Reals no=pa.normal(t);
Reals ta=pa.tangent(t);
Bézier curve#
For the set of control points
where
and but the curve does not interpolate the interior points (resp. is a tangent vector to the curve at (resp. ),the curve is inside the convex hull of the control points,
the curve is

XLiFE++ provides the BezierSpline
class with only one simple constructor from a vector of points
Number n=5;
vector<Point> points(n+1);
Real x=0, dx=pi_/n;
for(Number i=0;i<=n;i++, x+=dx) points[i]=Point(x,sin(x));
BezierSpline bz(points);
The parameter

Once a BezierSpline
object is constructed, using either the function evaluate
or the operator ()
,
it can be evaluated at any parameter
...
BezierSpline bz(points);
Real t=0.5; //midle parameter
Point P=bz(t); //value
Point dP=bz(t,_dt); //first derivative (vector as a point)
Point d2P=bz(t,_dt2); //second derivative (vector as a point)
BezierSpline
allocates also a Parametrization
object related to the spline parametrization.
Using this object, other quantities such as curvilinear abscissa, normal or tangent vector, curvatures are available (see The Parametrization class and Parametrization
class):
...
BezierSpline bz(points);
Real t=0.5;
const Parametrization& pa=bz.parametrization();
Real c=pa.curvature(t);
Real s=pa.curabc(t);
Reals no=pa.normal(t);
Reals ta=pa.tangent(t)
B-Spline#
The B-spline curve is a generalization of the Bézier curve. Let
with the convention
The B-spline functions have a lot of properties, in particular
is a polynomial of order on intervals with support , for , is at tight and is at knots of multiplicity
For the set of
The B-spline curve is inside the convex hull of the control points, it is
To clamp the curve at

A rational B-spline is defined as following:
where

if
with
By solving a linear inverse problem, the control points may be calculated in order to interpolate a given set of points. In that case, the spline is named interpolation B-spline. For such spline, it is possible to impose the derivative vectors at the endpoints when the spline is clamped.
XLiFE++ provides the BSpline
class with constructors that takes a vector of points
the type of B-spline, either _splineApproximation or _splineInterpolation
the degree of B-spline, default value 3
the type of parametrization : one of
_uniformParametrization
,_chordalParametrization
,_centripetalParametrization
the boundary conditions : two of _undefBC , _naturalBC , _clampedBC , _periodicBC
derivative vectors at end points when clamped B-spline is selected
the vector of weights (default 1)
The given vector of points is either the list of control points (approximation B-spline) or the list of interpolation points (interpolation B-spline). When the type of B-spline is not given, it is assumed to be an approximation B-spline:
Number n=6;
vector<Point> pts(n+1);
Real s=0, ds=2*pi_/n;
for(Number i=0;i<=n;i++,s+=ds) pts[i]=Point(2*cos(s),sin(s)); //points on ellipse
Spline bs(points,3,_periodicBC);
Specifying a periodic condition at starting point stands obviously for periodic condition at ending point!
To use some weights, define a vector of weights of the size of vector of control points:
vector<Real> we(pts.size(),1.);
for(Number k=0;k<we.size();k+=2) we[k]=0.5;
BSpline bsw(pts,3,_periodicBC,_periodicBC,we);
Because of the signature of the constructor, both boundary conditions have to be specified even they are redundant!

Once a BSpline
object is constructed, using either the function evaluate or the operator (), it can be evaluated at any parameter
...
BSpline bs(points,3,_periodicBC);
Real t=0.5; //midle parameter
Point P=bs(t); //value
Point dP=bs(t,_dt); //first derivative (vector as a point)
Point d2P=bs(t,_dt2); //second derivative (vector as a point)
BSpline
allocates also a Parametrization
object related to the spline parametrization.
Using this object, other quantities such as curvilinear abscissa, normal or tangent vector, curvatures are available (see The Parametrization class section and Parametrization
class):
...
BSpline bs(points,3,_periodicBC);
Real t=0.5; //midle parameter
const Parametrization& pa=bs.parametrization();
Real c=pa.curvature(t);
Real s=pa.curabc(t);
Reals no=pa.normal(t);
Reals ta=pa.tangent(t);
The following example shows how to build a clamped interpolation B-spline with a uniform parametrization from 5 points located on the sine curve:
...
vector<Point> pts(5,Point(0.,0.));
pts[1]=Point(pi_/4,sqrt(2)/2.);pts[2]=Point(pi_/2,1.);
pts[3]=Point(3*pi_/4,sqrt(2)/2.);pts[4]=Point(pi_,0.);
Reals d0(2,1.),d1=d0; d1[1]=-1.; //derivatives at end points
BSpline bs(_SplineInterpolation, pts, 3,_uniformParametrization, _clampedBC,_clampedBC,d0,d1);

When specifying only _splineInterpolation and a set of points in constructor, the B-spline will be a natural interpolation B-spline of degree 3 with a uniform parametrization (not rational).
Spline surface (nurbs)#
The most common method to approximate surface are NURBS (non uniform rational B-spline) that are no more than the cross-product of two rational B-splines. Let
a set of
control points anda knot vector in u-direction and v-direction :
andthe degree
in u-direction and the degree in v-direction and
The NURBS surface is defined by
To deal with nurbs, XLiFE++ provides the Nurbs
class. There is only one constructor from a vector of vectors of points (control
points) and optional parameters:
the degrees of B-spline along u /v parameter (default is 3)
the boundary conditions along
parameter, for each parameter, two of _naturalBC, _clampedBC, _periodicBCthe vector of vectors of weights (default no weight)
Number n=4;
Real ds=pi_/(2*n), u=-pi_/2, v=0;
PointMatrix pts(2*n+1,Points(n+1));
for(Number i=0;i<=2*n;i++,u+=ds) // points on the quarter of unit sphere
{
v=0;
for(Number j=0;j<=n;j++,v+=ds)
pts[i][j]=Point(cos(u)*cos(v),cos(u)*sin(v),sin(u));
}
Nurbs nuA(_splineApproximation, pts); //create approximation nurbs
Nurbs nuI(_splineInterpolation, pts); //create interpolation nurbs
Once a Nurbs
object is constructed, using either the function evaluate or the operator (),
it can be evaluated at any parameter
...
Point P=nu(0.5,0.5); //value
Point duP=nu(0.5,0.5,_d1); //first derivative (vector as a point)
Point dvP=nu(0.5,0.5,_d2); //first derivative (vector as a point)
Nurbs allocates also a Parametrization
object related to the spline parametrization.
Using this object, other quantities such as curvilinear abscissa, normal or tangent vector, curvatures are available (see The Parametrization class section and Parametrization
class):
...
const Parametrization& pa=nu.parametrization();
Real u=0.5, v=0.5;
Reals cu=pa.curvatures(u,v); //two main curvatures
Reals no=pa.normal(u,v); //normal vector
Reals ta=pa.tangents(u,v); //two orthogonal tangent vectors in a same Vector