Quaternion

Struct Quaternion 

Source
pub struct Quaternion<T>(pub T, pub T, pub T, pub T);
Expand description

A Quaternion with the format q = (q.0)i + (q.1)j + (q.2)k + (q.3) Quaternions are usually stored q = r + ai + bj + ck in this case however they are stored in the format q = ai + bj + ck + r to emphasize the fact that you can essentially use the r value as a scaler.

Tuple Fields§

§0: T§1: T§2: T§3: T

Implementations§

Source§

impl<T> Quaternion<T>

Source

pub fn new(a: T, b: T, c: T, r: T) -> Self

Creates a new Quaternion with defined a, b, c, and r values.

§Attributes
  • a - value multiplied by the imaginary number i in q = ai + bj + ck + r
  • b - value multiplied by the imaginary number j in q = ai + bj + ck + r
  • c - value multiplied by the imaginary number k in q = ai + bj + ck + r
  • r - The real number denoted r in q = ai + bj + ck + r
Source

pub fn new_vector_real(vector: Vector3<T>, real: T) -> Self

makes a quaternion from a Vector3 and a given real r value

§Arguments
  • vector - A Vector3 which maps out to (a, b, c)
  • real - The r value of the Quaternion
Source

pub fn new_axis_angle(axis: Vector3<T>, angle: T) -> Self
where T: Mul<T, Output = T> + Div<T, Output = T> + Add<T, Output = T> + F32Fmt + Debug + One + Two + Copy,

creates a new quaternion that corresponds to a given rotation around a given axis

§Arguments
  • axis - The Vector3 rotation axis
  • angle - the angle to rotate around that axis
Source

pub fn identity() -> Self
where T: Zero + One,

Returns the identity quaternion that is used for multiplying

§Arguments
  • zero - the T equivalent of zero
  • one - the T equivalent of one
Source

pub fn identity_add() -> Self
where T: Zero,

Returns the identity quaternion that is used for adding

§Arguments
  • zero - the T equivalent of zero
Source

pub fn conjugate(&self) -> Self
where T: Neg<Output = T> + Copy,

Returns the conjugate of the quaternion denoted q*

§Arguments
§Examples
todo!();
Source

pub fn norm(&self) -> T
where T: Add<T, Output = T> + Mul<T, Output = T> + F32Fmt + Copy,

Returns the magnitude of the quaternion denoted ||q||

§Arguments
§Examples
todo!();
Source

pub fn unit_quaternion(&self) -> Self
where T: Add<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + F32Fmt + Copy,

Returns the unit quaternion form of the quaternion denoted Uq

§Arguments
§Examples
todo!();
Source

pub fn reciprocal(&self) -> Self
where T: Add<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + Copy + One,

Returns the reciprocal of a quaternion denoted q⁻¹

§Arguments
§Examples
todo!();
Source

pub fn slerp(self, to: Self, time_stamp: T::F32Fmt) -> Self
where T: F32Fmt + One + Mul<T, Output = T> + Add<T, Output = T> + Sub<T, Output = T> + Neg<Output = T> + Copy + Div<T, Output = T>,

Source

pub fn sin(self) -> Self
where T: Copy + F32Fmt + One + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Neg<Output = T>,

Source

pub fn cos(self) -> Self

Source

pub fn tan(self) -> Self

Source§

impl Quaternion<f32>

Source

pub fn camera_look_at_v1(pos: Vector3<f32>, look_at: Vector3<f32>) -> Self

testing

Source

pub fn from_axes(left: Vector3<f32>, frd: Vector3<f32>) -> Self

testing

Source

pub fn camera_look_at( pos: Vector3<f32>, look_at: Vector3<f32>, ) -> Quaternion<f32>

Camera Objects look along the -Z axis so the look_at function for a camera object needs to be modified a little. flipping the pos and the look_at should do the trick.

   ^ Z
   |
   |
Y• C ------> X
  / \
 /   \
/     \
§Arguments
  • pos - A Vector3<f32> representing the position of the camera
  • look_at - A Vector3<f32> representing the position the camera is to look at
§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), todo!());
Source

pub fn f32_identity() -> Self

Trait Implementations§

Source§

impl<T> Add<T> for Quaternion<T>
where T: Add<T, Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the + operator.
Source§

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

Performs the + operation. Read more
Source§

impl<T> Add for Quaternion<T>
where T: Add<T, Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the + operator.
Source§

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

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 for Quaternion<T>
where T: Copy + Debug,

Source§

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

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

impl<T> Div<T> for Quaternion<T>
where T: Div<T, Output = T> + Copy,

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> Div for Quaternion<T>
where T: Copy + Neg<Output = T> + Sub<T, Output = T> + Add<T, Output = T> + Div<T, Output = 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> F32Fmt for Quaternion<T>
where T: F32Fmt + Copy + Mul<T, Output = T> + Add<T, Output = T> + Sub<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + One,

Source§

type F32Fmt = Quaternion<<T as F32Fmt>::F32Fmt>

Source§

fn intoF32Fmt(self) -> Self::F32Fmt

Source§

fn fromF32Fmt(f32_fmt: Self::F32Fmt) -> Self

Source§

fn sqrt(self) -> Self

Source§

fn cbrt(self) -> Self

Source§

fn f32_const_mul(self, constant: f32) -> Self

Source§

