Splines.BSpline
— TypeBSpline(degree, knots, ctrlpts)
Construct a B-Spline object
Arguments
deg::Integer
: degreeknots::Vector{Float64}
:: a knot vector (u0, ... un+1)ctrlpts::Vector{Vector{Float64}}
:: control points. outer index is number of control points, inner index of dimensionality of point.
Splines.NURBS
— TypeNURBS(degree, knots, weights, ctrlpts)
Construct a NURBS object
Arguments
deg::Integer
: degreeknots::Vector{Float64}
:: a knot vector (u0, ... un+1)weights::Vector{Float64}
:: a corresponding vector of weightsctrlpts::Vector{Vector{Float64}}
:: control points. outer index is number of control points, inner index of dimensionality of point.
Splines.bernsteincoeff
— Methodbernsteincoeff(u, n, i)
Calculate Bernstein Coefficient (Bezier Basis Function) defined as:
\[B_{i, n}(u) = \binom{n}{i} u^i (1-u)^{n-1}\]
at parametric point, $u$, where $0\leq u\leq1$. $u$ may either be a single value or an array.
(see NURBS, eqn 1.8)
Splines.binomialcoeff
— Methodbinomialcoeff(n, i)
Calculate the Binomial Coefficient defined as:
\[\binom{n}{i} = \frac{n!}{i!(n-1)!}\]
Splines.curvederivativecontrolpoints
— Methodcurvederivativecontrolpoints(n, p, U, P, d, r1, r2)
Compute control points of curve derivatives:
\[\mathbf{C}^{(k)}(u) = \sum_{i=0}^{n-k}N_{i,p-k}(u) \mathbf{P}_i^{(k)}\]
with
\[\mathbf{P}_i^{(k)} = \begin{cases} \mathbf{P}_i & k=0 \\ \frac{p-k+1}{u_{i+p+1}-u_{i+k}}\left(\mathbf{P}_{i+1}^{(k)} - \mathbf{P}_i^{(k)} \right) & k > 0 \end{cases}\]
(see NURBS, eqn 3.8 and A3.3)
Arguments
bspline::BSpline: bspline object
- `r1::Integer : first control point index to take derivatives at
- `r2::Integer : last control point index to take derivatives at
d::Float
: derivative order (0 ≤ k ≦ d)
Returns
PK::Matrix{Vector{Float}}
: PK[i, j] is the ith derivative of the jth control point
Splines.curvederivatives
— Methodcurvederivatives(bspline, u, d)
Compute a curve point and its derivatives up do the dth derivative at parametric point, $u$. (NURBS, A3.2)
Arguments
bspline::BSpline: bspline object
u::Float
: point on spline to evaluate atd::Float
: derivative order (0 ≤ k ≤ d)
Returns
CK::Vector{Vector{Float}}
. where CK[0] is the point, CK[1] the first derivative, and so on.
Splines.curvederivatives
— Methodcurvederivatives(nurbs, u, d)
Compute a curve point and its derivatives up do the dth derivative at parametric point, $u$. (NURBS, A3.2)
Arguments
nurbs::NURBS: bspline object
u::Float
: point on spline to evaluate atd::Float
: derivative order (0 ≤ k ≤ d)
Returns
CK::Vector{Vector{Float}}
where CK[1] is the point, CK[2] the first derivative, and so on.
Splines.curveknotinsertion
— Methodcurveknotinsertion(np, p, UP, Pw, u, k, s, r)
Compute a new curve from knot insertion. Using the formula:
\[\mathbf{Q}_{i, r}^w = \alpha_{i, r} \mathbf{Q}_{i, r-1}^w + (1-\alpha_{i, r}) \mathbf{Q}_{i-1, r-1}^w\]
where
\[\alpha_{i, r} = \begin{cases} 1 & i \leq k-p+r-1 \\ \frac{\bar{u} - u_i}{u_{i+p-r+1} - \bar{u}_i} & k-p+r \leq i\leq k-s \\ 0 & i \geq k-s+1 \end{cases}\]
(see NURBS eqn 5.15 and A5.1)
Inputs:
- np : the number of control points minus 1 (the index of the last control point) before insertion
- p : the curve order
- UP : the knot vector before insertion
- Pw : the set of weighted control points and weights before insertion
- u : the knot to be added
- k : the span index at which the knot is to be inserted.
- s : numer of instances of the new knot alrady present in the knot vector, UP
- r : number of times the new knot is inserted (it is assumed that $r+s \leq p$ )
Outputs:
- nq : the number of control points minus 1 (the index of the last control point) after insertion
- UQ : the knot vector after insertion
- Qw : the set of weighted control points and weights after insertion
Splines.curvepoint
— MethodEvaluate point on B-spline curve (NURBS, A3.1)
Arguments
bspline::BSpline: bspline object
u::Float
: point on spline to evaluate at
Returns
C::Vector{Float}
: point in ND space
Splines.curvepoint
— MethodEvaluate point on rational b-spline curve (NURBS, A4.1)
Arguments
nurbs::NURBS: NURBS object
u::Float
: point on spline to evaluate at
Returns
C::Vector{Float}
: point in ND space
Splines.decasteljau_bezier1D
— Methoddecasteljau_bezier1D(P, u)
Calculate a point along a Bezier curve at the parametric point, $u_0$, based on the control points, $\mathbf{P}$, using deCasteljau's Algorithm:
\[\mathbf{P}_{k, i}(u_0) = (1- u_0)\mathbf{P}_{k-1, i}(u_0) + u_0 \mathbf{P}_{k-1, i+1}(u_0)\]
for $k = 1, ..., n$ and $i = 0, ..., n-k$, where $u_0$ is any single value from 0 to 1.
(see NURBS, eqn 1.12 and A1.5)
Splines.degreeelevatecurve
— Methoddegreeelevatecurve(n,p,U,Pw,t)
Raise degree of spline from p to p $+t$, $t \geq 1$ by computing the new control point vector and knot vector.
Knots are inserted to divide the spline into equivalent Bezier Curves. These curves are then degree elevated using the following equation.
\[\mathbf{P}^t_i = \sum^{\textrm{min}(p,i)}_{j=\textrm{max}(0,i-t)} \frac{\binom{p}{j} \binom{t}{i-j} \mathbf{P}_j}{\binom{p+t}{i}}~,~~~~~i=0,...,p+t\]
where $\mathbf{P}^t_i$ are the degree elevated control points after $t$ -degree elevations
Finally, the excess knots are removed and the degree elevated spline is returned.
(see NURBS eqn 5.36, A5.9)
Inputs:
- n : the number of control points minus 1 (the index of the last control point) before degree elevation
- p : the curve order
- U : the knot vector before degree elevation
- Pw : the set of weighted control points and weights before degree elevation
- t : the number of degrees to elevate, i.e. the new curve degree is p+t
Outputs:
- nh : the number of control points minus 1 (the index of the last control point) after degree elevation
- Uh : the knot vector after degree elevation
- Qw : the set of weighted control points and weights after degree elevation
Splines.get_ctrlpts
— Methodget_ctrlpts
return control points of spline
Splines.get_degree
— Methodget_degree
return degree of spline
Splines.get_knots
— Methodget_knots
return knot vector of spline
Splines.get_weights
— Methodget_weights
return weights of spline
Splines.getspanindex
— Methodgetspanindex(deg, knots, u)
(private function) binary search to find span index of vector, knots, in which the parametric point, u, lies. (NURBS A2.1)
Arguments
deg::Integer
: degreeknots::Vector{Float64}
:: a knot vector (u0, ... un+1)u
::Float64`: nondimensional location we are searching for
Returns
span::Integer
: corresponding index i for u between knotsi and knotsi+1
Splines.globalcurveinterpolation
— Methodglobalcurveinterpolation(pts, deg)
Interpolate ctrl points pts, with a B-Spline of degree deg. (NURBS A9.1)
Arguments
pts::Vector{Vector{Float}}
: outer vector of length npts, inner vector of length dimension of spacedeg::Integer
: degree of B-spline
Outputs:
bspline::BSpline
: bspline object
Splines.leastsquarescurve
— Methodleastsquarescurve(pts, nctrl, deg)
Least squares fit to provided points. (NURBS section 9.4.1) TODO: Currently hard-coded to 2D data.
Arguments
pts::Vector{Vector{Float}}
: data pointsnctrl::Integer
: number of control points to use in fitdeg::Integer
: degree of bspline used in fit
Returns
bspline::BSpline
: a BSpline object
Splines.nurbsbasis
— Methodnurbsbasis(u,p,d,U,w)
Get rational basis functions and derivatives.
\[R_{i,p}(u) = \frac{N_{i,p}(u)w_i}{\sum_{j=0}^n N_{j,p}(u)w_j}\]
where $N_{i,p}(u )$ are B-Spline Basis Functions and $w_i$ are weights associated with the NURBS control points.
(see NURBS eqn 4.2)
Inputs:
- u : parametric point of interest
- p : the curve order
- d : the max derivative order (n ≦ p)
- U : the knot vector
- w : control point weights
Splines.refineknotvectorcurve
— Methodrefineknotvectorcurve(n, p, U, Pw, X, r)
Refine curve knot vector using NURBS A5.4.
This algorithm is simply a knot insertion algorithm that allows for multiple knots to be added simulataneously, i.e., a knot refinement procedure.
Inputs:
- n : the number of control points minus 1 (the index of the last control point) before insertion
- p : the curve order
- U : the knot vector before insertion
- Pw : the set of weighted control points and weights before insertion
- X : elements, in ascending order, to be inserted into U (elements should be repeated according to their multiplicities, e.g., if x and y have multiplicites 2 and 3, X = [x,x,y,y,y])
- r : length of X vector - 1
Outputs:
- Ubar : the knot vector after insertion
- Qw : the set of weighted control points and weights after insertion
Splines.simple_bezier1D
— Methodsimple_bezier1D(P, u)
Calculate a point along a Bezier curve at the parametric point, $u$, based on the control points, $\mathbf{P}$, where the Bezier curve, $\mathbf{C}(u)$, is defined as:
\[\mathbf{C}(u) = \sum_{i=0}^n B_{i, n}(u) \mathbf{P}_i~, ~~~~ 0 \leq u \leq 1\]
where $B$ is the basis (Bernstein Coefficient) at parametric point, $u$, as calculated from bernsteincoeff
, and n is the number of control points in vector $\mathbf{P}$. Again, $u$ may either be a single value or an array.
(see NURBS eqn 1.7)
Splines.singlebasisfunction
— Methodsinglebasisfunction(i, deg, knots, u)
(private function) Compute single basis function N_i^p. (NURBS A2.4)
Arguments
i::Integer
: the index of the basis (the i in N_i)deg::Integer
: the basis degree up to the the curve orderknots::Vector{Float}
: the knot vectoru::Float
: parametric point of interest
Returns
Nip::Float
: the N_i^p basis function value