matplotlib.bezier#

一个提供关于贝塞尔路径操作的实用函数的模块。

class matplotlib.bezier.BezierSegment(control_points)[源代码][源代码]#

基类:object

一个d维的贝塞尔线段。

参数:
控制点(N, d) 数组

位置的 N 控制点。

axis_aligned_extrema()[源代码][源代码]#

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

极值是曲线上的点,在这些点上,其一阶偏导数为零。

返回:
维度int 数组

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

dzeros浮点数数组

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

property control_points#

曲线的控制点。

property degree#

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

property dimension#

曲线的维度。

point_at_t(t)[源代码][源代码]#

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

property polynomial_coefficients#

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

警告

遵循与 numpy.polyval 相反的约定。

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

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

注释

系数计算如下

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

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

exception matplotlib.bezier.NonIntersectingPathException[源代码][源代码]#

基类:ValueError

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

检查两条线是否平行。

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

两条线的梯度 dy/dx

容差浮动

角度公差,单位为弧度,在此公差范围内的线条被视为平行。

返回:
is_parallel
  • 1 如果两条线在同一方向上平行。

  • -1 如果两条线在相反方向上平行。

  • 否则为假。

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

找到贝塞尔曲线与闭合路径的交点。

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

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

参数:
bezier_point_at_t可调用

一个返回参数 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浮动

搜索的启动参数。

容差浮动

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

返回:
t0, t1浮动

Bézier 路径参数。

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

找到通过参数值 0、0.5 和 1 的贝塞尔曲线的控制点 (c1x, c1y), (mmx, mmy), 和 (c2x, c2y)。

matplotlib.bezier.get_cos_sin(x0, y0, x1, y1)[源代码][源代码]#
matplotlib.bezier.get_intersection(cx1, cy1, cos_t1, sin_t1, cx2, cy2, cos_t2, sin_t2)[源代码][源代码]#

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

matplotlib.bezier.get_normal_points(cx, cy, cos_t, sin_t, length)[源代码][源代码]#

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

matplotlib.bezier.get_parallels(bezier2, width)[源代码][源代码]#

给定二次贝塞尔控制点 bezier2,返回大致平行于给定贝塞尔曲线的二次贝塞尔曲线的控制点,间隔为 width

matplotlib.bezier.inside_circle(cx, cy, r)[源代码][源代码]#

返回一个函数,该函数检查一个点是否在以 (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)[源代码][源代码]#

类似于 get_parallels,返回两条二次贝塞尔曲线的控制点,这两条曲线具有大致平行于给定曲线的宽度,且宽度为 width

matplotlib.bezier.split_bezier_intersecting_with_closedpath(bezier, inside_closedpath, tolerance=0.01)[源代码][源代码]#

在贝塞尔曲线与闭合路径的交点处将其分割为两条。

参数:
贝塞尔曲线(N, 2) 数组类

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

inside_closedpath可调用

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

容差浮动

交点的容差。另见 find_bezier_t_intersecting_with_closedpath

返回:
左, 右

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

matplotlib.bezier.split_de_casteljau(beta, t)[源代码][源代码]#

将由控制点 beta 定义的贝塞尔曲线段在 t 处分割为两个独立的线段,并返回它们的控制点。

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

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