<jupyter_start><jupyter_text>This notebook is part of https://github.com/AudioSceneDescriptionFormat/splines, see also https://splines.readthedocs.io/.[back to overview](bezier.ipynb)  Properties of Bézier SplinesThe terms *Bézier spline* and *Bézier curve*can mean two slightly different things:1. A curve constructed from a single Bernstein polynomial of degree $d$,   given a *control polygon* consisting of a sequence of $d + 1$ vertices.   The first and last vertex   lies on the curve (at its start and end, respectively),   while the other vertices in general don't   (the curve *approximates* them).2. A piecewise polynomial curve consisting of multiple segments,   each of them constructed from a separate Bernstein polynomial.   The start and end points of neighboring control polygons typically coincide,   leading to $C^0$ continuity.   However, the overall control polygon can be chosen in a way to achieve   $G^1$ or $C^1$ (or even higher) continuity. Bézier splines in the latter sense are well knownfrom their common use in 2D vector graphics software,where cubic (i.e. degree 3) curve segments are typically used.Each segment has four control points:The start and end point of the segment(shared with the end and start of the previous and next segment, respectively)as well as two additional points that control the shape of the curve segment.<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import splines<jupyter_output><empty_output><jupyter_text>As an example,we create control points for a Bézier splineconsisting of four segments,having polynomial degrees of 1, 2, 3 and 4.<jupyter_code>control_points = [
    [(0, 0), (1, 4)],
    [(1, 4), (2, 2), (4, 4)],
    [(4, 4), (6, 4), (5, 2), (6, 2)],
    [(6, 2), (6, 0), (4, 0), (5, 1), (3, 1)],
]<jupyter_output><empty_output><jupyter_text>We are using the[splines.Bernstein](../python-module/splines.rstsplines.Bernstein)class to construct a Bézier splines from these control points.<jupyter_code>s = splines.Bernstein(control_points)
times = np.linspace(s.grid[0], s.grid[-1], 100)
fig, ax = plt.subplots()
for segment in control_points:
    xy = np.transpose(segment)
    ax.plot(*xy, '--')
    ax.scatter(*xy, color='grey')
ax.plot(*s.evaluate(times).T, 'k.')
ax.axis('equal');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10753156290814106, 'fraction_numerical': 0.0195907705703091, 'mean_word_length': 4.937984496124031, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '270175', 'license': 'MIT', 'n_tokens_mistral': 749, 'n_tokens_neox': 692, 'n_words': 280, 'path': 'doc/euclidean/bezier-properties.ipynb', 'repo_name': 'AudioSceneDescriptionFormat/splines', 'size': '2297'}