Spline curves#
- class splinebox.spline_curves.Spline(M, basis_function, closed=False, coeffs=None)#
Base class for the construction of a spline.
Parameters#
- Mint
Number of control points.
- 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 connect.
- arc_length(stop=None, start=0)#
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.
- 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 coeffs#
- copy()#
- 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#
- 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.