geomdl

raw JSON →
5.4.0 verified Mon Apr 27 auth: no python

Object-oriented B-Spline and NURBS evaluation library for Python. Current version is 5.4.0, released in December 2022. Maintenance mode with irregular releases.

pip install geomdl
error AttributeError: module 'geomdl' has no attribute 'NURBS'
cause Incorrect import path; NURBS is now a submodule, not a direct attribute.
fix
Use from geomdl import NURBS or import geomdl.NURBS.
error TypeError: curve() takes no arguments
cause Attempting to instantiate a class directly from the module (e.g., `BSpline.Curve()` is correct, but `BSpline()` is the module, not the class).
fix
Use from geomdl import BSpline then curve = BSpline.Curve().
error ModuleNotFoundError: No module named 'geomdl.vis'
cause The vis module was removed in newer versions.
fix
Use from geomdl.visualization import VisMPL instead.
error ValueError: knotvector of length 8 is not appropriate for degree 3 with 5 control points
cause Knot vector length must equal number of control points + degree + 1. Generated using helper.
fix
Use knotvector.generate(degree, num_ctrlpts) to generate correct knot vector.
breaking In version 5.x, the API changed significantly from 4.x. The old `geomdl.NURBS` module no longer exists; use `geomdl.BSpline` and `geomdl.NURBS` as separate modules.
fix Update imports: replace `from geomdl import NURBS` with `from geomdl import BSpline` for B-spline, or keep `from geomdl import NURBS` for NURBS-specific (but the class names changed).
gotcha The knotvector must be generated explicitly using `knotvector.generate()`. Forgetting to do so leads to an incomplete curve or error.
fix Always generate knotvector after setting control points: `curve.knotvector = knotvector.generate(curve.degree, len(curve.ctrlpts))`.
gotcha The 'delta' parameter controls evaluation step size. Setting it too large yields jagged curves; too small may cause performance issues.
fix Use a reasonable delta (e.g., 0.01 for a parameter range [0,1]) and adjust based on application.
deprecated The `vis` module for visualization is deprecated in favor of `matplotlib` or `plotly` backends.
fix Use `from geomdl.visualization import VisMPL` or `VisPlotly` instead of the old `vis` module.

Create and evaluate a B-Spline curve using the geomdl library.

from geomdl import BSpline
from geomdl import knotvector
from geomdl import utilities

# Create a 3D B-Spline curve
curve = BSpline.Curve()
curve.degree = 3
curve.ctrlpts = [[0, 0, 0], [1, 2, 0], [3, 1, 0], [4, 2, 0], [5, 0, 0]]
curve.knotvector = knotvector.generate(curve.degree, len(curve.ctrlpts))
curve.delta = 0.01
curve.evaluate()

# Print evaluated points
for pt in curve.evalpts:
    print(pt)