Curves

Two type of curves are available:

  • B-splines curves
  • NURBS curves

Both are defined by initializing corresponding structures.


Defining Structures

NURBS and B-spline curves are defined by initializing a BsplineCurve or a NURBScurve structure, respectively.

# --- parameters
kVec = Float64[0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 6, 6, 6] # knot vector
kVec ./= maximum(kVec)                                # normalize it

p = 3  # degree

# --- control points
using StaticArrays
P1 = SVector(0.0, 0.0, 0.0)
P2 = SVector(0.1, 0.25, 0.0)
P3 = SVector(0.25, 0.3, 0.0)
P4 = SVector(0.3, 0.5, 0.0)
P5 = SVector(0.4, 0.4, 0.0)
P6 = SVector(0.6, 0.3, 0.0)
P7 = SVector(0.8, 0.7, 1.0)
P8 = SVector(1.0, 0.4, 0.0)
P9 = SVector(1.1, 0.4, 0.0)

controlPoints = [P1 , P2 , P3 , P4 , P5 , P6 , P7 , P8 , P9 ]
w             = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 3.0, 1.0, 1.0] # weights for the NURBS

# --- the structures
BCurve = BsplineCurve(Bspline(p, kVec), controlPoints)
NCurve   = NURBScurve(NURB(p, kVec, w), controlPoints)

Evaluate Points of a Curve

To evaluate the curves at parametric points simply hand over the latter.

evalpoints = collect(0:0.0005:1.0)

CBspline = BCurve(evalpoints)
CNurbs   = NCurve(evalpoints)

To plot the curves the plotCurve3D and the plotCurve functions are provided, where the latter ignores any $z$-components.

Note

The PlotlyJS.jl package has to be loaded in order to make the functions available. (It is a weak dependency.)

using PlotlyJS

plotCurve3D(CBspline, controlPoints=controlPoints)

Evaluate Derivatives of a Curve

To evaluate derivatives of curves at parametric points hand over the latter and the maximum derivative to be evaluated.

evalpoints = collect(0:0.0005:1.0)

C = NCurve(evalpoints, 2) # 0-th, 1st, and 2nd derivatives

The plotCurve3D function has an optional argument tangents to plot vectors at the points of the curve.

using PlotlyJS

plotCurve3D(C[1], controlPoints=controlPoints, tangents=C[2])