pub struct Quaternion<F> {
pub w: F,
pub x: F,
pub y: F,
pub z: F,
}Fields§
§w: F§x: F§y: F§z: FImplementations§
Source§impl<T: RealField> Quaternion<T>
impl<T: RealField> Quaternion<T>
Sourcepub fn norm(&self) -> T
pub fn norm(&self) -> T
Computes the norm (magnitude or absolute value) of the quaternion.
For a quaternion q = w + xi + yj + zk, the norm is sqrt(w^2 + x^2 + y^2 + z^2).
§Examples
use deep_causality_num::Quaternion;
let q = Quaternion::<f64>::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(q.norm(), (1.0f64*1.0f64 + 2.0f64*2.0f64 + 3.0f64*3.0f64 + 4.0f64*4.0f64).sqrt());Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Returns a normalized quaternion (unit quaternion).
A unit quaternion has a norm of 1. If the quaternion is a zero quaternion, it returns itself to avoid division by zero.
§Examples
use deep_causality_num::Quaternion;
let q = Quaternion::<f64>::new(1.0, 2.0, 3.0, 4.0);
let normalized_q = q.normalize();
assert!((normalized_q.norm() - 1.0).abs() < 1e-9);
let zero_q = Quaternion::<f64>::new(0.0, 0.0, 0.0, 0.0);
assert_eq!(zero_q.normalize(), zero_q);Sourcepub fn dot(&self, other: &Self) -> T
pub fn dot(&self, other: &Self) -> T
Computes the dot product with another quaternion.
For two quaternions q1 = w1 + x1i + y1j + z1k and q2 = w2 + x2i + y2j + z2k,
their dot product is w1*w2 + x1*x2 + y1*y2 + z1*z2.
§Arguments
other- The other quaternion.
§Examples
use deep_causality_num::Quaternion;
let q1 = Quaternion::new(1.0, 2.0, 3.0, 4.0);
let q2 = Quaternion::new(5.0, 6.0, 7.0, 8.0);
assert_eq!(q1.dot(&q2), 1.0*5.0 + 2.0*6.0 + 3.0*7.0 + 4.0*8.0);Sourcepub fn to_axis_angle(&self) -> (Vector3<T>, T)
pub fn to_axis_angle(&self) -> (Vector3<T>, T)
Converts the quaternion to an axis-angle representation.
Returns a tuple containing a 3-element array representing the rotation axis and the rotation angle in radians.
If the quaternion is an identity quaternion (or very close to it),
the angle will be 0 and the axis will be an arbitrary unit vector (e.g., [1.0, 0.0, 0.0]).
§Examples
use deep_causality_num::Quaternion;
use std::f64::consts::FRAC_PI_2;
let q = Quaternion::from_axis_angle([1.0, 0.0, 0.0], FRAC_PI_2);
let (axis, angle) = q.to_axis_angle();
assert!((axis[0] - 1.0).abs() < 1e-9);
assert!((axis[1] - 0.0).abs() < 1e-9);
assert!((axis[2] - 0.0).abs() < 1e-9);
assert!((angle - FRAC_PI_2).abs() < 1e-9);Sourcepub fn to_rotation_matrix(&self) -> Matrix3<T>
pub fn to_rotation_matrix(&self) -> Matrix3<T>
Converts the quaternion to a 3x3 rotation matrix.
The resulting matrix can be used to rotate 3D vectors.
§Examples
use deep_causality_num::Quaternion;
use std::f64::consts::FRAC_PI_2;
// 90 degrees around the X-axis
let q = Quaternion::from_axis_angle([1.0, 0.0, 0.0], FRAC_PI_2);
let mat = q.to_rotation_matrix();
// Expected rotation matrix for 90 degrees around X-axis
// [ 1, 0, 0 ]
// [ 0, 0, -1 ]
// [ 0, 1, 0 ]
assert!((mat[0][0] - 1.0).abs() < 1e-9);
assert!((mat[1][1] - 0.0).abs() < 1e-9);
assert!((mat[1][2] - (-1.0)).abs() < 1e-9);
assert!((mat[2][1] - 1.0).abs() < 1e-9);Sourcepub fn slerp(&self, other: &Self, t: T) -> Self
pub fn slerp(&self, other: &Self, t: T) -> Self
Performs spherical linear interpolation (SLERP) between two quaternions.
SLERP interpolates along the shortest arc on the unit sphere between two quaternions.
The parameter t is typically in the range [0, 1].
§Arguments
other- The target quaternion for interpolation.t- The interpolation parameter, wheret=0returnsselfandt=1returnsother.
§Examples
use deep_causality_num::Quaternion;
use std::f64::consts::FRAC_PI_2;
let q1 = Quaternion::<f64>::identity();
let q2 = Quaternion::from_axis_angle([1.0, 0.0, 0.0], FRAC_PI_2);
// Interpolate halfway between q1 and q2
let slerp_q = q1.slerp(&q2, 0.5);
let expected_q = Quaternion::from_axis_angle([1.0, 0.0, 0.0], FRAC_PI_2 / 2.0);
assert!((slerp_q.w - expected_q.w).abs() < 1e-9);
assert!((slerp_q.x - expected_q.x).abs() < 1e-9);
assert!((slerp_q.y - expected_q.y).abs() < 1e-9);
assert!((slerp_q.z - expected_q.z).abs() < 1e-9);pub fn sin(self) -> Self
pub fn cos(self) -> Self
pub fn tan(self) -> Self
pub fn sinh(self) -> Self
pub fn cosh(self) -> Self
pub fn tanh(self) -> Self
pub fn acos(self) -> Self
pub fn ln(self) -> Self
pub fn exp(self) -> Self
pub fn powi(&self, n: i32) -> Self
pub fn powf(&self, n: T) -> Self
pub fn powc(&self, p: Self) -> Self
Source§impl<F> Quaternion<F>where
F: RealField,
impl<F> Quaternion<F>where
F: RealField,
Sourcepub fn new(w: F, x: F, y: F, z: F) -> Self
pub fn new(w: F, x: F, y: F, z: F) -> Self
Creates a new quaternion from its scalar and vector components.
§Arguments
w- The scalar component.x- Theicomponent of the vector part.y- Thejcomponent of the vector part.z- Thekcomponent of the vector part.
§Examples
use deep_causality_num::Quaternion;
let q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(q.w, 1.0);
assert_eq!(q.x, 2.0);
assert_eq!(q.y, 3.0);
assert_eq!(q.z, 4.0);pub fn from_real(re: F) -> Self
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Returns the identity quaternion (1 + 0i + 0j + 0k).
The identity quaternion represents no rotation.
§Examples
use deep_causality_num::Quaternion;
let identity_q = Quaternion::<f64>::identity();
assert_eq!(identity_q.w, 1.0);
assert_eq!(identity_q.x, 0.0);
assert_eq!(identity_q.y, 0.0);
assert_eq!(identity_q.z, 0.0);Sourcepub fn from_axis_angle(axis: Vector3<F>, angle: F) -> Self
pub fn from_axis_angle(axis: Vector3<F>, angle: F) -> Self
Creates a quaternion from an axis-angle representation.
The axis vector is expected to be a unit vector. If the axis has zero length, an identity quaternion is returned.
§Arguments
axis- A 3-element array representing the rotation axis.angle- The rotation angle in radians.
§Examples
use deep_causality_num::Quaternion;
use std::f64::consts::FRAC_PI_2;
// 90 degrees around the X-axis
let q = Quaternion::from_axis_angle([1.0, 0.0, 0.0], FRAC_PI_2);
// Expected values for a 90-degree rotation around X-axis
assert!((q.w - (FRAC_PI_2 / 2.0).cos()).abs() < 1e-9);
assert!((q.x - (FRAC_PI_2 / 2.0).sin()).abs() < 1e-9);
assert!((q.y - 0.0).abs() < 1e-9);
assert!((q.z - 0.0).abs() < 1e-9);Sourcepub fn from_euler_angles(roll: F, pitch: F, yaw: F) -> Self
pub fn from_euler_angles(roll: F, pitch: F, yaw: F) -> Self
Creates a quaternion from Euler angles (roll, pitch, yaw).
The Euler angles are applied in the order: yaw (Z-axis), pitch (Y-axis), roll (X-axis). All angles should be in radians.
§Arguments
roll- Rotation around the X-axis (in radians).pitch- Rotation around the Y-axis (in radians).yaw- Rotation around the Z-axis (in radians).
§Examples
use deep_causality_num::Quaternion;
use std::f64::consts::FRAC_PI_2;
// 90 degrees around the Y-axis
let q = Quaternion::from_euler_angles(0.0, FRAC_PI_2, 0.0);
// Expected values for a 90-degree rotation around Y-axis
assert!((q.w - (FRAC_PI_2 / 2.0).cos()).abs() < 1e-9);
assert!((q.x - 0.0).abs() < 1e-9);
assert!((q.y - (FRAC_PI_2 / 2.0).sin()).abs() < 1e-9);
assert!((q.z - 0.0).abs() < 1e-9);Trait Implementations§
Source§impl<T: RealField> Add for Quaternion<T>
impl<T: RealField> Add for Quaternion<T>
Source§impl<T: RealField> AddAssign for Quaternion<T>
impl<T: RealField> AddAssign for Quaternion<T>
Source§fn add_assign(&mut self, other: Self)
fn add_assign(&mut self, other: Self)
+= operation. Read moreSource§impl<F, T> AsPrimitive<T> for Quaternion<F>
impl<F, T> AsPrimitive<T> for Quaternion<F>
Source§impl<F: Clone> Clone for Quaternion<F>
impl<F: Clone> Clone for Quaternion<F>
Source§fn clone(&self) -> Quaternion<F>
fn clone(&self) -> Quaternion<F>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<F> ConstOne for Quaternion<F>
impl<F> ConstOne for Quaternion<F>
Source§impl<F> ConstZero for Quaternion<F>
impl<F> ConstZero for Quaternion<F>
Source§impl<F: Debug> Debug for Quaternion<F>
impl<F: Debug> Debug for Quaternion<F>
Source§impl<F: Default> Default for Quaternion<F>
impl<F: Default> Default for Quaternion<F>
Source§fn default() -> Quaternion<F>
fn default() -> Quaternion<F>
Source§impl<F: RealField> Div<F> for Quaternion<F>
impl<F: RealField> Div<F> for Quaternion<F>
Source§impl<F: RealField> Div for Quaternion<F>
impl<F: RealField> Div for Quaternion<F>
Source§impl<F: RealField> DivAssign for Quaternion<F>
impl<F: RealField> DivAssign for Quaternion<F>
Source§fn div_assign(&mut self, other: Self)
fn div_assign(&mut self, other: Self)
/= operation. Read moreSource§impl<T: RealField> DivisionAlgebra<T> for Quaternion<T>
impl<T: RealField> DivisionAlgebra<T> for Quaternion<T>
Source§fn conjugate(&self) -> Self
fn conjugate(&self) -> Self
Returns the conjugate of the quaternion.
For a quaternion q = w + xi + yj + zk, its conjugate is w - xi - yj - zk.
§Examples
use deep_causality_num::{Quaternion, DivisionAlgebra};
let q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
let conj_q : Quaternion<f64> = q.conjugate();
assert_eq!(conj_q, Quaternion::new(1.0, -2.0, -3.0, -4.0));Source§fn norm_sqr(&self) -> T
fn norm_sqr(&self) -> T
Computes the squared norm (magnitude squared) of the quaternion.
For a quaternion q = w + xi + yj + zk, the squared norm is w^2 + x^2 + y^2 + z^2.
This method avoids the square root operation, making it more efficient
when only relative magnitudes are needed.
§Examples
use deep_causality_num::{Quaternion, DivisionAlgebra};
let q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
assert_eq!(q.norm_sqr(), 1.0*1.0 + 2.0*2.0 + 3.0*3.0 + 4.0*4.0);Source§fn inverse(&self) -> Self
fn inverse(&self) -> Self
Returns the inverse of the quaternion.
For a non-zero quaternion q, its inverse q^-1 is q.conjugate() / q.norm_sqr().
If the quaternion is a zero quaternion, it returns a quaternion with NaN components.
§Examples
use deep_causality_num::{Quaternion, DivisionAlgebra};
let q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
let inv_q = q.inverse();
// For a unit quaternion, inverse is its conjugate.
// For a general quaternion, q * q.inverse() should be identity.
let identity_q : Quaternion<f64> = q * inv_q;
assert!((identity_q.w - 1.0).abs() < 1e-9);
assert!((identity_q.x - 0.0).abs() < 1e-9);
assert!((identity_q.y - 0.0).abs() < 1e-9);
assert!((identity_q.z - 0.0).abs() < 1e-9);
let zero_q = Quaternion::<f64>::new(0.0, 0.0, 0.0, 0.0);
let inv_zero_q = zero_q.inverse();
assert!(inv_zero_q.w.is_nan());Source§impl<T: RealField + FromPrimitive> FromPrimitive for Quaternion<T>
impl<T: RealField + FromPrimitive> FromPrimitive for Quaternion<T>
Source§fn from_isize(n: isize) -> Option<Self>
fn from_isize(n: isize) -> Option<Self>
isize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i8(n: i8) -> Option<Self>
fn from_i8(n: i8) -> Option<Self>
i8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i16(n: i16) -> Option<Self>
fn from_i16(n: i16) -> Option<Self>
i16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i32(n: i32) -> Option<Self>
fn from_i32(n: i32) -> Option<Self>
i32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i64(n: i64) -> Option<Self>
fn from_i64(n: i64) -> Option<Self>
i64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_i128(n: i128) -> Option<Self>
fn from_i128(n: i128) -> Option<Self>
i128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_usize(n: usize) -> Option<Self>
fn from_usize(n: usize) -> Option<Self>
usize to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u8(n: u8) -> Option<Self>
fn from_u8(n: u8) -> Option<Self>
u8 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u16(n: u16) -> Option<Self>
fn from_u16(n: u16) -> Option<Self>
u16 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u32(n: u32) -> Option<Self>
fn from_u32(n: u32) -> Option<Self>
u32 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u64(n: u64) -> Option<Self>
fn from_u64(n: u64) -> Option<Self>
u64 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§fn from_u128(n: u128) -> Option<Self>
fn from_u128(n: u128) -> Option<Self>
u128 to return an optional value of this type. If the
value cannot be represented by this type, then None is returned.Source§impl<F: RealField> Mul<F> for Quaternion<F>
impl<F: RealField> Mul<F> for Quaternion<F>
Source§impl<F: RealField> Mul for Quaternion<F>
impl<F: RealField> Mul for Quaternion<F>
Source§impl<F: RealField> MulAssign<F> for Quaternion<F>
impl<F: RealField> MulAssign<F> for Quaternion<F>
Source§fn mul_assign(&mut self, scalar: F)
fn mul_assign(&mut self, scalar: F)
*= operation. Read moreSource§impl<F: RealField> MulAssign for Quaternion<F>
impl<F: RealField> MulAssign for Quaternion<F>
Source§fn mul_assign(&mut self, other: Self)
fn mul_assign(&mut self, other: Self)
*= operation. Read moreSource§impl<F> Neg for Quaternion<F>where
F: RealField,
impl<F> Neg for Quaternion<F>where
F: RealField,
Source§fn neg(self) -> Self
fn neg(self) -> Self
Returns the negation of the quaternion.
For a quaternion q = w + xi + yj + zk, its negation is -w - xi - yj - zk.
§Examples
use deep_causality_num::Quaternion;
let q = Quaternion::new(1.0, -2.0, 3.0, -4.0);
let neg_q = -q;
assert_eq!(neg_q, Quaternion::new(-1.0, 2.0, -3.0, 4.0));Source§type Output = Quaternion<F>
type Output = Quaternion<F>
- operator.Source§impl<F> One for Quaternion<F>where
F: RealField,
impl<F> One for Quaternion<F>where
F: RealField,
Source§fn one() -> Self
fn one() -> Self
Returns the multiplicative identity quaternion (1 + 0i + 0j + 0k).
§Examples
use deep_causality_num::{Quaternion, One};
let q = Quaternion::<f64>::one();
assert_eq!(q, Quaternion::new(1.0, 0.0, 0.0, 0.0));Source§fn is_one(&self) -> bool
fn is_one(&self) -> bool
Returns true if the quaternion is the multiplicative identity (1 + 0i + 0j + 0k).
§Examples
use deep_causality_num::{Quaternion, One};
let q1 = Quaternion::new(1.0, 0.0, 0.0, 0.0);
assert!(q1.is_one());
let q2 = Quaternion::new(1.0, 1.0, 0.0, 0.0);
assert!(!q2.is_one());Source§impl<F: PartialEq> PartialEq for Quaternion<F>
impl<F: PartialEq> PartialEq for Quaternion<F>
Source§impl<F: PartialOrd> PartialOrd for Quaternion<F>
impl<F: PartialOrd> PartialOrd for Quaternion<F>
Source§impl<F: RealField> Product for Quaternion<F>
impl<F: RealField> Product for Quaternion<F>
Source§impl<T: RealField> Rotation<T> for Quaternion<T>
impl<T: RealField> Rotation<T> for Quaternion<T>
Source§fn rotate_x(&self, angle: T) -> Self
fn rotate_x(&self, angle: T) -> Self
i. Quantum: Pauli X.Source§fn rotate_y(&self, angle: T) -> Self
fn rotate_y(&self, angle: T) -> Self
j. Quantum: Pauli Y.Source§fn rotate_z(&self, angle: T) -> Self
fn rotate_z(&self, angle: T) -> Self
k. Quantum: Pauli Z.Source§fn global_phase(&self, _angle: T) -> Self
fn global_phase(&self, _angle: T) -> Self
Source§impl<F: RealField> Sub for Quaternion<F>
impl<F: RealField> Sub for Quaternion<F>
Source§impl<F: RealField> SubAssign for Quaternion<F>
impl<F: RealField> SubAssign for Quaternion<F>
Source§fn sub_assign(&mut self, other: Self)
fn sub_assign(&mut self, other: Self)
-= operation. Read moreSource§impl<F: RealField> Sum for Quaternion<F>
impl<F: RealField> Sum for Quaternion<F>
Source§impl<F: RealField + ToPrimitive> ToPrimitive for Quaternion<F>
impl<F: RealField + ToPrimitive> ToPrimitive for Quaternion<F>
Source§fn to_isize(&self) -> Option<isize>
fn to_isize(&self) -> Option<isize>
Converts the scalar part (w) of the quaternion to an isize.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_isize(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_isize(), None);Source§fn to_i8(&self) -> Option<i8>
fn to_i8(&self) -> Option<i8>
Converts the scalar part (w) of the quaternion to an i8.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_i8(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_i8(), None);Source§fn to_i16(&self) -> Option<i16>
fn to_i16(&self) -> Option<i16>
Converts the scalar part (w) of the quaternion to an i16.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_i16(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_i16(), None);Source§fn to_i32(&self) -> Option<i32>
fn to_i32(&self) -> Option<i32>
Converts the scalar part (w) of the quaternion to an i32.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_i32(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_i32(), None);Source§fn to_i64(&self) -> Option<i64>
fn to_i64(&self) -> Option<i64>
Converts the scalar part (w) of the quaternion to an i64.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_i64(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_i64(), None);Source§fn to_i128(&self) -> Option<i128>
fn to_i128(&self) -> Option<i128>
Converts the scalar part (w) of the quaternion to an i128.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_i128(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_i128(), None);Source§fn to_usize(&self) -> Option<usize>
fn to_usize(&self) -> Option<usize>
Converts the scalar part (w) of the quaternion to a usize.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_usize(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_usize(), None);Source§fn to_u8(&self) -> Option<u8>
fn to_u8(&self) -> Option<u8>
Converts the scalar part (w) of the quaternion to a u8.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_u8(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_u8(), None);Source§fn to_u16(&self) -> Option<u16>
fn to_u16(&self) -> Option<u16>
Converts the scalar part (w) of the quaternion to a u16.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_u16(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_u16(), None);Source§fn to_u32(&self) -> Option<u32>
fn to_u32(&self) -> Option<u32>
Converts the scalar part (w) of the quaternion to a u32.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_u32(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_u32(), None);Source§fn to_u64(&self) -> Option<u64>
fn to_u64(&self) -> Option<u64>
Converts the scalar part (w) of the quaternion to a u64.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_u64(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_u64(), None);Source§fn to_u128(&self) -> Option<u128>
fn to_u128(&self) -> Option<u128>
Converts the scalar part (w) of the quaternion to a u128.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_u128(), Some(123));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert_eq!(q_nan.to_u128(), None);Source§fn to_f32(&self) -> Option<f32>
fn to_f32(&self) -> Option<f32>
Converts the scalar part (w) of the quaternion to an f32.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_f32(), Some(123.45f32));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert!(q_nan.to_f32().unwrap().is_nan());Source§fn to_f64(&self) -> Option<f64>
fn to_f64(&self) -> Option<f64>
Converts the scalar part (w) of the quaternion to an f64.
Returns None if the conversion is not possible (e.g., NaN, Infinity, or out of range).
§Examples
use deep_causality_num::Quaternion;
use deep_causality_num::ToPrimitive;
let q = Quaternion::new(123.45, 0.0, 0.0, 0.0);
assert_eq!(q.to_f64(), Some(123.45f64));
let q_nan = Quaternion::new(f64::NAN, 0.0, 0.0, 0.0);
assert!(q_nan.to_f64().unwrap().is_nan());Source§impl<F> Zero for Quaternion<F>where
F: RealField,
impl<F> Zero for Quaternion<F>where
F: RealField,
Source§fn zero() -> Self
fn zero() -> Self
Returns the additive identity quaternion (0 + 0i + 0j + 0k).
§Examples
use deep_causality_num::{Quaternion, Zero};
let q = Quaternion::<f64>::zero();
assert_eq!(q, Quaternion::new(0.0, 0.0, 0.0, 0.0));Source§fn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Returns true if the quaternion is the additive identity (all components are zero).
§Examples
use deep_causality_num::{Quaternion, Zero};
let q1 = Quaternion::new(0.0, 0.0, 0.0, 0.0);
assert!(q1.is_zero());
let q2 = Quaternion::new(1.0, 0.0, 0.0, 0.0);
assert!(!q2.is_zero());