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.

r11 property

r11: float

Get element (1,1) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 1, column 1

r12 property

r12: float

Get element (1,2) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 1, column 2

r13 property

r13: float

Get element (1,3) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 1, column 3

r21 property

r21: float

Get element (2,1) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 2, column 1

r22 property

r22: float

Get element (2,2) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 2, column 2

r23 property

r23: float

Get element (2,3) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 2, column 3

r31 property

r31: float

Get element (3,1) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 3, column 1

r32 property

r32: float

Get element (3,2) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 3, column 2

r33 property

r33: float

Get element (3,3) of the rotation matrix.

Returns:

Name Type Description
float float

Matrix element at row 3, column 3

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
1
2
3
import brahe as bh

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

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
1
2
3
4
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
1
2
3
4
5
6
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
1
2
3
4
5
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
1
2
3
4
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
1
2
3
4
5
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
1
2
3
4
5
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
1
2
3
4
5
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
1
2
3
4
5
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
1
2
3
4
5
import brahe as bh
import numpy as np

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