Skip to main content

Quaternion

Struct Quaternion 

Source
pub struct Quaternion<F> {
    pub w: F,
    pub x: F,
    pub y: F,
    pub z: F,
}

Fields§

§w: F§x: F§y: F§z: F

Implementations§

Source§

impl<T: RealField> Quaternion<T>

Source

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());
Source

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);
Source

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);
Source

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);
Source

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);
Source

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, where t=0 returns self and t=1 returns other.
§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);
Source

pub fn sin(self) -> Self

Source

pub fn cos(self) -> Self

Source

pub fn tan(self) -> Self

Source

pub fn sinh(self) -> Self

Source

pub fn cosh(self) -> Self

Source

pub fn tanh(self) -> Self

Source

pub fn acos(self) -> Self

Source

pub fn ln(self) -> Self

Source

pub fn exp(self) -> Self

Source

pub fn powi(&self, n: i32) -> Self

Source

pub fn powf(&self, n: T) -> Self

Source

pub fn powc(&self, p: Self) -> Self

Source§

impl<F> Quaternion<F>
where F: RealField,

Source

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 - The i component of the vector part.
  • y - The j component of the vector part.
  • z - The k component 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);
Source

pub fn from_real(re: F) -> Self

Source

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);
Source

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);
Source

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>

Source§

type Output = Quaternion<T>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self

Performs the + operation. Read more
Source§

impl<T: RealField> AddAssign for Quaternion<T>

Source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
Source§

impl<F, T> AsPrimitive<T> for Quaternion<F>
where F: AsPrimitive<T> + Field, T: 'static + Copy + NumCast,

Source§

fn as_(self) -> T

Convert a value to another, using the as operator.
Source§

impl<F: Clone> Clone for Quaternion<F>

Source§

fn clone(&self) -> Quaternion<F>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F> ConstOne for Quaternion<F>

Source§

const ONE: Self

The multiplicative identity element of Self, 1.
Source§

impl<F> ConstZero for Quaternion<F>
where F: RealField + ConstZero,

Source§

const ZERO: Self

The additive identity element of Self, 0.
Source§

impl<F: Debug> Debug for Quaternion<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Default> Default for Quaternion<F>

Source§

fn default() -> Quaternion<F>

Returns the “default value” for a type. Read more
Source§

impl<F: RealField + Display> Display for Quaternion<F>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: RealField> Div<F> for Quaternion<F>

Source§

type Output = Quaternion<F>

The resulting type after applying the / operator.
Source§

fn div(self, scalar: F) -> Self

Performs the / operation. Read more
Source§

impl<F: RealField> Div for Quaternion<F>

Source§

type Output = Quaternion<F>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self

Performs the / operation. Read more
Source§

impl<F: RealField> DivAssign for Quaternion<F>

Source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
Source§

impl<T: RealField> DivisionAlgebra<T> for Quaternion<T>

Source§

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

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

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>

Source§

fn from_isize(n: isize) -> Option<Self>

Converts an 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>

Converts an 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>

Converts an 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>

Converts an 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>

Converts an 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>

Converts an 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>

Converts a 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>

Converts an 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>

Converts an 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>

Converts an 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>

Converts an 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>

Converts an u128 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_f32(n: f32) -> Option<Self>

Converts a f32 to return an optional value of this type. If the value cannot be represented by this type, then None is returned.
Source§

fn from_f64(n: f64) -> Option<Self>

Converts a f64 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>

Source§

type Output = Quaternion<F>

The resulting type after applying the * operator.
Source§

fn mul(self, scalar: F) -> Self

Performs the * operation. Read more
Source§

impl<F: RealField> Mul for Quaternion<F>

Source§

type Output = Quaternion<F>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self

Performs the * operation. Read more
Source§

impl<F: RealField> MulAssign<F> for Quaternion<F>

Source§

fn mul_assign(&mut self, scalar: F)

Performs the *= operation. Read more
Source§

impl<F: RealField> MulAssign for Quaternion<F>

Source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
Source§

impl<F> Neg for Quaternion<F>
where F: RealField,

Source§

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>

The resulting type after applying the - operator.
Source§

impl<F: RealField + NumCast> NumCast for Quaternion<F>

Source§

fn from<T: ToPrimitive>(n: T) -> Option<Self>

Creates a number from another value that can be converted into a primitive via the ToPrimitive trait. If the source value cannot be represented by the target type, then None is returned. Read more
Source§

impl<F> One for Quaternion<F>
where F: RealField,

