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_components

Subclasses 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 own points, excluding descendant-items

class BoundingBox(points: VectArray)

Bases: object

Bounding box, self.data includes 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 func to all points as a single parameter, and see the result as new points

Considers about_point as the origin. If it’s None, then the edge in the about_edge direction is considered as 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

Applies the given function func to 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 angle around the specified axis, with an optional about_point about 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_factor is (2, 0.5, 1), the item will be scaled by a factor of 2 along the x axis, compressed by half along the y axis, and remain unchanged along the z axis

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 dim direction

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 stretch is False (default), it indicates proportional scaling

set_height(height: float, *, stretch: bool = False, **kwargs) Self

If stretch is False (default), it indicates proportional scaling

set_depth(depth: float, *, stretch: bool = False, **kwargs) Self

If stretch is False (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 item and matches the length in the dim_to_match dimension

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 replace but leaves a buffer space of buff around 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_pointabout_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 start and end

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.camera

  • normal_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