Welcome to Python-flavored Magnum! Please note that, while already being rather stable, this functionality is still considered experimental and some APIs might get changed without preserving full backwards compatibility.

magnum.Quaternion class

Float quaternion

Static methods

def from_matrix(matrix: Matrix3x3) -> Quaternion
Create a quaternion from rotation matrix
def identity_init() -> Quaternion
Construct an identity quaternion
def reflection(normal: Vector3) -> Quaternion
Reflection quaternion
def rotation(angle: Rad, normalized_axis: Vector3) -> Quaternion
Rotation quaternion
def rotation(normalized_from: Vector3, normalized_to: Vector3) -> Quaternion
Quaternion rotating from a vector to another
def zero_init() -> Quaternion
Construct a zero-initialized quaternion

Methods

def angle(self, /) -> Rad
Rotation angle of a unit quaternion
def axis(self, /) -> Vector3
Rotation axis of a unit quaternion
def conjugated(self, /) -> Quaternion
Conjugated quaternion
def dot(self, /) -> float
Dot product of the quaternion
def inverted(self, /) -> Quaternion
Inverted quaternion
def inverted_normalized(self, /) -> Quaternion
Inverted normalized quaternion
def is_normalized(self, /) -> bool
Whether the quaternion is normalized
def length(self, /) -> float
Quaternion length
def normalized(self, /) -> Quaternion
Normalized quaternion (of unit length)
def reflect_vector(self, vector: Vector3) -> Vector3
Reflect a vector with a reflection quaternion
def to_matrix(self, /) -> Matrix3x3
Convert to a rotation matrix
def transform_vector(self, vector: Vector3) -> Vector3
Rotate a vector with a quaternion
def transform_vector_normalized(self, vector: Vector3) -> Vector3
Rotate a vector with a normalized quaternion

Special methods

def __add__(self, arg0: Quaternion, /) -> Quaternion
Add a quaternion
def __eq__(self, arg0: Quaternion, /) -> bool
Equality comparison
def __getstate__(self, /) -> bytes
Dumps the in-memory representation of quaternion components
def __iadd__(self, arg0: Quaternion, /) -> Quaternion
Add and assign a quaternion
def __imul__(self, arg0: float, /) -> Quaternion
Multiply with a scalar and assign
def __init__(self, /) -> None
Default constructor
def __init__(self, arg0: Vector3, arg1: float, /) -> None
Construct from a vector and a scalar
def __init__(self, arg0: typing.Tuple[typing.Tuple[float, float, float], float], /) -> None
Construct from a tuple
def __init__(self, arg0: Vector3, /) -> None
Construct from a vector
def __init__(self, arg0: Quaterniond, /) -> None
Construct from different underlying type
def __isub__(self, arg0: Quaternion, /) -> Quaternion
Subtract and assign a quaternion
def __itruediv__(self, arg0: float, /) -> Quaternion
Divide with a scalar and assign
def __mul__(self, arg0: float, /) -> Quaternion
Multiply with a scalar
def __mul__(self, arg0: Quaternion, /) -> Quaternion
Multiply with a quaternion
def __ne__(self, arg0: Quaternion, /) -> bool
Non-equality comparison
def __neg__(self, /) -> Quaternion
Negated quaternion
def __repr__(self, /) -> str
Object representation
def __rmul__(self, arg0: float, /) -> Quaternion
Multiply a scalar with a quaternion
def __rtruediv__(self, arg0: float, /) -> Quaternion
Divide a quaternion with a scalar and invert
def __setstate__(self, arg0: bytes, /) -> None
Treats the data as the in-memory representation of quaternion components
def __sub__(self, arg0: Quaternion, /) -> Quaternion
Subtract a quaternion
def __truediv__(self, arg0: float, /) -> Quaternion
Divide with a scalar

Properties

scalar: float get set
Scalar part
vector: Vector3 get set
Vector part

Method documentation

def magnum.Quaternion.from_matrix(matrix: Matrix3x3) -> Quaternion staticmethod

Create a quaternion from rotation matrix

Exceptions
ValueError If matrix is not a rotation

def magnum.Quaternion.reflection(normal: Vector3) -> Quaternion staticmethod

Reflection quaternion

Exceptions
ValueError If normal is not normalized

def magnum.Quaternion.rotation(angle: Rad, normalized_axis: Vector3) -> Quaternion staticmethod

Rotation quaternion

Exceptions
ValueError If normalized_axis is not normalized

def magnum.Quaternion.rotation(normalized_from: Vector3, normalized_to: Vector3) -> Quaternion staticmethod

Quaternion rotating from a vector to another

Exceptions
ValueError If either of the vectors is not normalized

def magnum.Quaternion.angle(self, /) -> Rad

Rotation angle of a unit quaternion

Exceptions
ValueError If the quaternion is not normalized

def magnum.Quaternion.axis(self, /) -> Vector3

Rotation axis of a unit quaternion

Exceptions
ValueError If the quaternion is not normalized

def magnum.Quaternion.inverted_normalized(self, /) -> Quaternion

Inverted normalized quaternion

Exceptions
ValueError If the quaternion is not normalized

def magnum.Quaternion.transform_vector_normalized(self, vector: Vector3) -> Vector3

Rotate a vector with a normalized quaternion

Exceptions
ValueError If the quaternion is not normalized

def magnum.Quaternion.__setstate__(self, arg0: bytes, /) -> None

Treats the data as the in-memory representation of quaternion components

Exceptions
ValueError If the data size doesn’t match type size