Source§

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

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§

fn set_one(&mut self)

Sets self to the multiplicative identity element of Self, 1.
Source§

impl<F: PartialEq> PartialEq for Quaternion<F>

Source§

fn eq(&self, other: &Quaternion<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: PartialOrd> PartialOrd for Quaternion<F>

Source§

fn partial_cmp(&self, other: &Quaternion<F>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<F: RealField> Product for Quaternion<F>

Source§

fn product<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by multiplying the items.
Source§

impl<T: RealField> Rotation<T> for Quaternion<T>

Source§

fn rotate_x(&self, angle: T) -> Self

Rotation around the X-axis. Quaternions: Axis i. Quantum: Pauli X.
Source§

fn rotate_y(&self, angle: T) -> Self

Rotation around the Y-axis. Quaternions: Axis j. Quantum: Pauli Y.
Source§

fn rotate_z(&self, angle: T) -> Self

Rotation around the Z-axis (Phase). Quaternions: Axis k. Quantum: Pauli Z.
Source§

fn global_phase(&self, _angle: T) -> Self

Global Phase Shift. $P(\phi) = e^{i\phi}$.
Source§

impl<F: RealField> Sub for Quaternion<F>

Source§

type Output = Quaternion<F>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self

Performs the - operation. Read more
Source§

impl<F: RealField> SubAssign for Quaternion<F>

Source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
Source§

impl<F: RealField> Sum for Quaternion<F>

Source§

fn sum<I: Iterator<Item = Self>>(iter: I) -> Self

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl<F: RealField + ToPrimitive> ToPrimitive for Quaternion<F>

Source§

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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>

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,

Source§

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

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());
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl<T: RealField> AbelianGroup for Quaternion<T>

Source§

impl<T: RealField> Associative for Quaternion<T>

Source§

impl<F: Copy> Copy for Quaternion<F>

Source§

impl<T: RealField> Distributive for Quaternion<T>

Source§

impl<F> StructuralPartialEq for Quaternion<F>

Auto Trait Implementations§

§

impl<F> Freeze for Quaternion<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for Quaternion<F>
where F: RefUnwindSafe,

§

impl<F> Send for Quaternion<F>
where F: Send,

§

impl<F> Sync for Quaternion<F>
where F: Sync,

§

impl<F> Unpin for Quaternion<F>
where F: Unpin,

§

impl<F> UnwindSafe for Quaternion<F>
where F: UnwindSafe,

Blanket Implementations§

Source§

impl<T, R> Algebra<R> for T
where T: Module<R, Output = T> + Mul + MulAssign + One + Distributive, R: Ring,

Source§

fn sqr(&self) -> Self

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> InvMonoid for T
where T: MulMonoid + Div<Output = T> + DivAssign + One + Clone,

Source§

fn inverse(&self) -> T

Computes the multiplicative inverse of an element. Read more
Source§

impl<V, R> Module<R> for V
where V: AbelianGroup + Mul<R, Output = V> + MulAssign<R>, R: Ring,

Source§

fn scale(&self, scalar: R) -> Self

Scales the module element by a scalar from the ring R. Read more
Source§

fn scale_mut(&mut self, scalar: R)

Scales the module element in-place by a scalar from the ring R. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AddGroup for T
where T: Sub<Output = T> + Add<Output = T> + Zero + Clone,

Source§

impl<T> AddMagma for T
where T: Add<Output = T> + AddAssign + Clone + PartialEq,

Source§

impl<T> AddMonoid for T
where T: Add<Output = T> + AddAssign + Zero + Clone,

Source§

impl<T> AddSemigroup for T
where T: Add<Output = T> + Associative + Clone,

Source§

impl<T, R> AssociativeAlgebra<R> for T
where T: Algebra<R> + Ring, R: Ring,

Source§

impl<T, R> AssociativeDivisionAlgebra<R> for T

Source§

impl<T> AssociativeRing for T
where T: Ring + Associative,

Source§

impl<T> DivGroup for T
where T: MulGroup,

Source§

impl<T> Group for T
where T: AddGroup,

Source§

impl<T> MulGroup for T
where T: MulMonoid + InvMonoid<Output = T> + Div + DivAssign,

Source§

impl<T> MulMagma for T
where T: Mul<Output = T> + Clone,

Source§

impl<T> MulMonoid for T
where T: MulMagma + One + Associative,

Source§

impl<T> MulSemigroup for T
where T: Mul<Output = T> + Associative + Clone,

Source§

impl<T> Ring for T