Metadata-Version: 2.5
Name: beziervis
Version: 1.1.0
Summary: Fast Bézier curve evaluation in NumPy, with animations of de Casteljau's algorithm.
Project-URL: Homepage, https://github.com/venkateshwara-gopisetti/Bezier-Curves
Project-URL: Demo, https://venkateshwara-gopisetti.github.io/Bezier-Curves/
Project-URL: Issues, https://github.com/venkateshwara-gopisetti/Bezier-Curves/issues
Author: Venkateshwara Gopisetti
License-Expression: MIT
License-File: LICENSE
Keywords: animation,bezier,bezier-curve,de-casteljau,geometry,numba,numpy,visualization
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Visualization
Requires-Python: >=3.11
Requires-Dist: numpy>=1.23
Provides-Extra: all
Requires-Dist: matplotlib>=3.6; extra == 'all'
Requires-Dist: numba>=0.59; extra == 'all'
Requires-Dist: pillow>=9; extra == 'all'
Provides-Extra: anim
Requires-Dist: matplotlib>=3.6; extra == 'anim'
Requires-Dist: pillow>=9; extra == 'anim'
Provides-Extra: dev
Requires-Dist: matplotlib>=3.6; extra == 'dev'
Requires-Dist: numba>=0.59; extra == 'dev'
Requires-Dist: pillow>=9; extra == 'dev'
Requires-Dist: pylint>=3; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Provides-Extra: fast
Requires-Dist: numba>=0.59; extra == 'fast'
Description-Content-Type: text/markdown

# beziervis

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

[![Tests](https://github.com/venkateshwara-gopisetti/Bezier-Curves/actions/workflows/tests.yml/badge.svg)](https://github.com/venkateshwara-gopisetti/Bezier-Curves/actions/workflows/tests.yml)
[![PyPI](https://img.shields.io/pypi/v/beziervis.svg)](https://pypi.org/project/beziervis/)
[![Python](https://img.shields.io/pypi/pyversions/beziervis.svg)](https://pypi.org/project/beziervis/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/LICENSE)
[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/quickstart.ipynb)

<p align="center">
  <img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/hero.gif" width="480" alt="Animation of de Casteljau's algorithm tracing a degree-4 Bézier curve">
</p>

<p align="center"><b><a href="https://venkateshwara-gopisetti.github.io/Bezier-Curves/">▶ Try it in your browser</a></b>: drag the control points and watch the construction follow. Nothing to install.</p>

- **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](https://venkateshwara-gopisetti.github.io/Bezier-Curves/) · [Quickstart notebook](https://colab.research.google.com/github/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/quickstart.ipynb) · [Gallery](#gallery) · [API](#api) · [CLI](#command-line) · [How it works](#how-de-casteljaus-algorithm-works) · [Performance](#performance) · [Contributing](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/CONTRIBUTING.md) · [Changelog](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/CHANGELOG.md)

## Install

```bash
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

```python
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")
```

<p align="center">
  <img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/simple.gif" width="320" alt="A cubic Bézier curve being traced">
</p>

- **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.

## Gallery

Thirteen short, self-contained scripts in [`examples/`](https://github.com/venkateshwara-gopisetti/Bezier-Curves/tree/master/examples), each a few dozen lines. Click an image for its code.

<table>
  <tr><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/loop_animation.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/loop.gif" alt="A loop, every level drawn"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/loop_animation.py">A loop, every level drawn</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/generative_art.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/generative_art.png" alt="3,000 curves in one call"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/generative_art.py">3,000 curves in one call</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/calligraphy.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/calligraphy.png" alt="Broad-nib calligraphy"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/calligraphy.py">Broad-nib calligraphy</a></sub></td></tr>
  <tr><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/easing.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/easing.png" alt="CSS easing curves"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/easing.py">CSS easing curves</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/curvature_comb.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/curvature_comb.png" alt="Curvature comb"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/curvature_comb.py">Curvature comb</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/heart.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/heart.png" alt="Two mirrored cubics"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/heart.py">Two mirrored cubics</a></sub></td></tr>
  <tr><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/arc_length.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/arc_length.png" alt="Even spacing by length"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/arc_length.py">Even spacing by length</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/subdivision.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/subdivision.png" alt="Recursive subdivision"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/subdivision.py">Recursive subdivision</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/flythrough_3d.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/flythrough_3d.png" alt="Camera path: position + colour in 6-D"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/flythrough_3d.py">Camera path: position + colour in 6-D</a></sub></td></tr>
  <tr><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/coaster_3d_animation.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/coaster_3d.gif" alt="A roller-coaster loop, built in 3-D"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/coaster_3d_animation.py">A roller-coaster loop, built in 3-D</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/helix_3d.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/helix_3d.gif" alt="A helix from 12 cubic pieces"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/helix_3d.py">A helix from 12 cubic pieces</a></sub></td><td align="center" width="33%"><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/surface_3d_animation.py"><img src="https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/gallery/surface_3d.gif" alt="How a Bézier surface is built"></a><br><sub><a href="https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/surface_3d_animation.py">How a Bézier surface is built</a></sub></td></tr>
</table>

## 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)`.

```python
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

```bash
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](https://raw.githubusercontent.com/venkateshwara-gopisetti/Bezier-Curves/master/docs/assets/how-it-works.png)

```python
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 |

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

- **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](https://ffmpeg.org/download.html) 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`](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/examples/flythrough_3d.py) does this in 6-D).

**How does this compare with the [`bezier`](https://pypi.org/project/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](https://github.com/venkateshwara-gopisetti/Bezier-Curves/issues/new?template=bug_report.yml), ideally with a few lines that reproduce it |
| Suggest a feature | [Feature request form](https://github.com/venkateshwara-gopisetti/Bezier-Curves/issues/new?template=feature_request.yml). For anything big, agree on the API in the issue before writing code |
| Add an example to the gallery | One script in [`examples/`](https://github.com/venkateshwara-gopisetti/Bezier-Curves/tree/master/examples) with a `main(out_dir=".")` that saves one image. The tests pick it up automatically |
| Improve the browser demo | [`docs/demo/`](https://github.com/venkateshwara-gopisetti/Bezier-Curves/tree/master/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](https://github.com/venkateshwara-gopisetti/Bezier-Curves/labels/good%20first%20issue) are small and well-scoped. To set up and run the same checks as CI:

```bash
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](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/CONTRIBUTING.md) has the code guidelines and the PR checklist. Everyone taking part agrees to the [Code of Conduct](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/CODE_OF_CONDUCT.md).

## Citation

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

```bibtex
@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`](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/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](https://github.com/venkateshwara-gopisetti/Bezier-Curves/issues) with a link.

## License

[MIT](https://github.com/venkateshwara-gopisetti/Bezier-Curves/blob/master/LICENSE) © Venkateshwara Gopisetti
