math

This module provides a collection of jitted (using njit()) functions for mathematical and geometrical operations.

as_angle(vectors)

Represent vectors as angles in radians on the unit circle.

Note that input vectors do not need to be unit vectors. Zero-magnitude vectors result in np.nan values.

Parameters:

vectors (ndarray) – The array of vectors to represent as angles.

Return type:

ndarray

as_unit_vector(radians)

Unit vectors representing angles in radians on the unit circle.

Parameters:

radians (ndarray) – The array of angles in radians.

Return type:

ndarray

dot_product(vectors_1, vectors_2)

Dot product between two vector arrays.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

euclidean_distance(array_1, array_2)

Euclidean distance between two vector arrays.

Parameters:
  • array_1 (ndarray) – The first array of vectors.

  • array_2 (ndarray) – The second array of vectors.

Return type:

ndarray

magnitude(vectors)

Vector magnitudes.

Parameters:

vectors (ndarray) – The input vectors.

Return type:

ndarray

perp(vectors)

Perpendicular vectors (rotated counterclockwise).

Parameters:

vectors (ndarray) – The input vectors.

Return type:

ndarray

perp_dot_product(vectors_1, vectors_2)

Perpendicular dot product between two vector arrays.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

projection(vectors_1, vectors_2)

Projection vectors of vectors_1 onto vectors_2.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

rejection(vectors_1, vectors_2)

Rejection vectors of vectors_1 from vectors_2.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

rotate(vectors, angles)

Rotate vectors around angles in radians.

Parameters:
  • vectors (ndarray) – The array of vectors to rotate.

  • angles (ndarray) – The array of angles in radians.

Return type:

ndarray

scalar_projection(vectors_1, vectors_2)

Scalar projection of vectors_1 onto vectors_2.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

scalar_rejection(vectors_1, vectors_2)

Scalar rejection of vectors_1 from vectors_2.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

shift(array, step)

Similar to numpy.roll() on axis 0 (shift to right with step > 0, shift to left with step < 0).

Values are filled with the last value (shift to left) or the first value (shift to right), no wrapping.

Parameters:
  • array (ndarray) – The array to shift.

  • step (int) – The number of positions to shift the array.

Return type:

ndarray

signed_angle(vectors_1, vectors_2)

Signed angles between vectors.

See as_angle() for behavior with zero-magnitude input vectors.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

subtract(array_1, array_2)

Subtract array_2 from array_1.

Parameters:
  • array_1 (ndarray) – The first array of vectors.

  • array_2 (ndarray) – The second array of vectors.

Return type:

ndarray

unit_vector(vectors)

Vectors to unit vectors.

Parameters:

vectors (ndarray) – The input vectors.

Return type:

ndarray

unsigned_angle(vectors_1, vectors_2)

Unsigned angles between vectors.

Returns np.nan values when either input is of zero-magnitude.

Parameters:
  • vectors_1 (ndarray) – The first array of vectors.

  • vectors_2 (ndarray) – The second array of vectors.

Return type:

ndarray

wrap_angle(radians)

Wrap angles in radians into the [-pi, pi] range.

Parameters:

radians (ndarray) – The array of angles to wrap.

Return type:

ndarray