Skip to content

RotationMatrix Class

The RotationMatrix class represents attitude using Direction Cosine Matrices (DCM) for spacecraft orientation and coordinate transformations.

RotationMatrix

RotationMatrix(r11: float, r12: float, r13: float, r21: float, r22: float, r23: float, r31: float, r32: float, r33: float)

Represents a rotation using a 3x3 rotation matrix (Direction Cosine Matrix).

A rotation matrix is an orthogonal 3x3 matrix with determinant +1 that represents rotation in 3D space. Also known as a Direction Cosine Matrix (DCM).

Parameters:

Name Type Description Default
r11 float

Element at row 1, column 1

required
r12 float

Element at row 1, column 2

required
r13 float

Element at row 1, column 3

required
r21 float

Element at row 2, column 1

required
r22 float

Element at row 2, column 2

required
r23 float

Element at row 2, column 3

required
r31 float

Element at row 3, column 1

required
r32 float

Element at row 3, column 2

required
r33 float

Element at row 3, column 3

required

Raises:

Type Description
BraheError

If the matrix is not a valid rotation matrix

Example
import brahe as bh
import numpy as np

# Create identity rotation
dcm = bh.RotationMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)

# Create from numpy array
R = np.eye(3)
dcm2 = bh.RotationMatrix.from_matrix(R)

# Convert to quaternion
q = dcm.to_quaternion()

# Rotate a vector
v = np.array([1.0, 0.0, 0.0])
v_rot = dcm.rotate_vector(v)

Initialize instance.

__doc__ class-attribute

__doc__ = 'Represents a rotation using a 3x3 rotation matrix (Direction Cosine Matrix).\n\nA rotation matrix is an orthogonal 3x3 matrix with determinant +1 that\nrepresents rotation in 3D space. Also known as a Direction Cosine Matrix (DCM).\n\nArgs:\n    r11 (float): Element at row 1, column 1\n    r12 (float): Element at row 1, column 2\n    r13 (float): Element at row 1, column 3\n    r21 (float): Element at row 2, column 1\n    r22 (float): Element at row 2, column 2\n    r23 (float): Element at row 2, column 3\n    r31 (float): Element at row 3, column 1\n    r32 (float): Element at row 3, column 2\n    r33 (float): Element at row 3, column 3\n\nRaises:\n    BraheError: If the matrix is not a valid rotation matrix\n\nExample:\n    ```python\n    import brahe as bh\n    import numpy as np\n\n    # Create identity rotation\n    dcm = bh.RotationMatrix(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)\n\n    # Create from numpy array\n    R = np.eye(3)\n    dcm2 = bh.RotationMatrix.from_matrix(R)\n\n    # Convert to quaternion\n    q = dcm.to_quaternion()\n\n    # Rotate a vector\n    v = np.array([1.0, 0.0, 0.0])\n    v_rot = dcm.rotate_vector(v)\n    ```'

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

__module__ class-attribute

__module__ = 'brahe._brahe'

str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.

Rx builtin

Rx(angle: float, angle_format: AngleFormat) -> RotationMatrix

Create a rotation matrix for rotation about the X axis.

Parameters:

Name Type Description Default
angle float

Rotation angle in radians or degrees

required
angle_format AngleFormat

Units of input angle (RADIANS or DEGREES)

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Rotation matrix for X-axis rotation

Ry builtin

Ry(angle: float, angle_format: AngleFormat) -> RotationMatrix

Create a rotation matrix for rotation about the Y axis.

Parameters:

Name Type Description Default
angle float

Rotation angle in radians or degrees

required
angle_format AngleFormat

Units of input angle (RADIANS or DEGREES)

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Rotation matrix for Y-axis rotation

Rz builtin

Rz(angle: float, angle_format: AngleFormat) -> RotationMatrix

Create a rotation matrix for rotation about the Z axis.

Parameters:

Name Type Description Default
angle float

Rotation angle in radians or degrees

required
angle_format AngleFormat

Units of input angle (RADIANS or DEGREES)

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Rotation matrix for Z-axis rotation

Example
import brahe as bh

r = bh.RotationMatrix.Rz(1.5708, bh.AngleFormat.RADIANS)

__eq__ method descriptor

__eq__(value)

Return self==value.

__ge__ method descriptor

__ge__(value)

Return self>=value.

__getitem__ method descriptor

__getitem__(key: str) -> Any

Return self[key].

__gt__ method descriptor

__gt__(value)

Return self>value.

__imul__ method descriptor

__imul__(value)

Return self*=value.

__le__ method descriptor

__le__(value)

Return self<=value.

__lt__ method descriptor

