rust-nurbs

raw JSON →
0.28.0 verified Sat May 09 auth: no python

A Python API for evaluation of Non-Uniform Rational B-Splines (NURBS) curves and surfaces, implemented in Rust for performance. Current version: 0.28.0. Released approximately every few months.

pip install rust-nurbs
error ValueError: The degree must be less than the number of control points.
cause Degree too high for provided number of control points. For a curve with n control points, degree must be <= n-1.
fix
Reduce degree or increase control points. Example: 4 control points -> degree <= 3.
error TypeError: expected a numpy array, got list
cause rust-nurbs requires numpy arrays, Python lists are not automatically converted.
fix
Convert input to numpy array: control_points = np.array(control_points_list)
error ValueError: The number of knots must equal number of control points + degree + 1.
cause Custom knot vector length mismatch.
fix
For n control points and degree d, knot vector length must be n + d + 1.
gotcha All input arrays (control_points, knots, weights) must be of type float (e.g., numpy float64). Integer arrays cause silent type coercion errors.
fix Ensure control_points etc. are created with dtype=np.float64 or cast via .astype(float).
gotcha The evaluate method expects a single float or array-like of floats. Passing a Python list may work but using numpy array is recommended for performance.
fix Use np.linspace(0,1,100) for multiple evaluations.
gotcha Knot vector must be non-decreasing. If you supply a custom knot vector with duplicate knots at ends, ensure it is strictly non-decreasing. Errors are not descriptive.
fix Check knot_vector[i+1] >= knot_vector[i]. Use np.sort if needed.

Create a NURBS curve, evaluate at a parameter.

from rust_nurbs import NurbsCurve
import numpy as np

# Define control points (4 points, 3D)
control_points = np.array([[0.0, 0.0, 0.0],
                           [1.0, 2.0, 0.0],
                           [3.0, 3.0, 0.0],
                           [4.0, 0.0, 0.0]])

# Create a degree 3 NURBS curve with uniform knot vector and weights
curve = NurbsCurve(control_points, degree=3)

# Evaluate at parameter u=0.5
point = curve.evaluate(0.5)
print(point)