manim.utils.space_ops

Utility functions for two- and three-dimensional vectors.

Functions

R3_to_complex(point)[source]
Parameters

point (Sequence[float]) –

Return type

numpy.ndarray

angle_axis_from_quaternion(quaternion)[source]

Gets angle and axis from a quaternion.

Parameters

quaternion (Sequence[float]) – The quaternion from which we get the angle and axis.

Returns

Gives the angle and axis

Return type

Sequence[float]

angle_between(v1, v2)[source]

Deprecated

The function angle_between has been deprecated since v0.6.0 and is expected to be removed after v0.8.0. Use angle_between_vectors() instead.

angle_between_vectors(v1, v2)[source]

Returns the angle between two vectors. This angle will always be between 0 and pi

Parameters
  • v1 (numpy.ndarray) – The first vector.

  • v2 (numpy.ndarray) – The second vector.

Returns

The angle between the vectors.

Return type

np.ndarray

angle_of_vector(vector)[source]

Returns polar coordinate theta when vector is projected on xy plane.

Parameters

vector (Sequence[float]) – The vector to find the angle for.

Returns

The angle of the vector projected.

Return type

float

center_of_mass(points)[source]

Gets the center of mass of the points in space.

Parameters

points (Sequence[float]) – The points to find the center of mass from.

Returns

The center of mass of the points.

Return type

np.ndarray

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

Finds the cardinal directions using tau.

Parameters
  • n (int) – The amount to be rotated, by default 4

  • start_vect (numpy.ndarray) – The direction for the angle to start with, by default RIGHT

Returns

The angle which has been rotated.

Return type

np.ndarray

complex_func_to_R3_func(complex_func)[source]
complex_to_R3(complex_num)[source]
Parameters

complex_num (complex) –

Return type

numpy.ndarray

cross(v1, v2)[source]

Deprecated

The function cross has been deprecated since v0.6.0 and is expected to be removed after v0.8.0. Use cross() instead.

cross2d(a, b)[source]
earclip_triangulation(verts, ring_ends)[source]

Returns a list of indices giving a triangulation of a polygon, potentially with holes.

Parameters
  • verts (numpy.ndarray) – verts is a numpy array of points.

  • ring_ends (list) – ring_ends is a list of indices indicating where

  • ends of new paths are. (the) –

Returns

A list of indices giving a triangulation of a polygon.

Return type

list

find_intersection(p0, v0, p1, v1, threshold=1e-05)[source]

Return the intersection of a line passing through p0 in direction v0 with one passing through p1 in direction v1. (Or array of intersections from arrays of such points/directions). For 3d values, it returns the point on the ray p0 + v0 * t closest to the ray p1 + v1 * t

Return type

numpy.ndarray

get_norm(vect)[source]

Deprecated

The function get_norm has been deprecated since v0.6.0 and is expected to be removed after v0.8.0. Use norm() instead.

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

Gets the unit normal of the vectors.

Parameters
  • v1 (numpy.ndarray) – The first vector.

  • v2 (numpy.ndarray) – The second vector

  • tol (float) – [description], by default 1e-6

Returns

The normal of the two vectors.

Return type

np.ndarray

get_winding_number(points)[source]
Parameters

points (Sequence[float]) –

Return type

float

line_intersection(line1, line2)[source]

Returns intersection point of two lines, each defined with a pair of vectors determining the end points.

Parameters
  • line1 (Sequence[float]) – The first line.

  • line2 (Sequence[float]) – The second line.

Returns

The intersection points of the two lines which are intersecting.

Return type

np.ndarray

Raises

ValueError – Error is produced if the two lines don’t intersect with each other

midpoint(point1, point2)[source]

Gets the midpoint of two points.

Parameters
  • point1 (Sequence[float]) – The first point.

  • point2 (Sequence[float]) – The second point.

Returns

The midpoint of the points

Return type

Union[float, np.ndarray]

norm_squared(v)[source]
Parameters

v (float) –

Return type

float

normalize(vect, fall_back=None)[source]
Parameters

vect (Union[numpy.ndarray, Tuple[float]]) –

Return type

numpy.ndarray

