coordinate_systems

class janim.items.coordinate.coordinate_systems.CoordinateSystem(*args, num_sampled_graph_points_per_tick, **kwargs)

基类:object

坐标系统抽象类

具体实现请参考 Axes ThreeDAxes 以及 NumberPlane

static create_axis(range: RangeSpecifier, axis_config: dict, length: float | None) NumberLine
abstractmethod get_axes() list[NumberLine]

得到由各方向 NumberLine 所组成的列表

get_origin() ndarray
coords_to_point(*coords: float) ndarray

传入坐标得到对应的位置

例如 c2p(1, 3) 得到 (1,3) 的位置

coords_array_to_points(coords_array: VectArray) ndarray

传入一组坐标得到对应的一组位置

例如 c2p([[1, 3], [2, 1], [-1, -1]]) 得到对应的三个位置

c2p(*coords: float) ndarray

coords_to_point() 的缩写

point_to_coords3d(point: Vect | Iterable[Vect]) ndarray

传入位置得到对应的坐标(但是会扩张为三维坐标;对于二维坐标系来说,第三个分量则表示距离二维平面的距离)

也可以传入一组位置得到一组对应的坐标

p2c3d(point: Vect | Iterable[Vect]) ndarray

point_to_coords3d() 的简写

point_to_coords(point: Vect | Iterable[Vect]) ndarray

传入位置得到对应坐标

也可以传入一组位置得到一组对应的坐标

p2c(point: Vect | Iterable[Vect]) ndarray

point_to_coords() 的缩写

number_to_point(number: complex | float) ndarray

传入复数得到对应位置

n2p(number: complex | float) ndarray

number_to_point() 的缩写

point_to_number(point: Vect) complex

传入位置得到对应复数

p2n(point: Vect) complex

point_to_number() 的缩写

class janim.items.coordinate.coordinate_systems.Axes(x_range: RangeSpecifier = (-8.0, 8.0, 1), y_range: RangeSpecifier = (-4.0, 4.0, 1), *, num_sampled_graph_points_per_tick: int = 5, axis_config: dict = {}, x_axis_config: dict = {}, y_axis_config: dict = {}, x_length: float | None = None, y_length: float | None = None, height: float | None = None, width: float | None = None, unit_size: float = 1.0, **kwargs)

基类:CoordinateSystem, MarkedItem, NamedGroupMixin

二维坐标轴

  • num_sampled_graph_points_per_tick:

    表示 get_graph() 方法在采样步长缺省时,在每段刻度中采样点的数量

  • axis_config:

    横坐标轴和纵坐标轴共用的配置项,可用参数请参考 NumberLine

  • x_axis_config:

    横坐标轴的配置项,可用参数请参考 NumberLine

  • y_axis_config:

    纵坐标轴的配置项,可用参数请参考 NumberLine

  • x_length:

    当该值指定时,会将横坐标轴的长度拉伸以匹配该值

  • y_length:

    当该值指定时,会将纵坐标轴的长度拉伸以匹配该值

  • unit_size:

    指定横坐标与纵坐标的单位长度,如果指定了对应的 *_length 则会被忽略

    注:如果需要给某个坐标轴单独指定 unit_size,请传入对应的 *_axis_config

default_axis_config = {'numbers_to_exclude': [0]}
default_x_axis_config = {}
default_y_axis_config = {'line_to_number_direction': array([0., 1., 0.])}
axis_config_d = {'numbers_to_exclude': [0]}
x_axis_config_d = {}
y_axis_config_d = {'line_to_number_direction': array([0., 1., 0.])}
property x_axis: NumberLine
property y_axis: NumberLine
get_axes() list[NumberLine]

得到由各方向 NumberLine 所组成的列表

get_graph(function: Callable[[float], float], x_range: RangeSpecifier | None = None, *, bind: bool = True, **kwargs) ParametricCurve

基于坐标轴的坐标构造函数曲线,使用 ParametricCurve

  • function: 用于构造曲线的函数

  • x_range: 图像定义域

    如果没有指定则使用横坐标的定义域

    指定时,可以使用 [x_min, x_max, x_step] 或者省略采样步长 [x_min, x_max]

    如果没有指定采样步长,则将坐标轴的刻度步长除以物件的 num_sampled_graph_points_per_tick 作为采样步长

  • bind: 在默认情况下为 True,会使得函数曲线自动同步应用于坐标系上的变换,也可同步动画,详见 API 演示 中的 NumberPlaneExample

警告

bind=True 时,请勿将函数曲线与坐标系放在同一个 Group 中进行坐标变换

因为会导致变换效果被重复作用,(一次由 Group 导致的作用,另一次由 bind=True 导致的作用)

如果你有放在同一个 Group 里的需求,请传入 bind=False 以避免该情况

get_parametric_curve(function: Callable[[float], Vect], t_range: tuple[float, float, float] = (0, 1, 0.1), *, bind: bool = True, **kwargs)

基于坐标轴的坐标构造参数曲线,即 ParametricCurve

  • function: 将值映射为坐标系上的一个点的参数函数

  • bind: 在默认情况下为 True,会使得参数曲线自动同步应用于坐标系上的变换,也可同步动画,详见 API 演示 中的 NumberPlaneExample

警告

bind=True 时,请勿将参数曲线与坐标系放在同一个 Group 中进行坐标变换

因为会导致变换效果被重复作用,(一次由 Group 导致的作用,另一次由 bind=True 导致的作用)

如果你有放在同一个 Group 里的需求,请传入 bind=False 以避免该情况