fn sin_mul(self, mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cos_mul(self, mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tan_mul(self, mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn asin_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn acos_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn atan2_mul(self, _other: Self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn sinh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn cosh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

fn tanh_mul(self, _mul_by: Self) -> Self
where Self: Mul<Self, Output = Self> + Sized,

Source§

impl<T> From<Axes<T>> for Quaternion<T>
where T: Construct<T> + Copy,

Source§

fn from(a: Axes<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Euler<T>> for Quaternion<T>
where T: Construct<T> + Copy,

Source§

fn from(e: Euler<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Matrix3<T>> for Quaternion<T>
where T: F32Fmt + Add<T, Output = T> + Sub<T, Output = T> + Div<T, Output = T> + Mul<T, Output = T> + Debug + Two + One + Zero + Copy,

Source§

fn from(mat3: Matrix3<T>) -> Self

Converts to this type from the input type.
Source§

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

Source§

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

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Axes<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + F32Fmt + Debug + One + Two + Zero + Copy,

Source§

fn from(q: Quaternion<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Euler<T>
where T: Construct<T> + Copy,

Source§

fn from(q: Quaternion<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Matrix3<T>
where T: Add<T, Output = T> + Sub<T, Output = T> + Mul<T, Output = T> + Div<T, Output = T> + Neg<Output = T> + Copy + One + Two,

Source§

fn from(other: Quaternion<T>) -> Matrix3<T>

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Rotor<T>
where T: Construct<T> + Copy,

Source§

fn from(q: Quaternion<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Vector3<T>
where T: Copy,

Source§

fn from(other: Quaternion<T>) -> Vector3<T>

Converts to this type from the input type.
Source§

impl<T> From<Quaternion<T>> for Vector4<T>
where T: Copy,

Source§

fn from(other: Quaternion<T>) -> Vector4<T>

Converts to this type from the input type.
Source§

impl<T> From<Rotor<T>> for Quaternion<T>
where T: Construct<T> + Copy,

Source§

fn from(r: Rotor<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Mul<T> for Quaternion<T>
where T: Mul<T, Output = T> + Copy,

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> Mul for Quaternion<T>
where T: Sub<T, Output = T> + Mul<T, Output = T> + Add<T, Output = T> + Copy,

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> Neg for Quaternion<T>
where T: Neg<Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl<T> One for Quaternion<T>
where T: One + Zero,

Source§

const ONE: Self

Source§

impl<T> PartialEq for Quaternion<T>
where T: Neg<Output = T> + PartialEq + Copy,

Source§

fn eq(&self, other: &Self) -> 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> Rem<T> for Quaternion<T>
where T: Rem<T, Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the % operator.
Source§

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

Performs the % operation. Read more
Source§

impl<T> Rem for Quaternion<T>
where T: Copy + Neg<Output = T> + Sub<T, Output = T> + Add<T, Output = T> + Rem<T, Output = T>,

Source§

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

TODO Test

Source§

type Output = Quaternion<T>

The resulting type after applying the % operator.
Source§

impl<T> Rotation<T> for Quaternion<T>
where T: Construct<T>,

Source§

fn look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self

§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), Quaternion::new());
Source§

fn camera_look_at_xy(pos: Vector3<T>, look_at: Vector3<T>) -> Self

§Examples
use crate::linear_algebra::Vector3;
let pos = Vector3::new(0.0, 0.0, 0.0);
let look_at = Vector3::new(1.0, 1.0, 1.0);
assert_eq!(camera_look_at(pos, look_at), todo!());
Source§

fn look_at_xz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self

Generate a rotation for an object at a position look at a point. only uses the X and Z rotation axes to arrive at this result Z rotation axis Read more
Source§

fn look_at_yz(_pos: Vector3<T>, _look_at: Vector3<T>) -> Self

Generate a rotation for an object at a position look at a point. only uses the Z and Y rotation axes to arrive at this result Z rotation axis Read more
Source§

fn look_at_lock( _pos: Vector3<T>, _look_at: Vector3<T>, _locked_axis: Vector3<T>, ) -> Self

Generate a rotation for an object at a position look at a point. only uses the Z and Y rotation axes to arrive at this result Z rotation axis Read more
Source§

fn camera_look_at_xz(pos: Vector3<T>, look_at: Vector3<T>) -> Self

Source§

fn camera_look_at_yz(pos: Vector3<T>, look_at: Vector3<T>) -> Self

Source§

fn camera_look_at_lock( pos: Vector3<T>, look_at: Vector3<T>, locked_axis: Vector3<T>, ) -> Self

Source§

const X_AXIS: Vector3<T> = _

Source§

const Y_AXIS: Vector3<T> = _

Source§

const Z_AXIS: Vector3<T> = _

Source§

impl<T> SignOps for Quaternion<T>
where T: SignOps + Add<T, Output = T>,

Source§

fn ptcopysign(self, sign: Self) -> Self

Source§

fn ptsignum(self) -> i8

Source§

fn abs(self) -> Self

Source§

impl<T> Sub<T> for Quaternion<T>
where T: Sub<T, Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T> Sub for Quaternion<T>
where T: Sub<T, Output = T> + Copy,

Source§

type Output = Quaternion<T>

The resulting type after applying the - operator.
Source§

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

Performs the - operation. Read more
Source§

impl<T> Two for Quaternion<T>
where T: Two + Zero,

Source§

const TWO: Self

Source§

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

Source§

const ZERO: Self

Source§

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

Source§

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

Source§

impl<T> ImaginaryConstruct<T> for Quaternion<T>
where T: Construct<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, 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, A> Typed<T> for A
where T: Construct<A>,