normalize_along_axis(array, axis)[source]

Normalizes an array with the provided axis.

Parameters
  • array (numpy.ndarray) – The array which has to be normalized.

  • axis (numpy.ndarray) – The axis to be normalized to.

Returns

Array which has been normalized according to the axis.

Return type

np.ndarray

project_along_vector(point, vector)[source]

Projects a vector along a point.

Parameters
  • point (float) – The point to be project from.

  • vector (numpy.ndarray) – The vector which has to projected.

Returns

A dot product of the point and vector.

Return type

np.ndarray

quaternion_conjugate(quaternion)[source]

Used for finding the conjugate of the quaternion

Parameters

quaternion (Sequence[float]) – The quaternion for which you want to find the conjugate for.

Returns

The conjugate of the quaternion.

Return type

np.ndarray

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

Gets a quaternion from an angle and an axis. For more information, check this Wikipedia page.

Parameters
  • angle (float) – The angle for the quaternion.

  • axis (numpy.ndarray) – The axis for the quaternion

  • axis_normalized (bool, optional) – Checks whether the axis is normalized, by default False

Returns

Gives back a quaternion from the angle and axis

Return type

List[float]

quaternion_mult(*quats)[source]

Gets the Hamilton product of the quaternions provided. For more information, check this Wikipedia page.

Returns

Returns a list of product of two quaternions.

Return type

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

Parameters

quats (Sequence[float]) –

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

Generates regularly spaced vertices around a circle centered at the origin.

Parameters
  • n (int) – The number of vertices

  • radius (float) – The radius of the circle that the vertices are placed on.

  • start_angle (Optional[float]) –

    The angle the vertices start at.

    If unspecified, for even n values, 0 will be used. For odd n values, 90 degrees is used.

Returns

  • vertices (numpy.ndarray) – The regularly spaced vertices.

  • start_angle (float) – The angle the vertices start at.

Return type

Tuple[numpy.ndarray, float]

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

Function for rotating a vector.

Parameters
  • vector (numpy.ndarray) – The vector to be rotated.

  • angle (int) – The angle to be rotated by.

  • axis (numpy.ndarray) – The axis to be rotated, by default OUT

Returns

The rotated vector with provided angle and axis.

Return type

np.ndarray

Raises

ValueError – If vector is not of dimension 2 or 3.

rotation_about_z(angle)[source]

Returns a rotation matrix for a given angle.

Parameters

angle (float) – Angle for the rotation matrix.

Returns

Gives back the rotated matrix.

Return type

List[float]

rotation_matrix(angle, axis, homogeneous=False)[source]

Rotation in R^3 about a specified axis of rotation.

Parameters
  • angle (float) –

  • axis (numpy.ndarray) –

  • homogeneous (bool) –

Return type

numpy.ndarray

rotation_matrix_from_quaternion(quat)[source]
Parameters

quat (numpy.ndarray) –

Return type

numpy.ndarray

rotation_matrix_transpose(angle, axis)[source]
Parameters
  • angle (float) –

  • axis (numpy.ndarray) –

Return type

numpy.ndarray

rotation_matrix_transpose_from_quaternion(quat)[source]

Converts the quaternion, quat, to an equivalent rotation matrix representation. For more information, check this page.

Parameters

quat (numpy.ndarray) – The quaternion which is to be converted.

Returns

Gives back the Rotation matrix representation, returned as a 3-by-3 matrix or 3-by-3-by-N multidimensional array.

Return type

List[np.ndarray]

shoelace(x_y)[source]

2D implementation of the shoelace formula.

Returns

Returns signed area.

Return type

float

Parameters

x_y (numpy.ndarray) –

shoelace_direction(x_y)[source]

Uses the area determined by the shoelace method to determine whether the input set of points is directed clockwise or counterclockwise.

Returns

Either "CW" or "CCW".

Return type

str

Parameters

x_y (numpy.ndarray) –

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

dim (int) –

Return type

numpy.ndarray

z_to_vector(vector)[source]

Returns some matrix in SO(3) which takes the z-axis to the (normalized) vector provided as an argument

Parameters

vector (numpy.ndarray) –

Return type

numpy.ndarray