Spline curves#

class splinebox.spline_curves.Spline(M, basis_function, closed=False, control_points=None, padding_function=<function padding_function>)#

Base class for the construction of a spline.

Parameters#

Mint

Number of knots.

basis_functionsplinebox.basis_functions.BasisFunction

The basis function used to construct the spline.

closedboolean

Whether or not the spline is closed, i.e. the two ends connect.

control_pointsnp.array

The control points of the spline. Optional, can be provided later.

padding_functioncallable

A function that accepts an array of knots as the first argument and the padding size as the second argument. It should return a padded array. If None, a padded array has to be supplied when setting the knots. The default is constant padding with the edge values (see splinebox.spline_curves.padding_function()).

arc_length(stop=None, start=0, epsabs=1e-06, epsrel=1e-06)#

Compute the arc length of the spline between the two parameter value specified. if

Parameters#

stopfloat (optional)

Stop point in parameter space.

startfloat (optional)

Start point in parameter space.

epsabsfloat (optional)

Absolute error tolerance. Default is 1e-6.

epsrelfloat (optional)

Relative error tolerance. Default is 1e-6.

arc_length_to_parameter(s, atol=0.0001)#

Convert the arc length s to the coresponding value in parameter space.

Parameters#

sfloat or np.array

Length on curve.

atolfloat

The ablsolute error tolerance.

property basis_function#
property control_points#
copy()#
curvature(t)#
curvilinear_reparametrization_energy(epsabs=1e-06, epsrel=1e-06)#

This energy can be used to enforce equal spacing of the knots.

Implements equation 25 from Jaboc, et al. 2004 https://infoscience.epfl.ch/record/63117?ln=fr&v=pdf In order to make the energy scale invariant, we added a factor of length^-4 to the integral.

draw(x, y)#

Computes a whether a point is inside or outside a closed spline on a regular grid of points.

I would ask the user to provide a grid of points directly instead of asking for the dimensions. Like that the user can choose how densly they want to sample the grid.

dtheta(t)#

Helper function for calculating the winding number.

dtheta is the derivative of the polar coordinate \(\theta(t)\)

\[\theta(t) = arctan \left( \frac{y(t)}{x(t)} \right)\]

Differentiation yields:

\[\frac{d \theta}{dt} = \frac{1}{r^2} \left( x\frac{dy}{dt} - y\frac{dx}{dt} \right) \text{, where } r^2 = x^2 + y^2\]
eval(t, derivative=0)#

Evalute the spline or one of its derivatives at parameter value(s) t.

Parameters#

tnumpy.array, float

A 1D numpy array or a single float value.

derivativeint

Can be 0, 1, 2 for the spline, and its first and second derivative respectively.

fit(points, arc_length_parameterization=False)#

Fit the provided points with the spline using least squares.

Parameters#

pointsnumpy.ndarray

The data points that should be fit.

arc_length_parameterizationbool

Whether or not to space the knots based on the distance between the provided points. This is usefull when the points are not equally spaced. Default is False.

is_inside(x, y)#

Determines if a point with coordinates x, y is inside the spline. Only works for closed 2D curves.

To determine whether a point is inside or outside the spline, the winding number is used:

\[wind(\gamma, 0) = \frac{1}{2\pi} \oint_\gamma d\theta = \frac{1}{2\pi} \oint_\gamma \left( \frac{x}{r^2}dy - \frac{y}{r^2}dx \right).\]

For a description of \(d\theta\) check splinebox.splines_curves.Spline.dtheta().

Parameters#

xnumpy.ndarray or float

x coordinate(s) of point(s)

ynumpy.ndarray or float

y coordinate(s) of point(s)

Returns#

valfloat

1 if the point is inside, 0.5 if its on the curve and 0 if it is outside the curve.

property knots#
normal(t)#
rotate(rotation_matrix, centred=True)#

Rotate the spline with the provided rotation matrix.

Parameters#

rotation_matrixnumpy.ndarray

The rotation matrix applied to the spline.

sampleArcLength(numSamples, dt=False)#

Evaluate the spline equidistantly spaced along its trajectory. Perhaps it makes sense to ask the user to provide an array of distances instead of the numSamples.

scale(scaling_factor)#

Enlarge or shrink the spline. This should probably use splinebox.spline_curves.Spline.translate() scalingFactor can be renamed to factor.

translate(vector)#

Translates the spline by a vector.

Parameters#

vectornumpy.ndarray

Displacement vector added to the coefficients.