Skip to main content

beziervis

Watch a Bézier curve build itself, and evaluate millions of curve points with a fast NumPy core.

Tests PyPI Python License: MIT Open in Colab

Animation of de Casteljau's algorithm tracing a degree-4 Bézier curve

▶ Try it in your browser: drag the control points and watch the construction follow. Nothing to install.

  • For learning: animate de Casteljau's algorithm level by level, in 2-D or 3-D, then save it as a GIF or MP4 or play it inline in Jupyter.
  • For computing: evaluate curves of any degree, in any dimension, singly or in batches of thousands. Under the hood this is a Bernstein-matrix NumPy core, with optional Numba kernels for a further 3–40× speed-up.
  • Small: the only required dependency is NumPy. Animation and acceleration are opt-in extras.

Live demo · Quickstart notebook · Gallery · API · CLI · How it works · Performance · Contributing · Changelog

Install

pip install beziervis            # core: NumPy only
pip install "beziervis[all]"     # + Numba acceleration and matplotlib animations
extra adds for
[anim] matplotlib, Pillow animate() and the beziervis command
[fast] Numba JIT and multi-threaded evaluation, used automatically
[all] both everything

Requires Python 3.11 or newer. Tested on Linux, macOS and Windows.

Quickstart

import beziervis as bv

ctrl = [[0, 0], [5, 10], [9, 7], [4, 3]]       # 4 control points -> a cubic curve

pts = bv.points(ctrl, n=200)                   # (200, 2) NumPy array, from ctrl[0] to ctrl[-1]
bv.animate(ctrl, verbose=True).save("curve.gif")

A cubic Bézier curve being traced

  • Input: control points can be a list or a NumPy array of shape (k, d), in any dimension d; the result has shape (n, d).
  • Displaying: .show() opens a window. In Jupyter, an animation that is the last expression in a cell plays inline.
  • Saving: .save() writes .gif (Pillow) or .mp4 (needs ffmpeg), and works on servers and in CI without a display.

Thirteen short, self-contained scripts in examples/, each a few dozen lines. Click an image for its code.

A loop, every level drawn
A loop, every level drawn
3,000 curves in one call
3,000 curves in one call
Broad-nib calligraphy
Broad-nib calligraphy
CSS easing curves
CSS easing curves
Curvature comb
Curvature comb
Two mirrored cubics
Two mirrored cubics
Even spacing by length
Even spacing by length
Recursive subdivision
Recursive subdivision
Camera path: position + colour in 6-D
Camera path: position + colour in 6-D
A roller-coaster loop, built in 3-D
A roller-coaster loop, built in 3-D
A helix from 12 cubic pieces
A helix from 12 cubic pieces
How a Bézier surface is built
How a Bézier surface is built

API

function returns
points(ctrl, n=100, t=None) (n, d) points at n evenly spaced t in [0, 1], or at the t values you pass
points_batch(curves, n=100) (m, n, d) points for m curves of equal degree, given as (m, k, d)
casteljau_steps(ctrl, t) every level of the construction: [(k, d), (k-1, d), …, (1, d)]
split(ctrl, t=0.5) (left, right): two curves of the same degree that join at t
derivative(ctrl) control points of the derivative (hodograph) curve
elevate(ctrl, times=1) the same curve with times more control points
arc_length(ctrl) the curve's length (Gauss–Legendre quadrature, error around 1e-10)
animate(ctrl, frames=100, verbose=False, …) a BezierAnimation with .save(), .show() and .to_jshtml()
random_control_points(n, seed=None) n random integer points in [-100, 100)
set_backend(name) / get_backend() choose or report the backend: "numpy", "numba" or "auto"

animate() also takes labels, fps, hold (frames to pause on the finished curve), size (pixels), cmap and title. Give it 3-D control points and it animates in 3-D, with a floor shadow for depth and a camera that sways around the curve; elev, azim and spin (degrees of sway, 0 for a still camera) set the view, and start picks where the loop begins, so a GIF's still preview can show the construction half-built. Every function has a docstring with the details; try help(bv.animate).

import numpy as np

left, right = bv.split(ctrl, 0.5)
velocity    = bv.points(bv.derivative(ctrl), n=200)     # tangent vectors along the curve
length      = bv.arc_length(ctrl)
many        = bv.points_batch(np.random.rand(10_000, 4, 2), n=100)   # (10000, 100, 2)

Command line

beziervis --points "0,0 5,10 9,7 4,3" --verbose --save curve.gif
beziervis -n 5 --seed 42                  # 5 random control points, reproducible
beziervis -n 5 --dim 3 --verbose          # a random curve in 3-D
python -m beziervis --help                # same thing, without the script on PATH
option meaning
-p, --points "x,y x,y …" control points (otherwise random); use x,y,z for 3-D
-n N / --dim D number of random control points (default 4) and their dimension, 2 or 3 (default 2)
--seed S random seed
-v, --verbose draw the intermediate construction lines
-f, --frames F / --fps R animation steps (default 100) and playback speed (default 30)
--size PX / --no-labels figure size in pixels; hide point labels
-s, --save FILE write .gif or .mp4 instead of opening a window

How de Casteljau's algorithm works

A Bézier curve is defined by its control points (A0 … A3 below). To find the point at parameter t:

  1. Walk a fraction t along each edge of the control polygon. That gives one fewer point (B0 … B2).
  2. Repeat on the new points (C0, C1), then again, until a single point is left.
  3. That point (red) is on the curve. Sweep t from 0 to 1 and it traces the whole curve.

The same cubic curve at t = 0.2, 0.4, 0.6 and 0.8

steps = bv.casteljau_steps(ctrl, t=0.4)   # [A (4×2), B (3×2), C (2×2), point (1×2)]