get_area(graph: ParametricCurve, x_range: tuple[float, float] | None = None, color: JAnimColor = '#58C4DD', alpha: float = 0.3, stroke_alpha: float | None = None, fill_alpha: float | None = None, bounded_graph: ParametricCurve = None, **kwargs) Polygon

构造 x_range 区间内,graph 与坐标轴所围成的区域,使用 Polygon 表示

  • graph: 函数曲线,另见 get_graph()

  • x_range: x 区间的最小值与最大值,x_range = [x_min, x_max]

  • bounded_graph: 如果指定该参数,那么将会构造 graphbounded_graph 所围成的区域,而非与坐标轴

get_axis_labels(x_label: str | Points = 'x', y_label: str | Points = 'y', x_kwargs: dict = {}, y_kwargs: dict = {}, **kwargs) Group[TypstMath | Points]

详见 get_axis_label()

如果设置 ensure_on_screen=True,坐标轴标签会自动调整位置移动到默认屏幕区域内

get_x_axis_label(label: str | Points = 'x', **kwargs) TypstMath | Points

详见 get_axis_label()

如果设置 ensure_on_screen=True,坐标轴标签会自动调整位置移动到默认屏幕区域内

get_y_axis_label(label: str | Points = 'y', **kwargs) TypstMath | Points

详见 get_axis_label()

如果设置 ensure_on_screen=True,坐标轴标签会自动调整位置移动到默认屏幕区域内

class janim.items.coordinate.coordinate_systems.ThreeDAxes(x_range: RangeSpecifier = (-6, 6, 1), y_range: RangeSpecifier = (-5, 5, 1), z_range: RangeSpecifier = (-4, 4, 1), *, axis_config: dict = {}, z_length: float | None = None, z_axis_config: dict = {}, z_normal: Vect = array([0., 1., 0.]), **kwargs)

基类:Axes

三维坐标轴

  • z_normal 表示 z 坐标轴上刻度和箭头标记的面向,默认面向 UP 方向

其它可用参数请参考并类比 Axes 的使用

default_z_axis_config = {}
z_axis_config_d = {}
property z_axis: NumberLine
get_axes() list[NumberLine]

得到由各方向 NumberLine 所组成的列表

get_axis_labels(x_label: str | Points = 'x', y_label: str | Points = 'y', z_label: str | Points = 'z', x_kwargs: dict = {}, y_kwargs: dict = {}, z_kwargs: dict = {}, rotate_xy: bool = True, z_point_up: bool = True, **kwargs) Group[TypstMath | Points]

详见 get_axis_label()

另外,在默认情况下 rotate_xy=True 会将 x、y 轴的标签原地旋转半圈,以匹配从 x、y、z 三个轴的正方向看向原点的视角

以及,直接生成的 z 坐标轴标签会和 2D 平面平行,默认情况下 point_up=True 会将其立起来和 z 轴方向一致,传入 point_up=False 可禁用该行为

get_z_axis_label(label: str | Points = 'z', point_up: bool = True, **kwargs) TypstMath | Points

详见 get_axis_label()

另外,直接生成的坐标轴标签会和 2D 平面平行,默认情况下 point_up=True 会将其立起来和 z 轴方向一致,传入 point_up=False 可禁用该行为

class janim.items.coordinate.coordinate_systems.CmptVPoints_NumberPlaneImpl(*args, **kwargs)

基类:Cmpt_VPoints

prepare_for_nonlinear_transform(num_inserted_curves: int = 50, *, root_only=False) Self
class janim.items.coordinate.coordinate_systems.NumberPlane(x_range: RangeSpecifier = (-8.0, 8.0, 1), y_range: RangeSpecifier = (-4.0, 4.0, 1), background_line_style: dict = {}, faded_line_style: dict = {}, faded_line_ratio: int = 4, **kwargs)

基类:Axes

坐标网格

一般来说包含:

  • 坐标轴:

    默认是白色的坐标轴,不带箭头标志和刻度线

  • 主要网格线:

    颜色默认是 BLUE_D,可传入 background_line_style 调整

  • 次要网格线:

    • 可使用 faded_line_style 调整

      faded_line_style 没有设置时,会将采用与 background_line_style 相同的配置,并将其颜色透明化 50% 来使用

    • 使用 faded_line_ratio 调整每个网格中次要网格线的数量

      例如默认的 4 表示每两个主要网格线之间等距排布了 4 个次要网格线

      可调整成 1,减少次要网格线的密集程度,或是直接设置成 0 来禁用次要网格线

更多参数与方法另请参考 Axes

points
default_background_line_style = {'stroke_color': '#29ABCA', 'stroke_radius': 0.01}
default_axis_config = {'include_ticks': False, 'include_tip': False, 'line_to_number_buff': 0.1, 'line_to_number_direction': array([-1., -1.,  0.]), 'stroke_color': '#FFFFFF', 'stroke_radius': 0.01}
default_y_axis_config = {'line_to_number_direction': array([-1., -1.,  0.]), 'numbers_to_exclude': [0]}
background_line_style_d = {'stroke_color': '#29ABCA', 'stroke_radius': 0.01}
axis_config_d = {'include_ticks': False, 'include_tip': False, 'line_to_number_buff': 0.1, 'line_to_number_direction': array([-1., -1.,  0.]), 'stroke_color': '#FFFFFF', 'stroke_radius': 0.01}
y_axis_config_d = {'line_to_number_direction': array([-1., -1.,  0.]), 'numbers_to_exclude': [0]}
property background_lines: Group[Line]
property faded_lines: Group[Line]
get_lines_parallel_to_axis(axis1: NumberLine, axis2: NumberLine) tuple[Group[Line], Group[Line]]