__lt__(value)

Return self<value.

__mul__ method descriptor

__mul__(value)

Return self*value.

__ne__ method descriptor

__ne__(value)

Return self!=value.

__new__ builtin

__new__(*args, **kwargs)

Create and return a new object. See help(type) for accurate signature.

__repr__ method descriptor

__repr__() -> str

Return repr(self).

__rmul__ method descriptor

__rmul__(value)

Return value*self.

__str__ method descriptor

__str__() -> str

Return str(self).

from_euler_angle builtin

from_euler_angle(e: EulerAngle) -> RotationMatrix

Create a rotation matrix from Euler angles.

Parameters:

Name Type Description Default
e EulerAngle

Euler angle representation

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Equivalent rotation matrix

Example
import brahe as bh

euler = bh.EulerAngle("XYZ", 0.1, 0.2, 0.3, bh.AngleFormat.RADIANS)
r = bh.RotationMatrix.from_euler_angle(euler)

from_euler_axis builtin

from_euler_axis(e: EulerAxis) -> RotationMatrix

Create a rotation matrix from an Euler axis.

Parameters:

Name Type Description Default
e EulerAxis

Euler axis representation

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Equivalent rotation matrix

Example
import brahe as bh
import numpy as np

axis = np.array([0.0, 0.0, 1.0])
ea = bh.EulerAxis(axis, 1.5708, bh.AngleFormat.RADIANS)
r = bh.RotationMatrix.from_euler_axis(ea)

from_matrix builtin

from_matrix(m: ndarray) -> RotationMatrix

Create a rotation matrix from a 3x3 numpy array.

Parameters:

Name Type Description Default
m ndarray

3x3 rotation matrix

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

New rotation matrix instance

Raises:

Type Description
BraheError

If the matrix is not a valid rotation matrix

Example
import brahe as bh
import numpy as np

mat = np.eye(3)
r = bh.RotationMatrix.from_matrix(mat)

from_quaternion builtin

from_quaternion(q: Quaternion) -> RotationMatrix

Create a rotation matrix from a quaternion.

Parameters:

Name Type Description Default
q Quaternion

Source quaternion

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

Equivalent rotation matrix

Example
import brahe as bh

q = bh.Quaternion(1.0, 0.0, 0.0, 0.0)
r = bh.RotationMatrix.from_quaternion(q)

from_rotation_matrix builtin

from_rotation_matrix(r: RotationMatrix) -> RotationMatrix

Create a rotation matrix from another rotation matrix (copy constructor).

Parameters:

Name Type Description Default
r RotationMatrix

Source rotation matrix

required

Returns:

Name Type Description
RotationMatrix RotationMatrix

New rotation matrix instance

Example
import brahe as bh
import numpy as np

r1 = bh.RotationMatrix.from_array(np.eye(3))
r2 = bh.RotationMatrix.from_rotation_matrix(r1)

to_euler_angle method descriptor

to_euler_angle(order: str) -> EulerAngle

Convert to Euler angle representation.

Parameters:

Name Type Description Default
order str

Desired rotation sequence (e.g., "XYZ", "ZYX")

required

Returns:

Name Type Description
EulerAngle EulerAngle

Equivalent Euler angles

Example
import brahe as bh
import numpy as np

r = bh.RotationMatrix.from_array(np.eye(3))
euler = r.to_euler_angle("XYZ")

to_euler_axis method descriptor

to_euler_axis() -> EulerAxis

Convert to Euler axis representation.

Returns:

Name Type Description
EulerAxis EulerAxis

Equivalent Euler axis

Example
import brahe as bh
import numpy as np

r = bh.RotationMatrix.from_array(np.eye(3))
e = r.to_euler_axis()

to_matrix method descriptor

to_matrix() -> ndarray

Convert rotation matrix to a 3x3 numpy array.

Returns:

Type Description
ndarray

numpy.ndarray: 3x3 rotation matrix

to_quaternion method descriptor

to_quaternion() -> Quaternion

Convert to quaternion representation.

Returns:

Name Type Description
Quaternion Quaternion

Equivalent quaternion

Example
import brahe as bh
import numpy as np

r = bh.RotationMatrix.from_array(np.eye(3))
q = r.to_quaternion()

to_rotation_matrix method descriptor

to_rotation_matrix() -> RotationMatrix

Convert to rotation matrix representation (returns self).

Returns:

Name Type Description
RotationMatrix RotationMatrix

This rotation matrix

Example
import brahe as bh
import numpy as np

r1 = bh.RotationMatrix.from_array(np.eye(3))
r2 = r1.to_rotation_matrix()