space_ops

用于二维和三维向量的实用函数。

函数

R3_to_complex(point)[来源]
Parameters:

(序列[浮点数])

Return type:

ndarray

angle_axis_from_quaternion(quaternion)[source]

从四元数中获取角度和轴。

Parameters:

四元数 (序列[浮点数]) – 从中获取角度和轴的四元数。

Returns:

给出角度和轴

Return type:

序列[浮点数]

angle_between_vectors(v1, v2)[来源]

返回两个向量之间的角度。 这个角度将始终在0和pi之间

Parameters:
  • v1 (ndarray) – 第一个向量。

  • v2 (ndarray) – 第二个向量。

Returns:

向量之间的角度。

Return type:

浮点数

angle_of_vector(vector)[source]

返回向量投影在xy平面上的极坐标theta。

Parameters:

vector (Sequence[float] | ndarray) – 用于查找角度的向量。

Returns:

向量投影的角度。

Return type:

浮点数

cartesian_to_spherical(vec)[来源]

返回一个与每个极坐标值(距离,phi,theta)对应的数字数组。

Parameters:

vec (Sequence[float]) – 一个numpy数组 [x, y, z]

Return type:

ndarray

center_of_mass(points)[source]

获取空间中点的质心。

Parameters:

points (Sequence[float]) – 用于找到质心的点。

Returns:

点的质心。

Return type:

np.ndarray

compass_directions(n=4, start_vect=array([1., 0., 0.]))[source]

使用tau找到基本方向。

Parameters:
  • n (int) – 旋转的量,默认为4

  • start_vect (ndarray) – 角度的起始方向,默认为RIGHT

Returns:

已旋转的角度。

Return type:

np.ndarray

complex_func_to_R3_func(complex_func)[来源]
complex_to_R3(complex_num)[source]
Parameters:

complex_num (复数)

Return type:

ndarray

cross(v1, v2)[source]
Parameters:
Return type:

Vector3D

cross2d(a, b)[来源]

计算传递的向量(序列)的行列式。

Parameters:
Returns:

指定向量的前两个分量的行列式或行列式序列。

Return type:

序列[浮点数] | 浮点数

示例

>>> cross2d(np.array([1, 2]), np.array([3, 4]))
-2
>>> cross2d(
...     np.array([[1, 2, 0], [1, 0, 0]]),
...     np.array([[3, 4, 0], [0, 1, 0]]),
... )
array([-2,  1])
earclip_triangulation(verts, ring_ends)[source]

返回一个索引列表,提供多边形(可能带有孔)的三角剖分。

Parameters:
  • verts (ndarray) – verts 是一个点的 numpy 数组。

  • ring_ends (list) – ring_ends 是一个索引列表,指示新路径的末端位置。

Returns:

给出多边形三角剖分的索引列表。

Return type:

列表

find_intersection(p0s, v0s, p1s, v1s, threshold=1e-05)[source]

返回通过点 p0 方向为 v0 的直线与通过点 p1 方向为 v1 的直线的交点(或从这些点/方向的数组中返回交点的数组)。 对于三维值,它返回射线 p0 + v0 * t 上最接近射线 p1 + v1 * t 的点。

Parameters:
Return type:

序列[ndarray]

get_unit_normal(v1, v2, tol=1e-06)[来源]

获取向量的单位法线。

Parameters:
  • v1 (Vector3D) – 第一个向量。

  • v2 (Vector3D) – 第二个向量

  • tol (float) – [描述], 默认值为 1e-6

Returns:

两个向量的法线。

Return type:

np.ndarray

get_winding_number(points)[source]

确定多边形围绕原点的环绕次数。

方向以数学上的正方向测量,即逆时针方向。

Parameters:

points (Sequence[ndarray]) – 被查询的多边形的顶点。

Return type:

浮点数

示例

>>> from manim import Square, get_winding_number
>>> polygon = Square()
>>> get_winding_number(polygon.get_vertices())
1.0
>>> polygon.shift(2*UP)
Square
>>> get_winding_number(polygon.get_vertices())
0.0
line_intersection(line1, line2)[来源]

返回两条线的交点,每条线由位于该线上的一对不同点定义。

Parameters:
  • line1 (Sequence[ndarray]) – 确定第一条线的两个点的列表。

  • line2 (Sequence[ndarray]) – 确定第二条线的两个点的列表。

Returns:

两条相交直线的交点。

Return type:

np.ndarray

Raises:

ValueError – 如果两条线不相交或坐标不在xy平面上,则会产生错误。

midpoint(point1, point2)[来源]

获取两点的中点。

Parameters:
  • point1 (Sequence[float]) – 第一个点。

  • point2 (Sequence[float]) – 第二个点。

Returns:

点的中点

Return type:

Union[float, np.ndarray]

norm_squared(v)[source]
Parameters:

v (浮点数)

Return type:

浮点数

normalize(vect, fall_back=None)[来源]
Parameters:

vect (ndarray | tuple[float])

Return type:

