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.
- values#
Internal storage of the (w, x, y, z) components.
- Type:
tuple[unifloat, …]
- 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).
- 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.
- 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. Returns identity if the norm is zero.
- rotate_vector(vec)#
Rotate a 3D vector by this quaternion.
- 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.