points¶
- class janim.components.points.Cmpt_Points(*args, **kwargs)¶
Bases:
Component,Generic- static resize_func(array: ~numpy.ndarray, length: int, fall_back: ~typing.Callable[[int], ~numpy.ndarray] = <function <lambda>>) ndarray¶
- init_bind(bind: BindInfo)¶
Used for
Item._init_componentsSubclasses can inherit this function to perform item-related processing
- 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 the points
- get_all() ndarray¶
Get all points for self and descendant-items
- set(points: VectArray) Self¶
Set point coordinate data, with each point having three components
Use a format like
.set([[1.5, 3, 2], [2, 1.5, 0]])
- clear() Self¶
Clear points
- extend(points: VectArray) Self¶
Append point coordinate data, with each point having three components
Use a format like
.append([[1.5, 3, 2], [2, 1.5, 0]])
- reverse() Self¶
Reverse the order of points
- resize(length: int) Self¶
- count() int¶
The count of points
- has() bool¶
Checks if having points
- get_start() ndarray¶
Get the first point
- get_end() ndarray¶
Get the last point
- get_start_and_end() tuple[ndarray, ndarray]¶
Get the first and last points
- point_from_proportion(alpha: float) ndarray¶
- pfp(alpha) ndarray¶
Abbreviation for point_from_proportion
- property box: BoundingBox¶
Rectangular bounding box of the item (including descendant-items)
- property self_box: BoundingBox¶
Same as
box, but only represents the bounding box of its ownpoints, excluding descendant-items
- class BoundingBox(points: VectArray)¶
Bases:
objectBounding box,
self.dataincludes three elements representing the bottom-left, center, and top-right- static compute(points: VectArray) ndarray¶
Calculates the left-bottom, center, and right-top points of the bounding box based on the provided
points
- get(direction: Vect) ndarray¶
Get the coordinates on the borders of the bounding box
Examples:
If UR is passed, it returns the coordinates of the upper-right corner of the bounding bo
If RIGHT is passed, it returns the coordinates of the center on the right side of the bounding box
- get_continuous(direction: Vect) ndarray¶
Get the intersection point between a ray, emitted from the center in the direction of
direction, and the bounding box
- 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¶
Applies the given function
functo all points as a single parameter, and see the result as new pointsConsiders
about_pointas the origin. If it’sNone, then the edge in theabout_edgedirection is considered asabout_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¶
Applies the given function
functo each point individually for transformation
- apply_matrix(matrix: VectArray, *, about_point: Vect | None = None, about_edge: Vect | None = None, root_only: bool = False) Self¶
Apply a matrix transformation to the
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¶
Apply a complex-valued function to the
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¶
Rotate the item by an
anglearound the specifiedaxis, with an optionalabout_pointabout which the rotation should be performed
- 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¶
Flip the item around the specified 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 the item by a specified factor
If the scale factor provided is an iterable object, each element will be used as the scaling factor for the corresponding coordinate component. For example, if
scale_factoris(2, 0.5, 1), the item will be scaled by a factor of 2 along thexaxis, compressed by half along theyaxis, and remain unchanged along thezaxis
- 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¶
Stretch the object along the specified
dimdirection
- 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¶
If
stretchisFalse(default), it indicates proportional scaling
- set_height(height: float, *, stretch: bool = False, **kwargs) Self¶
If
stretchisFalse(default), it indicates proportional scaling
- set_depth(depth: float, *, stretch: bool = False, **kwargs) Self¶
If
stretchisFalse(default), it indicates proportional scaling
- 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¶
Moves to the position of the specified
itemand matches the length in thedim_to_matchdimension
- 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¶
Similar to
replacebut leaves a buffer space ofbuffaround the item
- 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¶
Rotate and scale this item such that its start and end points are positioned at
startandend
- property unit_normal: ndarray¶
计算三维点集的拟合平面的单位法向量
- face_to_camera(camera: Camera | types.EllipsisType = Ellipsis, *, rotate: float = 0, inverse: bool = False, normal_vector: Vect | types.EllipsisType = Ellipsis, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
使物件面向摄像机
实用参数:
rotate:在面向摄像机的基础上,绕摄像机视角旋转的角度inverse:是否让物件背向摄像机视
about_point为参考点,若其为None,则将物件在about_edge方向上的边界作为about_point
可手动指定
camera和法向量normal_vector,若无则会自动获取:camera默认为时间轴的self.cameranormal_vector默认通过unit_normal()计算
- shift(vector: Vect, *, root_only=False) Self¶
Shift the object by the specified
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¶
Move this item to the position of
target
- move_to_by_indicator(indicator: Item, target: Item | Vect, *, 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的位移Examples:
t1 = TypstMath('x^2 + y^2') t2 = TypstMath('x + y') t2.points.move_to_by_indicator(t2[1], t1[2])
可以将
t2移动至t1的位置, 并且使得t2的加号与t1的加号对齐Note
这个示例使用
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¶
Move this item to the origin
(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¶
Position this item next to
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旁边的位移Examples:
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的加号的正下方Note
这个示例也可以使用字符索引
- shift_onto_screen(**kwargs) Self¶
- shift_onto_screen_along_direction(direction: Vect, *, buff: float = 0.5) 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¶