Rotations

class py123d.geometry.Quaternion[source]

Represents a quaternion for 3D rotations.

Examples

>>> import numpy as np
>>> from py123d.geometry import Quaternion
>>> quat = Quaternion(1.0, 0.0, 0.0, 0.0)
>>> quat.qw
1.0
>>> quat.qx
0.0
>>> quat.array
array([1.0, 0.0, 0.0, 0.0])
>>> quat.rotation_matrix
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])

Public Data Attributes:

qw

The scalar component of the quaternion.

qx

The x component of the quaternion.

qy

The y component of the quaternion.

qz

The z component of the quaternion.

array

The numpy array of shape (4,) containing the quaternion [qw, qx, qy, qz], indexed by QuaternionIndex.

pyquaternion

The pyquaternion.Quaternion representation of the quaternion.

euler_angles

The EulerAngles representation of the quaternion.

rotation_matrix

Returns the 3x3 rotation matrix representation of the quaternion.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(arr[, copy])

Constructs a Quaternion from a numpy array.

from_rotation_matrix(rotation_matrix)

Constructs a Quaternion from a 3x3 rotation matrix.

from_euler_angles(euler_angles)

Constructs a Quaternion from Euler angles.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


__init__(qw, qx, qy, qz)[source]

Initialize Quaternion with components.

Parameters:
  • qw (float) – The scalar component of the quaternion.

  • qx (float) – The x component of the quaternion.

  • qy (float) – The y component of the quaternion.

  • qz (float) – The z component of the quaternion.

classmethod from_array(arr, copy=True)[source]

Constructs a Quaternion from a numpy array.

Parameters:
  • arr (ndarray[tuple[Any, ...], dtype[float64]]) – A 1D numpy array of shape (4,) containing the quaternion components [qw, qx, qy, qz].

  • copy (bool) – Whether to copy the array data, defaults to True.

Return type:

Quaternion

Returns:

A Quaternion instance.

classmethod from_rotation_matrix(rotation_matrix)[source]

Constructs a Quaternion from a 3x3 rotation matrix.

Parameters:

rotation_matrix (ndarray[tuple[Any, ...], dtype[float64]]) – A 3x3 numpy array representing the rotation matrix.

Return type:

Quaternion

Returns:

A Quaternion instance.

classmethod from_euler_angles(euler_angles)[source]

Constructs a Quaternion from Euler angles. NOTE: The rotation order is intrinsic Z-Y’-X’’ (yaw-pitch-roll).

Parameters:

euler_angles (EulerAngles) – An EulerAngles instance representing the Euler angles.

Return type:

Quaternion

Returns:

A Quaternion instance.

property qw: float

The scalar component of the quaternion.

property qx: float

The x component of the quaternion.

property qy: float

The y component of the quaternion.

property qz: float

The z component of the quaternion.

property array: ndarray[tuple[Any, ...], dtype[float64]]

The numpy array of shape (4,) containing the quaternion [qw, qx, qy, qz], indexed by QuaternionIndex.

property pyquaternion: Quaternion

The pyquaternion.Quaternion representation of the quaternion.

property euler_angles: EulerAngles

The EulerAngles representation of the quaternion.

property rotation_matrix: ndarray[tuple[Any, ...], dtype[float64]]

Returns the 3x3 rotation matrix representation of the quaternion.

copy()

Return a copy of the object with a copied array.

Return type:

ArrayMixin

classmethod from_list(values)

Create an instance from a list of values.

Return type:

Self

Parameters:

values (list)

property shape: tuple

Return the shape of the array.

to_list()

Convert the array to a Python list.

Return type:

list

tolist()

Convert the array to a Python list.

Return type:

list

class py123d.geometry.EulerAngles[source]

Class to represent 3D rotation using Euler angles (roll, pitch, yaw) in radians.

Examples

>>> import numpy as np
>>> from py123d.geometry import EulerAngles
>>> euler_angles = EulerAngles(roll=0.0, pitch=0.0, yaw=np.pi)
>>> euler_angles.roll
0.0
>>> euler_angles.yaw
3.141592653589793
>>> euler_angles.array
array([0.0, 0.0, 3.14159265])
>>> EulerAngles.from_rotation_matrix(euler_angles.rotation_matrix).yaw
3.141592653589793

Notes

The rotation order is intrinsic Z-Y’-X’’ (yaw-pitch-roll) [1].

References

Public Data Attributes:

roll

The roll (x-axis rotation) angle in radians.

pitch

The pitch (y-axis rotation) angle in radians.

yaw

The yaw (z-axis rotation) angle in radians.

array

Converts the EulerAngles instance to a numpy array of shape (3,), indexed by EulerAnglesIndex.

quaternion

The Quaternion representation of the Euler angles.

rotation_matrix

Returns the 3x3 rotation matrix representation of the Euler angles.

Inherited from ArrayMixin

array

The array representation of the geometric entity.

shape

Return the shape of the array.

Public Methods:

from_array(array[, copy])

Constructs a EulerAngles from a numpy array of shape (3,) representing, indexed by EulerAnglesIndex.

from_rotation_matrix(rotation_matrix)

Constructs a EulerAngles from a 3x3 rotation matrix.

Inherited from ArrayMixin

from_array(array[, copy])

Create an instance from a NumPy array.

from_list(values)

Create an instance from a list of values.

tolist()

Convert the array to a Python list.

to_list()

Convert the array to a Python list.

copy()

Return a copy of the object with a copied array.


__init__(roll, pitch, yaw)[source]

Initialize EulerAngles with roll, pitch, yaw angles in radians.

Parameters:
  • roll (float) – The roll (x-axis rotation) angle in radians.

  • pitch (float) – The pitch (y-axis rotation) angle in radians.

  • yaw (float) – The yaw (z-axis rotation) angle in radians.

classmethod from_array(array, copy=True)[source]

Constructs a EulerAngles from a numpy array of shape (3,) representing, indexed by EulerAnglesIndex.

Parameters:
  • array (ndarray[tuple[Any, ...], dtype[float64]]) – Array of shape (3,) representing the euler angles [roll, pitch, yaw].

  • copy (bool) – Whether to copy the input array. Defaults to True.

Return type:

EulerAngles

Returns:

A EulerAngles instance.

classmethod from_rotation_matrix(rotation_matrix)[source]

Constructs a EulerAngles from a 3x3 rotation matrix.

Parameters:

rotation_matrix (ndarray[tuple[Any, ...], dtype[float64]]) – A 3x3 numpy array representing the rotation matrix.

Return type:

EulerAngles

Returns:

A EulerAngles instance.

property roll: float

The roll (x-axis rotation) angle in radians.

property pitch: float

The pitch (y-axis rotation) angle in radians.

property yaw: float

The yaw (z-axis rotation) angle in radians.

property array: ndarray[tuple[Any, ...], dtype[float64]]

Converts the EulerAngles instance to a numpy array of shape (3,), indexed by EulerAnglesIndex.

property quaternion: Quaternion

The Quaternion representation of the Euler angles.

property rotation_matrix: ndarray[tuple[Any, ...], dtype[float64]]

Returns the 3x3 rotation matrix representation of the Euler angles.

copy()

Return a copy of the object with a copied array.

Return type:

ArrayMixin

classmethod from_list(values)

Create an instance from a list of values.

Return type:

Self

Parameters:

values (list)

property shape: tuple

Return the shape of the array.

to_list()

Convert the array to a Python list.

Return type:

list

tolist()

Convert the array to a Python list.

Return type:

list