rocket_league.math

A set of useful mathematical operations.

Functions

euclidean_distance(→ float)

Returns the Euclidean distance between two vectors.

vector_projection(→ numpy.ndarray)

Returns the vector projection of a vector a onto another vector b.

scalar_projection(→ float)

Returns the scalar projection of a vector a onto another vector b.

magnitude(→ float)

Returns the magnitude of a vector.

normalize(vec)

Returns a unit vector with the same direction as the input vector.

cosine_similarity(→ float)

Computes the cosine similarity between two vectors.

quat_to_euler(→ numpy.ndarray)

Converts a quaternion to Euler angles.

quat_to_rot_mtx(→ numpy.ndarray)

Converts a quaternion to a rotation matrix.

rotation_to_quaternion(→ numpy.ndarray)

Converts a rotation matrix to a quaternion.

euler_to_rotation(→ numpy.ndarray)

Converts Euler angles to a rotation.

rand_uvec3(→ numpy.ndarray)

Generates a random 3-dimensional unit vector.

rand_vec3(→ numpy.ndarray)

Generates a random 3-dimensional vector with a size between 0 and max_norm.

Module Contents

rocket_league.math.euclidean_distance(x: numpy.ndarray, y: numpy.ndarray) float

Returns the Euclidean distance between two vectors.

Parameters:
  • x – A numpy array of size n.

  • y – A numpy array of size n.

Returns:

A float representing the distance between the two vectors.

rocket_league.math.vector_projection(a: numpy.ndarray, b: numpy.ndarray) numpy.ndarray

Returns the vector projection of a vector a onto another vector b.

Parameters:
  • a – A numpy array of size n.

  • b – A numpy array of size n.

Returns:

A numpy array of size n representing the vector projection.

rocket_league.math.scalar_projection(a: numpy.ndarray, b: numpy.ndarray) float

Returns the scalar projection of a vector a onto another vector b.

Parameters:
  • a – A numpy array of size n.

  • b – A numpy array of size n.

Returns:

A float representing the scalar projection.

rocket_league.math.magnitude(vec: numpy.ndarray) float

Returns the magnitude of a vector.

Parameters:

vec – A numpy array of size n.

Returns:

A float representing the magnitude of the vector.

rocket_league.math.normalize(vec: numpy.ndarray)

Returns a unit vector with the same direction as the input vector.

Parameters:

vec – A numpy array of size n.

Returns:

A numpy array of size n.

rocket_league.math.cosine_similarity(a: numpy.ndarray, b: numpy.ndarray) float

Computes the cosine similarity between two vectors.

Parameters:
  • a – A numpy array of size n.

  • b – A numpy array of size n.

Returns:

A float representing the cosine similarity.

rocket_league.math.quat_to_euler(quat: numpy.ndarray) numpy.ndarray

Converts a quaternion to Euler angles.

Parameters:

quat – A numpy array of size 4 representing the quaternion.

Returns:

A numpy array of size 3 representing the pitch, yaw, and roll angles.

rocket_league.math.quat_to_rot_mtx(quat: numpy.ndarray) numpy.ndarray

Converts a quaternion to a rotation matrix.

Parameters:

quat – A numpy array of size 4 representing the quaternion.

Returns:

A numpy array of size 3x3 representing the rotation matrix.

rocket_league.math.rotation_to_quaternion(m: numpy.ndarray) numpy.ndarray

Converts a rotation matrix to a quaternion.

Parameters:

m – A numpy array of size 3x3 representing the rotation matrix.

Returns:

A numpy array of size 4 representing the quaternion.

rocket_league.math.euler_to_rotation(pyr: numpy.ndarray) numpy.ndarray

Converts Euler angles to a rotation.

Parameters:

pyr – A numpy array of size 3 representing the pitch, yaw, and roll angles.

Returns:

A numpy array of size 3x3 representing the rotation matrix.

rocket_league.math.rand_uvec3(rng: numpy.random.Generator = np.random) numpy.ndarray

Generates a random 3-dimensional unit vector.

Parameters:

rng – The random number generator to use.

Returns:

A numpy array of size 3.

rocket_league.math.rand_vec3(max_norm: float, rng: numpy.random.Generator = np.random) numpy.ndarray

Generates a random 3-dimensional vector with a size between 0 and max_norm.

Parameters:
  • max_norm – The maximum norm of the vector.

  • rng – The random number generator to use.

Returns:

A numpy array of size 3.