ndarray

normalize_along_axis(array, axis)[source]

使用提供的轴对数组进行归一化。

Parameters:
  • array (ndarray) – 需要标准化的数组。

  • axis (ndarray) – 需要归一化的轴。

Returns:

根据轴进行归一化的数组。

Return type:

np.ndarray

perpendicular_bisector(line, norm_vector=array([0., 0., 1.]))[source]

返回与给定两点的垂直平分线的两端相对应的两个点的列表。

Parameters:
  • line (Sequence[ndarray]) – 两个numpy数组点的列表(对应于线的两端)。

  • norm_vector – 垂直于给定直线和垂直平分线的向量。

Returns:

一个包含两个numpy数组点的列表,这些点对应于垂直平分线的端点

Return type:

列表

quaternion_conjugate(quaternion)[来源]

用于找到四元数的共轭

Parameters:

四元数 (序列[浮点数]) – 你想要找到其共轭的四元数。

Returns:

四元数的共轭。

Return type:

np.ndarray

quaternion_from_angle_axis(angle, axis, axis_normalized=False)[source]

从角度和轴获取四元数。 有关更多信息,请查看此维基百科页面

Parameters:
  • angle (float) – 四元数的角度。

  • axis (ndarray) – 四元数的轴

  • axis_normalized (bool) – 检查轴是否已归一化,默认为 False

Returns:

从角度和轴返回一个四元数

Return type:

列表[浮点数]

quaternion_mult(*quats)[来源]

获取提供的四元数的哈密顿积。 更多信息,请查看此维基百科页面

Returns:

返回两个四元数的乘积列表。

Return type:

Union[np.ndarray, List[Union[float, np.ndarray]]]

Parameters:

quats (序列[浮点数])

regular_vertices(n, *, radius=1, start_angle=None)[来源]

生成围绕原点为中心的圆的等距顶点。

Parameters:
  • n (int) – 顶点的数量

  • radius (float) – 顶点所在圆的半径。

  • start_angle (float | None) –

    顶点开始的角度。

    如果未指定,对于偶数 n 值,将使用 0。 对于奇数 n 值,将使用 90 度。

Returns:

  • vertices (numpy.ndarray) – 规则间隔的顶点。

  • start_angle (float) – 顶点开始的角度。

Return type:

元组[ndarray, 浮点数]

rotate_vector(vector, angle, axis=array([0., 0., 1.]))[source]

用于旋转向量的函数。

Parameters:
  • vector (ndarray) – 要旋转的向量。

  • angle (float) – 旋转的角度。

  • axis (ndarray) – 要旋转的轴,默认为 OUT

Returns:

根据提供的角度和轴旋转后的向量。

Return type:

np.ndarray

Raises:

ValueError – 如果向量的维度不是2或3。

rotation_about_z(angle)[来源]

返回给定角度的旋转矩阵。

Parameters:

angle (float) – 旋转矩阵的角度。

Returns:

返回旋转后的矩阵。

Return type:

np.ndarray

rotation_matrix(angle, axis, homogeneous=False)[来源]

在R^3中围绕指定旋转轴的旋转。

Parameters:
  • 角度 (浮点数)

  • axis (ndarray)

  • 同质的 (布尔型)

Return type:

ndarray

rotation_matrix_from_quaternion(quat)[source]
Parameters:

quat (ndarray)

Return type:

ndarray

rotation_matrix_transpose(angle, axis)[source]
Parameters:
  • 角度 (浮点数)

  • axis (ndarray)

Return type:

ndarray

rotation_matrix_transpose_from_quaternion(quat)[来源]

将四元数quat转换为等效的旋转矩阵表示。 有关更多信息,请查看此页面

Parameters:

quat (ndarray) – 要转换的四元数。

Returns:

返回旋转矩阵表示,返回为3×3矩阵或3×3×N多维数组。

Return type:

列表[np.ndarray]

shoelace(x_y)[source]

鞋带公式的2D实现。

Returns:

返回有符号区域。

Return type:

float

Parameters:

x_y (ndarray)

shoelace_direction(x_y)[来源]

使用鞋带法确定的面积来判断输入的点集是顺时针方向还是逆时针方向。

Returns:

要么是"CW",要么是"CCW"

Return type:

str

Parameters:

x_y (ndarray)

spherical_to_cartesian(spherical)[source]

返回一个基于给定球面坐标的numpy数组 [x, y, z]

Parameters:

spherical (Sequence[float]) –

一个包含三个浮点数的列表,分别对应以下内容:

r - 点与原点之间的距离。

theta - 点与正x轴之间的方位角。

phi - 点与正z轴之间的垂直角。

Return type:

ndarray

thick_diagonal(dim, thickness=2)[source]
Parameters:

dim (int)

Return type:

ndarray

z_to_vector(vector)[来源]

返回一个SO(3)中的矩阵,该矩阵将z轴转换为作为参数提供的(归一化)向量

Parameters:

向量 (多维数组)

Return type:

ndarray