spline_curves#
This submodule provides the classes used to create spline and hermite spline objects.
- 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_function
splinebox.basis_functions.BasisFunction The basis function used to construct the spline.
- closedboolean
Whether or not the spline is closed, i.e. the two ends are connected.
- 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 values specified. If no value for start is give, start from the begining of the spline. If no value for stop is give, go until the end of the spline. When arrays with multiple values are given for start and/or stop, an array with all of the arc lengths is returned.
Parameters#
- stopnp.array / float (optional)
Stop point(s) in parameter space.
- startnp.array / float (optional)
Start point(s) 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#
The basis function of the spline. Should be an object of a specific implementation of the abstract base class
splinebox.basis_functions.BasisFunction.
- copy()#
Returns a deep copy of this spline.
- curvature(t)#
Compute the curcature of the spline at position(s) t. For splines in 1 and 2 dimensions, the signed curvature is returned. Otherwise the unsigned curvature is returned.
Parameters#
- tfloat or numpy array
The paramter value(s) at which the curvature should be calculated.
Returns#
- kfloat or numpy array
The curvature value.
- 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 [Jacob2004]. In order to make the energy scale invariant, we added a factor of (arc length)^-4 to the integral.
Parameters#
- epsabsfloat
The absolute accuracy for the integration. Default is 1e-6. For details see scipy.integrate.quad.
- epsrelfloat
The relative accuracy for the integration. Default is 1e-6. For details see scipy.integrate.quad.
Returns#
- energyfloat
The curvilinear reparametrization energy of the spline.
- draw(x, y)#
Computes whether a point is inside or outside a closed spline on a regular grid of points.
Parameters#
- xnumpy array
A 1D array containing the x values of the grid of points.
- ynumpy array
A 1D array containing the y values of the grid of points.
- 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. For details refer to Data approximation.
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.spline_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#
The knots of this spline, i.e. the values of the spline at \(t=0,1,...,M\).
- normal(t)#
Returns the normal vector for 1D and 2D splines. The normal vector points to the right of the spline when facing in the direction of increasing t.
Parameters#
- tfloat or numpy array
The parameter value(s) for which the normal vector(s) are computed.
Returns#
- normalsnumpy array
The normal vectors.
- rotate(rotation_matrix, centred=True)#
Rotate the spline with the provided rotation matrix.
Parameters#
- rotation_matrixnumpy.ndarray
The rotation matrix applied to the spline.
- scale(scaling_factor)#
Enlarge or shrink the spline by the provided factor.
- splinebox.spline_curves.padding_function(knots, pad_length)#
This is the default padding function of splinebox. It applies constant padding to the ends of the knots.
Parameters#
- knotsnumpy array
The knots to be padded.
- pad_lengthint
The amount of padding at each end.
Returns#
- padded_knotsnumpy array
Array of padded knots.