Skip to content

bezierkit: Bézier curve toolkit for Python

bezierkit

A small, renderer-independent Python toolkit for Bézier curves.

PyPI Python License

from bezierkit import BezierCurve, Point
from bezierkit.sampling import UniformSampler

curve = BezierCurve.cubic(
    Point(0, 0),
    Point(1, 2),
    Point(3, 2),
    Point(4, 0),
)

# Point(coords=(2.0, 1.5))
print(curve.at(0.5))

# cut the curve in two
left, right = curve.split(0.3)

sample = UniformSampler(200).sample(curve)
print(len(sample.points), "sample points")

Features

Mathematics and proofs

The guides state the properties the algorithms rely on as theorems: what the Bernstein basis guarantees, why de Casteljau's algorithm evaluates and subdivides a curve, how far a Hermite interpolant can stray, and what the exporters lose to rounding. Every proof is folded under its theorem, so the pages read as API documentation until you open one. The standard references are Farin (2002) and Prautzsch et al. (2002); see References.

Notation

A point lives in \(\mathbb{R}^d\) for some \(d \ge 1\); most figures use \(d = 2\). A Bézier curve of degree \(n\) has \(n + 1\) control points \(P_0, \dots, P_n\) and is the map

\[ B(t) = \sum_{i=0}^{n} b_{i,n}(t)\, P_i, \qquad t \in [0, 1], \]

where \(b_{i,n}(t) = \binom{n}{i} t^i (1-t)^{n-i}\) are the Bernstein polynomials. Every curve in the package is parameterized over \([0, 1]\); a parameter outside it raises ParameterOutOfDomain.

Reading guide

Topic Page
Points, vectors, parameters, errors Geometry values
Bernstein basis, curves, evaluation Bézier curves
Derivatives, subdivision, reversal Derivatives and subdivision
Cubic segments and piecewise paths Cubic segments and paths
Constructions and Hermite interpolation Constructions
Fitting functions and polylines Fitting
Tracing level sets Level sets
Sampling, JSON, SVG, TikZ, Matplotlib Sampling and export
Command line Command line

On first use, read the Quick start and Bézier curves.

Scope

Rendering style and diagram semantics are intentionally outside this package: it draws nothing. Intersections, B-splines and NURBS are future work.

Install

uv add bezierkit

Requires Python 3.10 or later. See Installation for extras and the development setup, or go straight to the Quick start.

Documentation

The following chapters cover bezierkit 1.1.0.

Examples

The scripts that draw the figures in the manual and on these pages come as one zip, sorted by topic.

Download all examples

Comments