copapy.quaternion#
- class copapy.quaternion(w=1.0, x=0.0, y=0.0, z=0.0)#
Bases:
ArrayType[float]Mathematical quaternion class for representing 3D rotations.
The components are stored in the order (w, x, y, z) in values.
- w, x, y, z
Property accessors to individual components.
- Type:
unifloat
Create a quaternion with given components.
- Parameters:
w (
value[float] |float|Iterable[value[float] |float]) – w component, or an iterable of 4 components.x (
value[float] |float) – x component (ignored if w is an iterable).y (
value[float] |float) – y component (ignored if w is an iterable).z (
value[float] |float) – z component (ignored if w is an iterable).
- conjugate()#
Return the conjugate of the quaternion.
- Return type:
- Returns:
The conjugate quaternion (negates x, y, z components).
- property dtype: str#
‘int’, ‘float’ or ‘bool’
- Type:
Type of the elements
- classmethod from_euler(roll, pitch, yaw)#
Create a quaternion from Euler angles (roll, pitch, yaw).
- Parameters:
- Return type:
- Returns:
A quaternion representing the rotation.
- classmethod identity()#
Return the identity quaternion (no rotation).
- Return type:
- Returns:
The identity quaternion (x=0, y=0, z=0, w=1).
- inverse()#
Return the inverse of the quaternion.
- Return type:
- Returns:
The inverse quaternion. Returns identity if the norm is zero.
- map(func)#
Applies a function to each element of the quaternion and returns a new quaternion.
- Parameters:
func (
Callable[[Any],value[float] |float]) – A function that takes a single argument.- Return type:
- Returns:
A new quaternion with the function applied to each element.
- ndim: int#
Number of dimensions (length of shape)
- norm()#
Calculate the norm (magnitude) of the quaternion.
- Return type:
value[float] |float- Returns:
The norm (square root of the sum of squared components).
- normalize()#
Normalize the quaternion to unit length.
- Return type:
- Returns:
A normalized (unit) quaternion.
- pack_threshold: int | None = None#
Instances are packed if more elements than pack_threshold are copapy values or constants other than zero, None disables packing and type promotion
- rotate_vector(vec)#
Rotate a 3D vector by this quaternion.
- shape: tuple[int, ...]#
Shape of the elements, e.g. (n,) for a vector
- toAxisAngle()#
Convert the quaternion to axis-angle representation.
- toEulerAngles()#
Convert the quaternion to Euler angles (roll, pitch, yaw).
- Return type:
vector[float]- Returns:
A vector of [roll, pitch, yaw] in radians.