matplotlib.bezier
#
A module providing some utility functions regarding Bézier path manipulation.
- classmatplotlib.bezier.BezierSegment(control_points)[source]#
Bases:
object
A d-dimensional Bézier segment.
- Parameters:
- control_points(N, d) array
Location of theN 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 partialderivatives is zero.
- Returns:
- dimsarray of int
Index\(i\) of the partial derivative which is zero at eachinterior extrema.
- dzerosarray of float
Of same size as dims. The\(t\) such that\(d/dx_i B(t) =0\)
- propertycontrol_points#
The control points of the curve.
- propertydegree#
Degree of the polynomial. One less the number of control points.
- propertydimension#
The dimension of the curve.
- propertypolynomial_coefficients#
The polynomial coefficients of the Bézier curve.
Warning
Follows opposite convention from
numpy.polyval
.- 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 bewritten\(\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.
- exceptionmatplotlib.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 gradientsdy/dx of the two lines.
- tolerancefloat
The angular tolerance in radians up to which the lines are consideredparallel.
- Returns:
- is_parallel
1 if two lines are parallel in same direction.
-1 if two lines are parallel in opposite direction.
False otherwise.
- 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 pointt is approximated by two parameterst0,t1such thatt0 <=t <=t1.
Search starts fromt0 andt1 and uses a simple bisecting algorithmtherefore one of the end points must be inside the path while the otherdoesn't. The search stops when the distance of the points parametrized byt0 andt1 gets smaller than the giventolerance.
- Parameters:
- bezier_point_at_tcallable
A function returning x, y coordinates of the Bézier at parametert.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 theclosed 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_intersection(cx1,cy1,cos_t1,sin_t1,cx2,cy2,cos_t2,sin_t2)[source]#
Return the intersection between the line through (cx1,cy1) at anglet1 and the line through (cx2,cy2) at anglet2.
- matplotlib.bezier.get_normal_points(cx,cy,cos_t,sin_t,length)[source]#
For a line passing through (cx,cy) and having an anglet, returnlocations of the two points located along its perpendicular line at thedistance oflength.
- matplotlib.bezier.get_parallels(bezier2,width)[source]#
Given the quadratic Bézier control pointsbezier2, returnscontrol points of quadratic Bézier lines roughly parallel to givenone separated bywidth.
- 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 radiusr.
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 quadraticBézier lines having a width roughly parallel to given one separated bywidth.
- 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 theclosed path. See also
find_bezier_t_intersecting_with_closedpath
.- tolerancefloat
The tolerance for the intersection. See also
find_bezier_t_intersecting_with_closedpath
.
- Returns:
- left, right
Lists of control points for the two Bézier segments.