points¶
- class janim.components.points.Cmpt_Points(*args, **kwargs)¶
基类:
Component,Generic- static resize_func(array: ~numpy.ndarray, length: int, fall_back: ~typing.Callable[[int], ~numpy.ndarray] = <function <lambda>>) ndarray¶
- copy() Self¶
- become(other: Cmpt_Points) Self¶
- not_changed(other: Cmpt_Points) bool¶
- classmethod align_for_interpolate(cmpt1: Cmpt_Points, cmpt2: Cmpt_Points) AlignedData[Self]¶
- interpolate(cmpt1: ~typing.Self, cmpt2: ~typing.Self, alpha: float, *, path_func: PathFunc = <function straight_path>) None¶
- get() ndarray¶
得到点坐标数据
- get_all() ndarray¶
得到自己以及后代物件的所有点坐标数据
- set(points: VectArray) Self¶
设置点坐标数据,每个坐标点都有三个分量
使用形如
.set([[1.5, 3, 2], [2, 1.5, 0]])的形式
- clear() Self¶
清除点
- extend(points: VectArray) Self¶
追加点坐标数据,每个坐标点都有三个分量
使用形如
.append([[1.5, 3, 2], [2, 1.5, 0]])的形式
- reverse() Self¶
使点倒序
- resize(length: int) Self¶
- count() int¶
点的数量
- has() bool¶
是否有点坐标数据
- get_start() ndarray¶
得到
points的第一个点
- get_end() ndarray¶
得到
points的最后一个点
- get_start_and_end() tuple[ndarray, ndarray]¶
得到
points的第一个和最后一个点
- point_from_proportion(alpha: float) ndarray¶
- pfp(alpha) ndarray¶
point_from_proportion的缩写
- property box: BoundingBox¶
表示物件(包括后代物件)的矩形包围框
- property self_box: BoundingBox¶
同
box,但仅表示自己points的包围框,不考虑后代物件的
- class BoundingBox(points: VectArray)¶
基类:
object边界框,
self.data包含三个元素,分别为左下,中心,右上- static compute(points: VectArray) ndarray¶
根据传入的
points计算得到包围框的 左下、中心、右上 三个点
- get(direction: Vect) ndarray¶
获取边界框边上的坐标
例如:
传入 UR,则返回边界框右上角的坐标
传入 RIGHT,则返回边界框右侧中心的坐标
- get_continuous(direction: Vect) ndarray¶
得到从中心发出的方向为
direction的射线与边界框的交点
- get_corners() ndarray¶
得到包围框(立方体)的八个顶点
- property top: ndarray¶
- property bottom: ndarray¶
- property right: ndarray¶
- property left: ndarray¶
- property zenith: ndarray¶
- property nadir: ndarray¶
- property center: ndarray¶
- length_over_dim(dim: int) float¶
- property width: float¶
- property height: float¶
- property depth: float¶
- coord(dim: int, direction=array([0., 0., 0.])) float¶
- get_x(direction=array([0., 0., 0.])) float¶
- property x: float¶
- get_y(direction=array([0., 0., 0.])) float¶
- property y: float¶
- get_z(direction=array([0., 0., 0.])) float¶
- property z: float¶
- 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
- apply_point_fn(func: PointFn, *, about_point: Vect | None = array([0., 0., 0.]), about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
对每个点依次传入
func进行变换;以默认的原点作用变换,而不是物件的中心
- apply_matrix(matrix: VectArray, *, about_point: Vect | None = None, about_edge: Vect | None = None, root_only: bool = False) Self¶
将矩阵变换作用于
points;以默认的原点作用变换,而不是物件的中心
- apply_complex_fn(func: ComplexFn, *, about_point: Vect | None = array([0., 0., 0.]), about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
将复变函数作用于
points;以默认的原点作用变换,而不是物件的中心
- rotate(angle: float, *, axis: Vect = array([0., 0., 1.]), about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
以
axis为方向,angle为角度旋转,可传入about_point指定相对于以哪个点为中心
- flip(axis: Vect = array([0., 1., 0.]), *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
绕 axis 轴翻转
- scale(scale_factor: float | Iterable, *, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
将物件缩放指定倍数
如果传入的倍数是可遍历的对象,那么则将其中的各个元素作为坐标各分量缩放的倍数, 例如传入
scale_factor为(2, 0.5, 1)则是在x方向上缩放为两倍,在y方向上压缩为原来的一半,在z方向上保持不变
- stretch(factor: float, *, dim: int, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
在指定的
dim方向上使物件伸缩
- rescale_to_fit(length: float, *, dim: int, stretch: bool = False, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
- set_width(width: float, *, stretch: bool = False, **kwargs) Self¶
如果
stretch为False(默认),则表示等比缩放
- set_height(height: float, *, stretch: bool = False, **kwargs) Self¶
如果
stretch为False(默认),则表示等比缩放
- set_depth(depth: float, *, stretch: bool = False, **kwargs) Self¶
如果
stretch为False(默认),则表示等比缩放
- set_size(width: float | None = None, height: float | None = None, depth: float | None = None, **kwargs) Self¶
- replace(item: Item, dim_to_match: int = 0, *, stretch: bool = False, root_only: bool = False, item_root_only: bool = False) Self¶
放到 item 的位置,并且在
dim_to_match维度上长度相同
- surround(item: Item, dim_to_match: int = 0, *, stretch: bool = False, buff: float = 0.25, root_only: bool = False, item_root_only: bool = False) Self¶
与
replace类似,但是会向外留出buff间距
- shear(factor: float = 0.2, direction: Vect = array([1., 0., 0.]), *, about_point: Vect | None = None, about_edge: Vect = array([0., 0., 0.]), root_only: bool = False) Self¶
切变
factor表示切变的程度direction表示切变的方向可以传入
about_point或about_edge控制参考点
- put_start_and_end_on(start: Vect, end: Vect) Self¶
通过旋转和缩放,使得物件的起点和终点被置于
start和end
- shift(vector: Vect, *, root_only=False) Self¶
相对移动
vector向量
- move_to(target: Item | Vect, *, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, item_root_only: bool = False) Self¶
移动到
target的位置
- move_to_by_indicator(indicator: Item, target: Item, *, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, indicator_root_only: bool = False, item_root_only: bool = False) Self¶
与
move_to()类似,但是该方法作用indicator被移动到target所计算出的位移, 而不是move_to()中self被移动到target的位移例如:
t1 = Typst('x^2 + y^2') t2 = Typst('x + y') t2.points.move_to_by_indicator(t2[1], t1[2])
可以将
t2移动至t1的位置, 并且使得t2的加号与t1的加号对齐备注
这个示例使用
match_pattern()会更简洁
- align_to(item_or_point: Item | Vect, direction: Vect = array([0., 0., 0.]), *, root_only: bool = False, item_root_only: bool = False) Self¶
对齐
例如,
item1.align_to(item2, UP)会将item1垂直移动,顶部与item2的上边缘对齐
- arrange(direction: Vect = array([1., 0., 0.]), center: bool = True, **kwargs) Self¶
将子物件按照
direction方向排列
- arrange_in_grid(n_rows: int | None = None, n_cols: int | None = None, buff: float | None = None, h_buff: float | None = None, v_buff: float | None = None, aligned_edge: ndarray = array([0., 0., 0.]), by_center_point: bool = False, fill_rows_first: bool = True) Self¶
将子物件按网格方式排列
n_rows,n_cols: 行数、列数v_buff,h_buff: 行距、列距aligned_edge: 对齐边缘by_center_point: 默认为False;若设置为True,则仅将物件视为中心点,不考虑物件的宽高
- arrange_by_offset(offset: Vect, *, aligned_edge: Vect = array([0., 0., 0.]), center: bool = True) Self¶
- to_center(root_only=False) Self¶
移动到原点
(0, 0, 0)
- to_border(direction: Vect, buff: float = 0.5) Self¶
移动到视框的边界
- next_to(target: Item | Vect, direction: Vect = array([1., 0., 0.]), *, buff: float = 0.25, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, item_root_only: bool = False) Self¶
将该物件放到
target旁边
- next_to_by_indicator(indicator: Item, target: Item | Vect, direction: Vect = array([1., 0., 0.]), *, buff: float = 0.25, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, indicator_root_only: bool = False, item_root_only: bool = False) Self¶
与
next_to()类似,但是该方法作用indicator被放到target旁边所计算出的位移, 而不是move_to()中self被放到target旁边的位移例如:
t1 = Typst('x^2 + y^2') t2 = Typst('x + y z w') t2.points.next_to_by_indicator(t2[1], t1[2], DOWN)
可以将
t1对齐到t2的下方, 并且使得t1的加号在t2的加号的正下方备注
这个示例也可以使用字符索引
- shift_onto_screen(**kwargs) Self¶
- set_coord(value: float, *, dim: int, direction: Vect = array([0., 0., 0.]), root_only=False) Self¶
- set_x(x: float, direction: Vect = array([0., 0., 0.])) Self¶
- set_y(y: float, direction: Vect = array([0., 0., 0.])) Self¶
- set_z(z: float, direction: Vect = array([0., 0., 0.])) Self¶