matplotlib.bezier#

一个提供 Bézier 路径操作相关实用函数的模块。

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

基类: object

一个 d 维 Bézier 片段。

参数:
control_points(N, d) 数组

N 个控制点的位置。

axis_aligned_extrema()[source]#

返回曲线内部极值点的维度和位置。

极值点是曲线上其偏导数为零的点。

返回:
dims整数数组

在每个内部极值点处偏导数为零的索引 \(i\)

dzeros浮点数数组

与 dims 大小相同。使得 \(d/dx_i B(t) = 0\)\(t\)

property control_points#

曲线的控制点。

property degree#

多项式的次数。比控制点数量少一。

property dimension#

曲线的维度。

point_at_t(t)[source]#

在单个点处评估曲线,返回包含 d 个浮点数的元组。

property polynomial_coefficients#

Bézier 曲线的多项式系数。

警告

numpy.polyval 的约定相反。

返回:
(n+1, d) 数组

在多项式基中展开后的系数,其中 \(n\) 是 Bézier 曲线的次数,\(d\) 是其维度。这些是使得曲线可以写成 \(\sum_{j=0}^n C_j t^j\) 的数字 (\(C_j\))。

备注

系数计算方式如下:

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

其中 \(P_i\) 是曲线的控制点。

exception matplotlib.bezier.NonIntersectingPathException[source]#

基类:ValueError

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

检查两条线是否平行。

参数:
dx1, dy1, dx2, dy2浮点数

两条线的梯度 dy/dx

tolerance浮点数

线的平行判定角容差,单位为弧度。

返回:
is_parallel
  • 如果两条线方向相同,则为 1。

  • 如果两条线方向相反,则为 -1。

  • 否则为 False。

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

找到 Bézier 曲线与闭合路径的交点。

交点 t 由两个参数 t0, t1 近似,使得 t0 <= t <= t1

搜索从 t0t1 开始,并使用简单的二分算法,因此其中一个端点必须在路径内部,而另一个不在。当由 t0t1 参数化的点之间的距离小于给定 tolerance 时,搜索停止。

参数:
bezier_point_at_t可调用对象

一个函数,返回 Bézier 曲线在参数 t 处的 x, y 坐标。它必须具有以下签名:

bezier_point_at_t(t: float) -> tuple[float, float]
inside_closedpath可调用对象

一个函数,如果给定点 (x, y) 在闭合路径内部则返回 True。它必须具有以下签名:

inside_closedpath(point: tuple[float, float]) -> bool
t0, t1浮点数

搜索的起始参数。

tolerance浮点数

最终点之间的最大允许距离。

返回:
t0, t1浮点数

Bézier 路径参数。

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

找到 Bézier 曲线的控制点,该曲线通过 (c1x, c1y)、(mmx, mmy) 和 (c2x, c2y),参数值为 0、0.5 和 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]#

返回通过 (cx1, cy1) 且角度为 t1 的直线与通过 (cx2, cy2) 且角度为 t2 的直线之间的交点。

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

对于一条通过 (cx, cy) 且角度为 t 的直线,返回沿其垂直线以 length 距离处的两个点的位置。

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

给定二次 Bézier 控制点 bezier2,返回大致平行于给定 Bézier 曲线并由 width 分隔的二次 Bézier 线的控制点。

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

返回一个函数,用于检查一个点是否在以 (cx, cy) 为中心,半径为 r 的圆内。

返回的函数具有以下签名:

f(xy: tuple[float, float]) -> bool
matplotlib.bezier.make_wedged_bezier2(bezier2, width, w1=1.0, wm=0.5, w2=0.0)[source]#

get_parallels 类似,返回两条二次 Bézier 线的控制点,这些线大致平行于给定曲线并由 width 分隔。

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

在与闭合路径的交点处将 Bézier 曲线分成两部分。

参数:
bezier(N, 2) 数组类对象

Bézier 片段的控制点。参见 BezierSegment

inside_closedpath可调用对象

一个函数,如果给定点 (x, y) 在闭合路径内部则返回 True。另请参见 find_bezier_t_intersecting_with_closedpath

tolerance浮点数

交点的容差。另请参见 find_bezier_t_intersecting_with_closedpath

返回:
left, right

两个 Bézier 片段的控制点列表。

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

将由其控制点 beta 定义的 Bézier 片段在 t 处分成两个独立片段,并返回它们的控制点。

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

inside(x, y) 变为 False 的点处将路径分成两个片段。