Skip to main content

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

Project description

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

CircleCI Build AppVeyor CI Build Code Coverage

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

This library provides:

Dive in and take a look!

https://cdn.rawgit.com/dhermes/bezier/0.5.0/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://cdn.rawgit.com/dhermes/bezier/0.5.0/docs/images/bernstein_basis.png

to define a curve as a linear combination:

https://cdn.rawgit.com/dhermes/bezier/0.5.0/docs/images/bezier_defn.png

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

https://cdn.rawgit.com/dhermes/bezier/0.5.0/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

bezier can be installed with pip:

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

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.0],
...     [0.5, 1.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.0],
...     [0.25,  2.0],
...     [0.5 , -2.0],
...     [0.75,  2.0],
...     [1.0 ,  0.0],
... ])
>>> curve2 = bezier.Curve.from_nodes(nodes2)
>>> intersections = curve1.intersect(curve2)
>>> intersections
array([[ 0.31101776, 0.42857143],
       [ 0.68898224, 0.42857143],
       [ 0.        , 0.        ],
       [ 1.        , 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(
...     intersections[:, 0], intersections[:, 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://cdn.rawgit.com/dhermes/bezier/0.5.0/docs/images/curves1_and_13.png

For API-level documentation, check out the Bézier 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
bezier-0.5.0-cp27-cp27m-macosx_10_6_intel.whl (2.5 MB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-cp27m-manylinux1_i686.whl (1.6 MB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-cp27m-manylinux1_x86_64.whl (1.7 MB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-cp27mu-manylinux1_i686.whl (1.6 MB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-cp27mu-manylinux1_x86_64.whl (1.7 MB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-none-win32.whl (665.2 kB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp27-none-win_amd64.whl (648.9 kB) Copy SHA256 hash SHA256 Wheel cp27
bezier-0.5.0-cp35-cp35m-macosx_10_6_intel.whl (2.5 MB) Copy SHA256 hash SHA256 Wheel cp35
bezier-0.5.0-cp35-cp35m-manylinux1_i686.whl (1.6 MB) Copy SHA256 hash SHA256 Wheel cp35
bezier-0.5.0-cp35-cp35m-manylinux1_x86_64.whl (1.8 MB) Copy SHA256 hash SHA256 Wheel cp35
bezier-0.5.0-cp35-none-win32.whl (652.6 kB) Copy SHA256 hash SHA256 Wheel cp35
bezier-0.5.0-cp35-none-win_amd64.whl (640.7 kB) Copy SHA256 hash SHA256 Wheel cp35
bezier-0.5.0-cp36-cp36m-macosx_10_6_intel.whl (2.5 MB) Copy SHA256 hash SHA256 Wheel cp36
bezier-0.5.0-cp36-cp36m-manylinux1_i686.whl (1.6 MB) Copy SHA256 hash SHA256 Wheel cp36
bezier-0.5.0-cp36-cp36m-manylinux1_x86_64.whl (1.8 MB) Copy SHA256 hash SHA256 Wheel cp36
bezier-0.5.0-cp36-none-win32.whl (654.7 kB) Copy SHA256 hash SHA256 Wheel cp36
bezier-0.5.0-cp36-none-win_amd64.whl (643.7 kB) Copy SHA256 hash SHA256 Wheel cp36
bezier-0.5.0.tar.gz (528.3 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page