#[repr(C)]pub struct Quat<T>where
T: Scalar,{
pub x: T,
pub y: T,
pub z: T,
pub w: T,
}
Fields§
§x: T
§y: T
§z: T
§w: T
Implementations§
Source§impl<T> Quat<T>where
T: FloatScalar,
impl<T> Quat<T>where
T: FloatScalar,
pub fn identity() -> Quat<T>
pub fn new(x: T, y: T, z: T, w: T) -> Quat<T>
Sourcepub fn dot(l: &Quat<T>, r: &Quat<T>) -> T
pub fn dot(l: &Quat<T>, r: &Quat<T>) -> T
Computes the dot product of two quaternions.
q₁ · q₂ = x₁x₂ + y₁y₂ + z₁z₂ + w₁w₂
Sourcepub fn length(&self) -> T
pub fn length(&self) -> T
Computes the length (magnitude) of the quaternion.
||q|| = √(x² + y² + z² + w²)
Sourcepub fn conjugate(q: &Quat<T>) -> Quat<T>
pub fn conjugate(q: &Quat<T>) -> Quat<T>
Returns the conjugate of the quaternion.
The conjugate inverts the rotation:
q* = -xi - yj - zk + w
Sourcepub fn normalize(q: &Quat<T>) -> Quat<T>
pub fn normalize(q: &Quat<T>) -> Quat<T>
Normalizes the quaternion to unit length.
Unit quaternions represent valid rotations:
q̂ = q / ||q||
Sourcepub fn neg(q: &Quat<T>) -> Quat<T>
pub fn neg(q: &Quat<T>) -> Quat<T>
Negates all components of the quaternion.
Note: -q and q represent the same rotation (double cover property).
pub fn add(l: &Quat<T>, r: &Quat<T>) -> Quat<T>
pub fn sub(l: &Quat<T>, r: &Quat<T>) -> Quat<T>
pub fn mul(l: &Quat<T>, r: &Quat<T>) -> Quat<T>
pub fn mulf(l: &Quat<T>, r: T) -> Quat<T>
pub fn fmul(l: T, r: &Quat<T>) -> Quat<T>
pub fn divf(l: &Quat<T>, r: T) -> Quat<T>
pub fn fdiv(l: T, r: &Quat<T>) -> Quat<T>
pub fn inverse(q: &Quat<T>) -> Quat<T>
Sourcepub fn mat3(&self) -> Matrix3<T>
pub fn mat3(&self) -> Matrix3<T>
Converts the quaternion to a 3x3 rotation matrix.
The conversion formula:
R = I + 2s(q×) + 2(q×)²
where q× is the cross-product matrix of the vector part.
Sourcepub fn mat4(&self) -> Matrix4<T>
pub fn mat4(&self) -> Matrix4<T>
Converts the quaternion to a 4x4 transformation matrix.
The resulting matrix represents a pure rotation with no translation. The bottom-right element is 1 for homogeneous coordinates.
Sourcepub fn to_axis_angle(&self) -> (Vector3<T>, T)
pub fn to_axis_angle(&self) -> (Vector3<T>, T)
Converts the quaternion to axis-angle representation.
Returns:
axis
: The normalized rotation axisangle
: The rotation angle in radians
For a quaternion q = cos(θ/2) + sin(θ/2)(xi + yj + zk):
- axis = normalize(x, y, z)
- angle = 2 * acos(w)
pub fn of_matrix3(m: &Matrix3<T>) -> Quat<T>
pub fn of_matrix4(m: &Matrix4<T>) -> Quat<T>
Sourcepub fn of_axis_angle(axis: &Vector3<T>, angle: T) -> Quat<T>
pub fn of_axis_angle(axis: &Vector3<T>, angle: T) -> Quat<T>
Creates a quaternion from an axis and angle.
§Parameters
axis
: The rotation axis (will be normalized)angle
: The rotation angle in radians
The quaternion is constructed as:
q = cos(θ/2) + sin(θ/2) * normalize(axis)