The construction also splits a curve in two exactly: A0, B0, C0 and the red point are the control points of the left half. This is how split() is implemented.

Performance

Points are evaluated with a precomputed Bernstein matrix and one matrix multiply. Above degree 30, where that becomes numerically fragile, a vectorised de Casteljau is used instead. When Numba is installed, JIT-compiled kernels (multi-threaded for large inputs) are used automatically. Every backend agrees with the others to within 1e-12.

case naive Python NumPy Bernstein NumPy de Casteljau Numba serial Numba parallel
cubic, 1k points 5.95 ms 60 µs 53.6 µs 22.8 µs 21.1 µs
cubic, 1M points – 71.5 ms 79.2 ms 25.9 ms 10.6 ms
degree 10, 100k points – 21.4 ms 52.4 ms 7.93 ms 2.33 ms
degree 50, 100k points – – 1.02 s 131 ms 25 ms
10k cubics × 100 points – 36.1 ms – – 4.85 ms

Best of 5 runs on Windows 11, Python 3.12, NumPy 2.5, Numba 0.68. To reproduce: python benchmarks/bench.py.

  • Choosing a backend: set BEZIERVIS_BACKEND=numpy|numba|auto before import, or call bv.set_backend(...) at any time.
  • First Numba call: it compiles the kernels, which takes about a second the first time and is then cached on disk.
  • Small inputs: for a single curve with a few hundred points, every backend takes microseconds, so pick whichever you have installed.

FAQ

Saving .mp4 fails. MP4 needs ffmpeg on your PATH. GIF needs only Pillow.

The animation is cluttered with many control points. Use verbose=False, which draws only the polygon and the curve, or labels=False. Labels switch off automatically above 10 points.

Can I animate 3-D curves? Yes. Pass control points with three coordinates, e.g. bv.animate([[0, 0, 0], [4, 0, 8], [8, 8, 8], [8, 8, 0]], verbose=True), or use beziervis --dim 3 on the command line. Animation covers 2-D and 3-D; the maths functions (points, split, derivative, …) work in any dimension. That is handy for more than geometry: give each control point extra columns, such as colour, zoom or joint angles, and one call smooths them all together (flythrough_3d.py does this in 6-D).

How does this compare with the bezier package? bezier is a mature computational-geometry library with curve intersection, surfaces and a compiled core, and the right choice for CAD-grade geometry. beziervis is smaller and focused on teaching and visualising the construction, plus fast batch evaluation in pure NumPy or Numba.

Contributing

Contributions of every size are welcome, and you don't need to know the maths to help.

You could Where to start
Report a bug or a confusing error message Bug report form, ideally with a few lines that reproduce it
Suggest a feature Feature request form. For anything big, agree on the API in the issue before writing code
Add an example to the gallery One script in examples/ with a main(out_dir=".") that saves one image. The tests pick it up automatically
Improve the browser demo docs/demo/: plain HTML, CSS and JavaScript, no build step
Make it faster Run python benchmarks/bench.py before and after, and put both numbers in the PR
Fix the docs Typos, clearer explanations and better docstrings all count

Issues labelled good first issue are small and well-scoped. To set up and run the same checks as CI:

git clone https://github.com/venkateshwara-gopisetti/Bezier-Curves && cd Bezier-Curves
pip install -e ".[dev]"
pytest                                          # tests, on every installed backend
pylint src/beziervis benchmarks docs examples   # must stay at 10.00/10

CONTRIBUTING.md has the code guidelines and the PR checklist. Everyone taking part agrees to the Code of Conduct.

Citation

If beziervis helps your research, teaching or course material, please cite it:

@software{gopisetti_beziervis_2026,
  author  = {Gopisetti, Venkateshwara},
  title   = {beziervis: Bézier curve evaluation and de Casteljau animations for Python},
  year    = {2026},
  version = {1.1.0},
  url     = {https://github.com/venkateshwara-gopisetti/Bezier-Curves},
  license = {MIT}
}

APA: Gopisetti, V. (2026). beziervis: Bézier curve evaluation and de Casteljau animations for Python (Version 1.1.0) [Computer software]. https://github.com/venkateshwara-gopisetti/Bezier-Curves

The metadata lives in CITATION.cff, so GitHub's Cite this repository button (in the sidebar) gives the same entries. To cite a different release, change version to the one you used (python -c "import beziervis; print(beziervis.__version__)").

If you use beziervis in a paper, course or project, I'd love to hear about it: open an issue with a link.

License

MIT © Venkateshwara Gopisetti

Metadata

Release files for beziervis 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for beziervis 1.1.0
File Size Uploaded Provenance Actions
beziervis-1.1.0.tar.gz 36.0 kB With provenance Details for beziervis-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for beziervis 1.1.0
File Interpreter ABI Platform Actions
beziervis-1.1.0-py3-none-any.whl Python 3 none any Details for beziervis-1.1.0-py3-none-any.whl

Total release size: 57.7 kB

Release files / beziervis-1.1.0.tar.gz

Download URL beziervis-1.1.0.tar.gz
Size 36.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7a53a023595597020fb25ebc6ab772388441b1952ba1edd8c9ac9681b1d43bb
BLAKE2b-256 checksum
How to use checksums
76e24107a6fc2a017240d54046a0dc2cc076b4883c9616caf805f2f6175be67e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / beziervis-1.1.0-py3-none-any.whl

Download URL beziervis-1.1.0-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b262d365aa5c10ec1ce074b6c1528c50ca1e5c281be649574e3fac866aea7a74
BLAKE2b-256 checksum
How to use checksums
c783199f3837b0a6d02ff5faaed644a3b164a10fe251dc477e3c01828e3cb932
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for beziervis 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for beziervis-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page