Struct Quaternion

Source
#[repr(C)]
pub struct Quaternion<T> { /* private fields */ }
Expand description

Quaternion type

Implementations§

Source§

impl<T> Quaternion<T>

Source

pub const fn new(q0: T, q: V3<T>) -> Self

Construct a new Quaternion from a number(real part) and a vector(imag part)

Source

pub const fn new_from(q0: T, q1: T, q2: T, q3: T) -> Self

Construct a new Quaternion from raw four numbers

Source§

impl<T: Num + Copy> Quaternion<T>

Source

pub fn dot(&self, rhs: Self) -> T

dot product

Source

pub fn real(&self) -> T

get the real part

Source

pub fn imag(&self) -> V3<T>

get the imaginary part

Source

pub fn one() -> Quaternion<T>

construct a unit Quaternion

Source

pub fn zero() -> Self

construct a zero Quaternion

Source

pub fn new_real(q0: T) -> Self

construct a pure “real” Quaternion

Source

pub fn new_imag(q: &V3<T>) -> Self

construct a pure “imaginary” Quaternion

Source

pub fn abs2(&self) -> T

calculate the abs2 of the Quaternion

Source

pub fn new_from_vec(v: &V4<T>) -> Self

Construct a new Quternion from a V4

Source

pub fn to_rotation(&self) -> M33<T>

convert the Quaternion to a rotation matrix

Source§

impl<T: Num + Copy + Signed> Quaternion<T>

Source

pub fn conj(&self) -> Self

Source§

impl<T: Float + Sum> Quaternion<T>

Source

pub fn from_rotation(rot: &M33<T>) -> Self

convert a rotation matrix M33 to a Quaternion

Source§

impl<T: Float> Quaternion<T>

Source

pub fn norm2(&self) -> T

the euclidean norm of the Quaternion

Source

pub fn normalize(&self) -> Option<Self>

normalize the Quaternion only if necessary

Source

pub fn abs_imag(&self) -> T

get the norm of the “imaginary” part

Source

pub fn rotation(theta: T, vector: &V3<T>) -> Self

generate a Quaternion that represents a rotation of a angle theta around the axis(normalized) v

Source

pub fn rotation_norm_encoded(v: &V3<T>) -> Self

generate a Quaternion that represents a rotation of a angle theta around the axis(normalized) v, the angle theta is encoded in the norm of the vector v

Source

pub fn from_euler_angles(yay: T, pitch: T, roll: T) -> Self

create a quaternion that represents the rotation from a Euler angles with the roll-pitch-yay convention

Source

pub fn get_angle(&self) -> T

get the angle of representation from this Quaternion

Source

pub fn get_axis(&self) -> Option<V3<T>>

get the axis of rotation from which this Quaternion represent

Source

pub fn axis_angle(&self) -> (Option<V3<T>>, T)

combine the two previous methods: get_axis and get_angle

Source

pub fn normalize_q(&self) -> Self

normalize the Quaternion

Source

pub fn argq(&self) -> Self

get the argument of the Quaternion

Source

pub fn exp(&self) -> Self

exponential function apply to the current Quaternion

Source

pub fn ln(&self) -> Self

natural logaritmic function apply to the current Quaternion

Source

pub fn sqrt(&self) -> Self

sqrt function apply to the current Quaternion

Source

pub fn pow(&self, rhs: Self) -> Self

power the current Quaternion to the rhs argument

Source

pub fn slerp(a: Self, b: Self, t: T) -> Self

Spherical Linear Interpolation between two Quaternions this implementation follow this implementations:

https://www.mrpt.org/tutorials/programming/maths-and-geometry/slerp-interpolation/

Function arguments:

a: Quaternion(normalized)

b: Quaternion(normalized)

t: Float in the closed interval [0.0, 1.0]

Source

pub fn derivative(&self, rate: &V3<T>) -> Self

Calculate the instantaneous Quaternion derivative representing a Quaternion rotating at rate given by a vector rate

Function arguments:

rate: V3

Source§

impl<T: Float + Signed> Quaternion<T>

Source

pub fn inverse(&self) -> Option<Self>

Calculate the inverse of the Quaternion

Source

pub fn sin(&self) -> Self

sin function apply to the current Quaternion

Source

pub fn cos(&self) -> Self

cos function apply to the current Quaternion

Source§

impl<T: Float + FloatConst> Quaternion<T>

Source

pub fn to_euler_angles(&self) -> (T, T, T)

get the euler angles from the Quaternion

Trait Implementations§

Source§

impl<T: Num + Copy> Add for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T: Clone> Clone for Quaternion<T>

Source§

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

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<T: Debug> Debug for Quaternion<T>

Source§

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

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

impl<T: Num + Display> Display for Quaternion<T>

Source§

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

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

impl<T: Num + Copy> Div<T> for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Float + Signed> Div for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: Self) -> Self::Output

Performs the / operation. Read more
Source§

impl<T: Copy> From<[T; 4]> for Quaternion<T>

Source§

fn from(data: [T; 4]) -> Quaternion<T>

Converts to this type from the input type.
Source§

impl<T: Num + Copy> Mul<T> for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Num + Copy + Signed> Mul<V3<T>> for Quaternion<T>

Source§

type Output = V3<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: V3<T>) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Num + Copy> Mul for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<T: Num + Copy + Signed> Neg for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<T: Num + Copy> One for Quaternion<T>

Source§

fn one() -> Self

Create an identity Quaternion

Source§

fn set_one(&mut self)

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

fn is_one(&self) -> bool
where Self: PartialEq,

Returns true if self is equal to the multiplicative identity. Read more
Source§

impl<T: PartialEq> PartialEq for Quaternion<T>

Source§

fn eq(&self, other: &Quaternion<T>) -> 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<T: Num + Copy> Sub for Quaternion<T>

Source§

type Output = Quaternion<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T: Num + Copy> Zero for Quaternion<T>

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

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

impl<T: Copy> Copy for Quaternion<T>

Source§

impl<T> StructuralPartialEq for Quaternion<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

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> 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.