Helper for Bézier Curves, Triangles, and Higher Order Objects
Clone or download
Latest commit 9231d92 Nov 15, 2018
Permalink
Failed to load latest commit information.
.circleci Uber-commit of project updates. Oct 20, 2018
appveyor Renaming `libbezier.dll` to `bezier.dll`. Oct 31, 2018
docs [ci skip] Using code font for `libbezier.dll` ref Oct 31, 2018
scripts Dropping `imp` for `importlib`. Nov 15, 2018
src/bezier Restoring source tree to "non-release" form. Oct 31, 2018
tests Enabling Sphinx nitpicky mode. Oct 16, 2018
.appveyor.yml Uber-commit of project updates. Oct 20, 2018
.clang-format Running `.c` and `.h` files through `clang-format`. Oct 31, 2018
.coveragerc Actually adding unit tests for `__config__` module. Nov 16, 2017
.gitignore Removing all traces of 32-bit support for OS X. Aug 20, 2018
.readthedocs.yml Reverting RTD to Python 3.6. Aug 14, 2018
.travis.yml Uber-commit of project updates. Oct 20, 2018
DEVELOPMENT.rst Restoring source tree to "non-release" form. Oct 31, 2018
DEVELOPMENT.rst.template Renaming `libbezier.dll` to `bezier.dll`. Oct 31, 2018
LICENSE Replacing all remaining http links with https equivalents. Jul 20, 2017
MANIFEST.in Adding `setup_helpers_windows.py` to `MANIFEST.in`. Oct 9, 2017
README.rst Restoring source tree to "non-release" form. Oct 31, 2018
README.rst.release.template [ci skip] Using `sanitize=true` for GitHub hosted SVGs. Oct 31, 2018
README.rst.template "Collating" all Python specific documentation Oct 24, 2018
codemeta.json [ci skip] Updated README / docs for release 0.9.0. Oct 31, 2018
noxfile.py Running `.c` and `.h` files through `clang-format`. Oct 31, 2018
paper.bib Re-write of summary in `paper.md`. Aug 1, 2017
paper.md [ci skip] Updated README / docs for release 0.9.0. Oct 31, 2018
pylintrc Re-running latest version of `black`. Jul 26, 2018
setup.cfg Started change over to nox (from tox). May 22, 2017
setup.py Restoring source tree to "non-release" form. Oct 31, 2018
setup_helpers.py Upgrading nox-automation to nox. (#127) Oct 16, 2018
setup_helpers_osx.py Removing all traces of 32-bit support for OS X. Aug 20, 2018
setup_helpers_windows.py Renaming `libbezier.dll` to `bezier.dll`. Oct 31, 2018

README.rst

bezier

Helper for Bézier Curves, Triangles, and Higher Order Objects

CircleCI Build Travis Build AppVeyor CI Build Code Coverage

PyPI Latest Package Versions

Documentation Status Zenodo DOI for ``bezier`` "Journal of Open Source Science" DOI for ``bezier``

This library provides:

Dive in and take a look!

https://raw.githubusercontent.com/dhermes/bezier/master/docs/images/surfaces6Q_and_7Q.png

Why Bézier?

A Bézier curve (and surface, etc.) is a parametric curve that uses the Bernstein basis:

https://raw.githubusercontent.com/dhermes/bezier/master/docs/images/bernstein_basis.png

to define a curve as a linear combination:

https://raw.githubusercontent.com/dhermes/bezier/master/docs/images/bezier_defn.png

This comes from the fact that the weights sum to one:

https://raw.githubusercontent.com/dhermes/bezier/master/docs/images/sum_to_unity.png

This can be generalized to higher order by considering three, four, etc. non-negative weights that sum to one (in the above we have the two non-negative weights s and 1 - s).

Due to their simple form, Bézier curves:

  • can easily model geometric objects as parametric curves, surfaces, etc.
  • can be computed in an efficient and numerically stable way via de Casteljau's algorithm
  • can utilize convex optimization techniques for many algorithms (such as curve-curve intersection), since curves (and surfaces, etc.) are convex combinations of the basis

Many applications -- as well as the history of their development -- are described in "The Bernstein polynomial basis: A centennial retrospective", for example;

  • aids physical analysis using finite element methods (FEM) on isogeometric models by using geometric shape functions called NURBS to represent data
  • used in robust control of dynamic systems; utilizes convexity to create a hull of curves

Installing

The bezier Python package can be installed with pip:

$ python    -m pip install --upgrade bezier
$ python2.7 -m pip install --upgrade bezier
$ python3.7 -m pip install --upgrade bezier

bezier is open-source, so you can alternatively grab the source code from GitHub and install from source.

Getting Started

For example, to create a curve:

>>> nodes1 = np.asfortranarray([
...     [0.0, 0.5, 1.0],
...     [0.0, 1.0, 0.0],
... ])
>>> curve1 = bezier.Curve(nodes1, degree=2)

The intersection (points) between two curves can also be determined:

>>> nodes2 = np.asfortranarray([
...     [0.0, 0.25,  0.5, 0.75, 1.0],
...     [0.0, 2.0 , -2.0, 2.0 , 0.0],
... ])
>>> curve2 = bezier.Curve.from_nodes(nodes2)
>>> intersections = curve1.intersect(curve2)
>>> intersections
array([[0.31101776, 0.68898224, 0. , 1. ],
       [0.31101776, 0.68898224, 0. , 1. ]])
>>> s_vals = np.asfortranarray(intersections[0, :])
>>> points = curve1.evaluate_multi(s_vals)
>>> points
array([[0.31101776, 0.68898224, 0. , 1. ],
       [0.42857143, 0.42857143, 0. , 0. ]])

and then we can plot these curves (along with their intersections):

>>> import matplotlib.pyplot as plt
>>> import seaborn
>>> seaborn.set()
>>>
>>> ax = curve1.plot(num_pts=256)
>>> _ = curve2.plot(num_pts=256, ax=ax)
>>> lines = ax.plot(
...     points[0, :], points[1, :],
...     marker="o", linestyle="None", color="black")
>>> _ = ax.axis("scaled")
>>> _ = ax.set_xlim(-0.125, 1.125)
>>> _ = ax.set_ylim(-0.0625, 0.625)
>>> plt.show()

https://raw.githubusercontent.com/dhermes/bezier/master/docs/images/curves1_and_13.png

For API-level documentation, check out the Bézier Python package documentation.

Development

To work on adding a feature or to run the functional tests, see the DEVELOPMENT doc for more information on how to get started.

License

bezier is made available under the Apache 2.0 License. For more details, see the LICENSE.