matplotlib.bezier — Matplotlib 3.10.1 documentation (original) (raw)

A module providing some utility functions regarding Bézier path manipulation.

class matplotlib.bezier.BezierSegment(control_points)[source]#

Bases: object

A d-dimensional Bézier segment.

Parameters:

control_points(N, d) array

Location of the N control points.

axis_aligned_extrema()[source]#

Return the dimension and location of the curve's interior extrema.

The extrema are the points along the curve where one of its partial derivatives is zero.

Returns:

dimsarray of int

Index \(i\) of the partial derivative which is zero at each interior extrema.

dzerosarray of float

Of same size as dims. The \(t\) such that \(d/dx_i B(t) = 0\)

property control_points#

The control points of the curve.

property degree#

Degree of the polynomial. One less the number of control points.

property dimension#

The dimension of the curve.

point_at_t(t)[source]#

Evaluate the curve at a single point, returning a tuple of d floats.

property polynomial_coefficients#

The polynomial coefficients of the Bézier curve.

Returns:

(n+1, d) array

Coefficients after expanding in polynomial basis, where \(n\)is the degree of the Bézier curve and \(d\) its dimension. These are the numbers (\(C_j\)) such that the curve can be written \(\sum_{j=0}^n C_j t^j\).

Notes

The coefficients are calculated as

\[{n \choose j} \sum_{i=0}^j (-1)^{i+j} {j \choose i} P_i\]

where \(P_i\) are the control points of the curve.

exception matplotlib.bezier.NonIntersectingPathException[source]#

Bases: ValueError

matplotlib.bezier.check_if_parallel(dx1, dy1, dx2, dy2, tolerance=1e-05)[source]#

Check if two lines are parallel.

Parameters:

dx1, dy1, dx2, dy2float

The gradients dy/dx of the two lines.

tolerancefloat

The angular tolerance in radians up to which the lines are considered parallel.

Returns:

is_parallel

matplotlib.bezier.find_bezier_t_intersecting_with_closedpath(bezier_point_at_t, inside_closedpath, t0=0.0, t1=1.0, tolerance=0.01)[source]#

Find the intersection of the Bézier curve with a closed path.

The intersection point t is approximated by two parameters t0, _t1_such that t0 <= t <= t1.

Search starts from t0 and t1 and uses a simple bisecting algorithm therefore one of the end points must be inside the path while the other doesn't. The search stops when the distance of the points parametrized by_t0_ and t1 gets smaller than the given tolerance.

Parameters:

bezier_point_at_tcallable

A function returning x, y coordinates of the Bézier at parameter t. It must have the signature:

bezier_point_at_t(t: float) -> tuple[float, float]

inside_closedpathcallable

A function returning True if a given point (x, y) is inside the closed path. It must have the signature:

inside_closedpath(point: tuple[float, float]) -> bool

t0, t1float

Start parameters for the search.

tolerancefloat

Maximal allowed distance between the final points.

Returns:

t0, t1float

The Bézier path parameters.

matplotlib.bezier.find_control_points(c1x, c1y, mmx, mmy, c2x, c2y)[source]#

Find control points of the Bézier curve passing through (c1x, c1y), (mmx, mmy), and (c2x, c2y), at parametric values 0, 0.5, and 1.

matplotlib.bezier.get_cos_sin(x0, y0, x1, y1)[source]#

matplotlib.bezier.get_intersection(cx1, cy1, cos_t1, sin_t1, cx2, cy2, cos_t2, sin_t2)[source]#

Return the intersection between the line through (cx1, cy1) at angle_t1_ and the line through (cx2, cy2) at angle t2.

matplotlib.bezier.get_normal_points(cx, cy, cos_t, sin_t, length)[source]#

For a line passing through (cx, cy) and having an angle t, return locations of the two points located along its perpendicular line at the distance of length.

matplotlib.bezier.get_parallels(bezier2, width)[source]#

Given the quadratic Bézier control points bezier2, returns control points of quadratic Bézier lines roughly parallel to given one separated by width.

matplotlib.bezier.inside_circle(cx, cy, r)[source]#

Return a function that checks whether a point is in a circle with center (cx, cy) and radius r.

The returned function has the signature:

f(xy: tuple[float, float]) -> bool

matplotlib.bezier.make_wedged_bezier2(bezier2, width, w1=1.0, wm=0.5, w2=0.0)[source]#

Being similar to get_parallels, returns control points of two quadratic Bézier lines having a width roughly parallel to given one separated by_width_.

matplotlib.bezier.split_bezier_intersecting_with_closedpath(bezier, inside_closedpath, tolerance=0.01)[source]#

Split a Bézier curve into two at the intersection with a closed path.

Parameters:

bezier(N, 2) array-like

Control points of the Bézier segment. See BezierSegment.

inside_closedpathcallable

A function returning True if a given point (x, y) is inside the closed path. See also find_bezier_t_intersecting_with_closedpath.

tolerancefloat

The tolerance for the intersection. See alsofind_bezier_t_intersecting_with_closedpath.

Returns:

left, right

Lists of control points for the two Bézier segments.

matplotlib.bezier.split_de_casteljau(beta, t)[source]#

Split a Bézier segment defined by its control points beta into two separate segments divided at t and return their control points.

matplotlib.bezier.split_path_inout(path, inside, tolerance=0.01, reorder_inout=False)[source]#

Divide a path into two segments at the point where inside(x, y) becomes False.