Splines in Euclidean Space and Beyond

raw JSON →
0.3.3 verified Fri May 01 auth: no python

A Python library for creating and evaluating splines in Euclidean space and beyond, including B-splines and Bézier curves. Current version is 0.3.3, released in 2021. The library is under active development with irregular release cadence.

pip install splines
error ModuleNotFoundError: No module named 'splines'
cause Library not installed or installed in wrong environment.
fix
Run pip install splines in the correct Python environment.
error AttributeError: module 'splines' has no attribute 'UnitBSpline'
cause Outdated library version or incorrect import path.
fix
Upgrade to version >=0.2.0 with pip install --upgrade splines and use from splines import UnitBSpline.
gotcha The `UnitBSpline` class expects a specific knot vector format with repeated knots at the ends for clamped splines. Using a non-clamped knot vector may produce unexpected results.
fix Ensure knot vector has multiplicity equal to degree+1 at start and end.
deprecated Older versions used an `evaluate` method that returned a single point; newer versions may return an array. Check documentation for your version.
fix Update code to handle array output or upgrade to latest version.
gotcha The library does not support non-uniform rational B-splines (NURBS) out of the box. Attempting to use weights will cause errors.
fix Use a different library like `numpy` or `scipy.interpolate` for NURBS.

Create a uniform B-spline and evaluate at a parameter value.

from splines import UnitBSpline
import numpy as np

knots = [0, 0, 0, 1, 2, 3, 4, 4, 4]
controls = [0, 1, 0, 1, 0]
spline = UnitBSpline(knots, controls)
print(spline.evaluate(0.5))