aerosandbox.numpy.rotations#

Module Contents#

Functions#

rotation_matrix_2D(angle[, as_array])

Gives the 2D rotation matrix associated with a counterclockwise rotation about an angle.

rotation_matrix_3D(angle, axis[, as_array, ...])

Yields the rotation matrix that corresponds to a rotation by a specified amount about a given axis.

rotation_matrix_from_euler_angles([roll_angle, ...])

Yields the rotation matrix that corresponds to a given Euler angle rotation.

is_valid_rotation_matrix(a[, tol])

Returns a boolean of whether the given matrix satisfies the properties of a rotation matrix.

aerosandbox.numpy.rotations.rotation_matrix_2D(angle, as_array=True)[source]#

Gives the 2D rotation matrix associated with a counterclockwise rotation about an angle. :param angle: Angle by which to rotate. Given in radians. :param as_array: Determines whether to return an array-like or just a simple list of lists.

Returns: The 2D rotation matrix

Parameters:

as_array (bool) –

aerosandbox.numpy.rotations.rotation_matrix_3D(angle, axis, as_array=True, axis_already_normalized=False)[source]#

Yields the rotation matrix that corresponds to a rotation by a specified amount about a given axis.

An implementation of https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle

Parameters:
  • angle (Union[float, numpy.ndarray]) – The angle to rotate by. [radians]

  • rule. (Direction of rotation corresponds to the right-hand) –

  • vectorized. (Can be) –

  • axis (Union[numpy.ndarray, List, str]) – The axis to rotate about. [ndarray]

  • x-components (Can be vectorized; be sure axis[0] yields all the) –

  • etc.

  • as_array (bool) –

    boolean, returns a 3x3 array-like if True, and a list-of-lists otherwise.

    If you are intending to use this function vectorized, it is recommended you flag this False. (Or test before proceeding.)

  • axis_already_normalized (bool) – boolean, skips axis normalization for speed if you flag this true.

Returns:

The rotation matrix, with type according to the parameter as_array.

aerosandbox.numpy.rotations.rotation_matrix_from_euler_angles(roll_angle=0, pitch_angle=0, yaw_angle=0, as_array=True)[source]#

Yields the rotation matrix that corresponds to a given Euler angle rotation.

Note: This uses the standard (yaw, pitch, roll) Euler angle rotation, where: * First, a rotation about x is applied (roll) * Second, a rotation about y is applied (pitch) * Third, a rotation about z is applied (yaw)

In other words: R = R_z(yaw) @ R_y(pitch) @ R_x(roll).

Note: To use this, pre-multiply your vector to go from body axes to earth axes.
Example:
>>> vector_earth = rotation_matrix_from_euler_angles(np.pi / 4, np.pi / 4, np.pi / 4) @ vector_body

See notes: http://planning.cs.uiuc.edu/node102.html

Parameters:
  • roll_angle (Union[float, numpy.ndarray]) – The roll angle, which is a rotation about the x-axis. [radians]

  • pitch_angle (Union[float, numpy.ndarray]) – The pitch angle, which is a rotation about the y-axis. [radians]

  • yaw_angle (Union[float, numpy.ndarray]) – The yaw angle, which is a rotation about the z-axis. [radians]

  • as_array (bool) – If True, returns a 3x3 array-like. If False, returns a list-of-lists.

Returns:

aerosandbox.numpy.rotations.is_valid_rotation_matrix(a, tol=1e-09)[source]#

Returns a boolean of whether the given matrix satisfies the properties of a rotation matrix.

Specifically, tests for:
  • Volume-preserving

  • Handedness of output reference frame

  • Orthogonality of output reference frame

Parameters:
  • a (numpy.ndarray) – The array-like to be tested

  • tol – A tolerance to use for truthiness; accounts for floating-point error.

Return type:

bool

Returns: A boolean of whether the array-like is a valid rotation matrix.