vpoints

class janim.components.vpoints.Cmpt_VPoints(*args, **kwargs)

基类:Cmpt_Points, Generic

曲线点坐标数据

  • 每三个点表示一段二阶贝塞尔曲线,并且前后相接的曲线共用公共点。

    例如对于点坐标列表 [a, b, c, d, e, f, g],则表示这些曲线:[a, b, c] [c, d, e] [e, f, g]

  • NAN_POINT 视为子路径结束的表示。

    例如对于点坐标列表 [a, b, c, d, e, NAN_POINT, f, g, h],则表示两段子路径:[a, b, c, d, e][f, g, h]

  • 如果子路径的终止点和起始点相同,则该段子路径被视为闭合路径。

    只有闭合的子路径,才能够进行填充色的渲染

set(points: VectArray) Self

设置点坐标数据,每个坐标点都有三个分量

使用形如 .set([[1.5, 3, 2], [2, 1.5, 0]]) 的形式

apply_points_fn(func: PointsFn, *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self

将所有点作为单独的一个参数传入 func,并将 func 返回的结果作为新的点坐标数据

about_point 为原点,若其为 None,则将物件在 about_edge 方向上的边界作为 about_point

scale(scale_factor: float | Iterable, scale_stroke_radius: bool = False, *, root_only: bool = False, **kwargs) Self

将物件缩放指定倍数

如果传入的倍数是可遍历的对象,那么则将其中的各个元素作为坐标各分量缩放的倍数, 例如传入 scale_factor(2, 0.5, 1) 则是在 x 方向上缩放为两倍,在 y 方向上压缩为原来的一半,在 z 方向上保持不变

classmethod align_for_interpolate(cmpt1: Cmpt_VPoints, cmpt2: Cmpt_VPoints) AlignedData[Self]
interpolate(cmpt1: ~typing.Self, cmpt2: ~typing.Self, alpha: float, *, path_func: PathFunc = <function straight_path>) None
static align_path(path1: ndarray, path2: ndarray) tuple[ndarray, ndarray]
static insert_n_curves_to_point_list(n: int, points: VectArray) ndarray
insert_n_curves(n: int, root_only=False) Self
get_anchors() ndarray

得到曲线的锚点

get_handles() ndarray

得到曲线的控制点

property start_direction: ndarray
property end_direction: ndarray
static start_direction_from_points(points: ndarray) ndarray
static end_direction_from_points(points: ndarray) ndarray
close_path() Self
static get_bezier_tuples_from_points(points: VectArray) Iterable[ndarray]

points 得到由每一组贝塞尔曲线控制点组成的列表

例如,对于有 7 个点的 points,返回值是 (points[[0, 1, 2]], points[[2, 3, 4]], points[[4, 5, 6]])

get_bezier_tuples() Iterable[ndarray]

得到由每一组贝塞尔曲线控制点组成的列表,具体参考 get_bezier_tuples_from_points()

curves_count() int

得到曲线数量

get_nth_curve_points(n: int) VectArray

得到第 n 组的贝塞尔曲线控制点 (从 0 开始计数)

get_nth_curve_function(n: int) Callable[[float], ndarray]

返回值是第 n 组贝塞尔曲线的描点函数,传入 [0, 1] 之间的值,得到对应的在曲线上的点

get_nth_curve_length_pieces(n: int, sample_points: int | None = None) ndarray
quick_point_from_proportion(alpha: float) ndarray

相比 point_from_proportion() 而言,更快

但是这里假设所有的曲线都有相同的长度,所以是不准确的

curve_and_prop_of_partial_point(alpha: float) tuple[int, float]

如果你想要得到沿着整个曲线上所在比例为 alpha 处的点, 这个函数会返回这个比例所对应的曲线部分的索引,以及在这个曲线部分上需要行进的比例

point_from_proportion(alpha: float) ndarray
pointwise_become_partial(other: Cmpt_VPoints | Item, a: float, b: float) Self

将传入对象的曲线截取 [a, b] 区间(最大范围 [0, 1] 表示整个曲线)的部分后,设置到该对象上,且保持点的数量不变(将区间外的点都放到起点/终点处)

static partial_points(points: ndarray, a: float, b: float) ndarray

得到 points 所表示的曲线中 [a, b] 的部分(最大范围 [0, 1] 表示整个曲线),且保持点的数量不变(将区间外的点都放到起点/终点处)

注:当 a <= 0b >= 1 时,直接返回 points,不作拷贝

pointwise_become_partial_reduced(other: Cmpt_VPoints | Item, a: float, b: float) Self

将传入对象的曲线截取 [a, b] 区间(最大范围 [0, 1] 表示整个曲线)的部分后,设置到该对象上,丢弃区间外的点

static partial_points_reduced(points: ndarray, a: float, b: float) ndarray

得到 points 所表示的曲线中 [a, b] 的部分(最大范围 [0, 1] 表示整个曲线),丢弃区间外的点

注:当 a <= 0b >= 1 时,直接返回 points,不作拷贝

add_as_corners(points: VectArray) Self

以折线的方式将 points 添加

set_as_corners(points: VectArray) Self

将点数据设置为由 points 构成的折线

is_smooth(angle_tol: float = 0.017453292519943295) bool
get_joint_products() ndarray

得到每个锚点前后方向向量的点积

change_anchor_mode(mode: AnchorMode) Self
make_smooth(approx=False, root_only=False) Self

Edits the path so as to pass smoothly through all the current anchor points.

If approx is False, this may increase the total number of points.

make_approximately_smooth(root_only=False) Self
make_jagged(root_only=False) Self
static get_area_vector_from_points(points: ndarray) ndarray
property area_vector: ndarray

一个向量,其长度为锚点形成的多边形所围成的面积,根据右手定则指向垂直于该多边形的方向

property unit_normal: ndarray

单位法向量

walk_subpath_end_indices() Generator[int, None, None]

遍历每个子路径结尾的下标

get_subpath_end_indices() list[int]
get_closepath_flags() ndarray

得到子路径是否闭合的标志,结果长度与点数量相同

对于闭合路径,结果中对应部分会被设置为 True

static get_parts_by_end_indices(array: ndarray, end_indices: ndarray) list[ndarray]

根据子路径结尾下标的列表,将 array 分段

get_subpaths() list[ndarray]

得到子路径列表

add_subpath(points: VectArray) Self
property identity: tuple[int, ndarray]
width_along_direction(direction: Vect) float
same_shape(other: Cmpt_VPoints | Item) bool

判断两组点是否有完全相同的形状

对于相同形状的两组点还可以用 same_direction() 衡量方向重合度

same_direction(other: Cmpt_VPoints | Item) bool

对于 same_shape() 结果为 True 的两组点,可以通过该方法衡量方向重合度

  • 返回 -1 ~ 1 之间的值

  • 其中 1 表示完全同向,-1 表示完全反向,0 表示垂直

注:对于 same_shape() 结果为 False 的两组点,该方法的结果没有实际含义

class janim.components.vpoints.AnchorMode(*values)

基类:Enum

Jagged = 0
ApproxSmooth = 1
TrueSmooth = 2