Struct num_quaternion::Quaternion
source · pub struct Quaternion<T> {
pub w: T,
pub x: T,
pub y: T,
pub z: T,
}
Expand description
Quaternion type.
We follow the naming conventions from Wikipedia for quaternions.
Fields§
§w: T
Real part of the quaternion.
x: T
The coefficient of $i$.
y: T
The coefficient of $j$.
z: T
The coefficient of $k$.
Implementations§
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
source§impl<T> Quaternion<T>where
T: ConstZero,
impl<T> Quaternion<T>where
T: ConstZero,
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
sourcepub const ONE: Self = _
pub const ONE: Self = _
A constant Quaternion
of value $1$.
See also Quaternion::one()
.
sourcepub const I: Self = _
pub const I: Self = _
A constant Quaternion
of value $i$.
See also Quaternion::i()
.
sourcepub const J: Self = _
pub const J: Self = _
A constant Quaternion
of value $j$.
See also Quaternion::j()
.
sourcepub const K: Self = _
pub const K: Self = _
A constant Quaternion
of value $k$.
See also Quaternion::k()
.
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
sourcepub fn i() -> Self
pub fn i() -> Self
Returns the imaginary unit $i$.
See also Quaternion::I
.
sourcepub fn j() -> Self
pub fn j() -> Self
Returns the imaginary unit $j$.
See also Quaternion::J
.
sourcepub fn k() -> Self
pub fn k() -> Self
Returns the imaginary unit $k$.
See also Quaternion::K
.
source§impl<T> Quaternion<T>where
T: Float,
impl<T> Quaternion<T>where
T: Float,
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
sourcepub fn norm_sqr(&self) -> T
pub fn norm_sqr(&self) -> T
Returns the square of the norm.
The result is $w^2 + x^2 + y^2 + z^2$ with some rounding errors. The rounding error is at most 2 ulps.
This is guaranteed to be more efficient than norm()
.
Furthermore, T
only needs to support addition and multiplication
and therefore, this function works for more types than
norm()
.
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
source§impl<T> Quaternion<T>where
T: Float,
impl<T> Quaternion<T>where
T: Float,
sourcepub fn norm(self) -> T
pub fn norm(self) -> T
Calculates |self|.
The result is $\sqrt{w^2+x^2+y^2+z^2}$ with some possible rounding errors. The rounding error is at most 1.5 ulps.
sourcepub fn normalize(self) -> Option<UnitQuaternion<T>>
pub fn normalize(self) -> Option<UnitQuaternion<T>>
Normalizes the quaternion to length $1$.
The sign of the real part will be the same as the sign of the input. If the input quaternion
- is zero, or
- has infinite length, or
- has a
NaN
value, thenNone
will be returned.
source§impl<T> Quaternion<T>
impl<T> Quaternion<T>
Trait Implementations§
source§impl<T> Add<Quaternion<T>> for UnitQuaternion<T>
impl<T> Add<Quaternion<T>> for UnitQuaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
+
operator.source§impl<T> Add<T> for Quaternion<T>where
T: Add<T, Output = T>,
impl<T> Add<T> for Quaternion<T>where
T: Add<T, Output = T>,
source§impl<T> Add<UnitQuaternion<T>> for Quaternion<T>where
T: Add<T, Output = T>,
impl<T> Add<UnitQuaternion<T>> for Quaternion<T>where
T: Add<T, Output = T>,
§type Output = Quaternion<T>
type Output = Quaternion<T>
+
operator.source§impl<T> Add for Quaternion<T>where
T: Add<T, Output = T>,
impl<T> Add for Quaternion<T>where
T: Add<T, Output = T>,
§type Output = Quaternion<T>
type Output = Quaternion<T>
+
operator.source§impl<T, S> AddAssign<S> for Quaternion<T>
impl<T, S> AddAssign<S> for Quaternion<T>
source§fn add_assign(&mut self, other: S)
fn add_assign(&mut self, other: S)
+=
operation. Read moresource§impl<T> Borrow<Quaternion<T>> for UnitQuaternion<T>
impl<T> Borrow<Quaternion<T>> for UnitQuaternion<T>
source§fn borrow(&self) -> &Quaternion<T>
fn borrow(&self) -> &Quaternion<T>
source§impl<T: Clone> Clone for Quaternion<T>
impl<T: Clone> Clone for Quaternion<T>
source§fn clone(&self) -> Quaternion<T>
fn clone(&self) -> Quaternion<T>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T> ConstOne for Quaternion<T>
impl<T> ConstOne for Quaternion<T>
source§impl<T> ConstZero for Quaternion<T>where
T: ConstZero,
impl<T> ConstZero for Quaternion<T>where
T: ConstZero,
source§impl<T: Debug> Debug for Quaternion<T>
impl<T: Debug> Debug for Quaternion<T>
source§impl<T: Default> Default for Quaternion<T>
impl<T: Default> Default for Quaternion<T>
source§fn default() -> Quaternion<T>
fn default() -> Quaternion<T>
source§impl<T> Div<Quaternion<T>> for UnitQuaternion<T>
impl<T> Div<Quaternion<T>> for UnitQuaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
/
operator.source§impl<T> Div<T> for Quaternion<T>
impl<T> Div<T> for Quaternion<T>
source§impl<T> Div<UnitQuaternion<T>> for Quaternion<T>
impl<T> Div<UnitQuaternion<T>> for Quaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
/
operator.source§impl<T> Div for Quaternion<T>
impl<T> Div for Quaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
/
operator.source§impl<T, S> DivAssign<S> for Quaternion<T>
impl<T, S> DivAssign<S> for Quaternion<T>
source§fn div_assign(&mut self, other: S)
fn div_assign(&mut self, other: S)
/=
operation. Read moresource§impl<'a, T> From<&'a T> for Quaternion<T>
impl<'a, T> From<&'a T> for Quaternion<T>
source§impl<'a, T> From<&'a UnitQuaternion<T>> for &'a Quaternion<T>
impl<'a, T> From<&'a UnitQuaternion<T>> for &'a Quaternion<T>
source§fn from(q: &'a UnitQuaternion<T>) -> Self
fn from(q: &'a UnitQuaternion<T>) -> Self
source§impl<T> From<T> for Quaternion<T>where
T: Zero,
impl<T> From<T> for Quaternion<T>where
T: Zero,
source§impl<T> From<UnitQuaternion<T>> for Quaternion<T>
impl<T> From<UnitQuaternion<T>> for Quaternion<T>
source§fn from(q: UnitQuaternion<T>) -> Self
fn from(q: UnitQuaternion<T>) -> Self
source§impl<T: Hash> Hash for Quaternion<T>
impl<T: Hash> Hash for Quaternion<T>
source§impl<T> Inv for &Quaternion<T>
impl<T> Inv for &Quaternion<T>
source§impl<T> Inv for Quaternion<T>
impl<T> Inv for Quaternion<T>
source§impl<T> Mul<Quaternion<T>> for UnitQuaternion<T>
impl<T> Mul<Quaternion<T>> for UnitQuaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
*
operator.source§impl<T> Mul<T> for Quaternion<T>
impl<T> Mul<T> for Quaternion<T>
source§impl<T> Mul<UnitQuaternion<T>> for Quaternion<T>
impl<T> Mul<UnitQuaternion<T>> for Quaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
*
operator.source§impl<T> Mul for Quaternion<T>
impl<T> Mul for Quaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
*
operator.source§impl<T, S> MulAssign<S> for Quaternion<T>
impl<T, S> MulAssign<S> for Quaternion<T>
source§fn mul_assign(&mut self, other: S)
fn mul_assign(&mut self, other: S)
*=
operation. Read moresource§impl<T> Neg for Quaternion<T>where
T: Neg<Output = T>,
impl<T> Neg for Quaternion<T>where
T: Neg<Output = T>,
source§impl<T> One for Quaternion<T>
impl<T> One for Quaternion<T>
source§impl<T: PartialEq> PartialEq for Quaternion<T>
impl<T: PartialEq> PartialEq for Quaternion<T>
source§fn eq(&self, other: &Quaternion<T>) -> bool
fn eq(&self, other: &Quaternion<T>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<T> Sub<Quaternion<T>> for UnitQuaternion<T>
impl<T> Sub<Quaternion<T>> for UnitQuaternion<T>
§type Output = Quaternion<T>
type Output = Quaternion<T>
-
operator.source§impl<T> Sub<T> for Quaternion<T>where
T: Sub<T, Output = T>,
impl<T> Sub<T> for Quaternion<T>where
T: Sub<T, Output = T>,
source§impl<T> Sub<UnitQuaternion<T>> for Quaternion<T>where
T: Sub<T, Output = T>,
impl<T> Sub<UnitQuaternion<T>> for Quaternion<T>where
T: Sub<T, Output = T>,
§type Output = Quaternion<T>
type Output = Quaternion<T>
-
operator.source§impl<T> Sub for Quaternion<T>where
T: Sub<T, Output = T>,
impl<T> Sub for Quaternion<T>where
T: Sub<T, Output = T>,
§type Output = Quaternion<T>
type Output = Quaternion<T>
-
operator.source§impl<T, S> SubAssign<S> for Quaternion<T>
impl<T, S> SubAssign<S> for Quaternion<T>
source§fn sub_assign(&mut self, other: S)
fn sub_assign(&mut self, other: S)
-=
operation. Read more