utils

Utilities for the rest of manim-eng.

Functions

manim_eng._utils.utils.cardinalised(vector: ndarray[tuple[Any, ...], dtype[float64]], margin: float | None = None) ndarray[tuple[Any, ...], dtype[float64]]

If vector is within margin of a cardinal direction, snap it to it.

The angle the passed vector makes with the positive horizontal is checked, and if it falls within margin of a given cardinal direction, i.e. up, down, left, or right, then the vector is snapped to that cardinal direction, maintaining its original magnitude.

In the event that a vector lies perfectly on the boundary between possible snaps, the horizontal snap will be preferred.

Parameters:
  • vector (mnt.Vector3D) – The vector to potentially snap to a cardinal direction.

  • margin (float) – The maximum angle vector can make with a cardinal direction and still be snapped to it, in radians. If not supplied, all vectors will be snapped to the nearest cardinal direction.

Returns:

The resultant vector.

Return type:

Vector3D