Struct cgmath::Quaternion

source ·
pub struct Quaternion<S> {
    pub s: S,
    pub v: Vector3<S>,
}
Expand description

A quaternion in scalar/vector form.

Fields§

§s: S§v: Vector3<S>

Implementations§

source§

impl<S: BaseFloat> Quaternion<S>

source

pub fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion<S>

Construct a new quaternion from one scalar component and three imaginary components

source

pub fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S>

Construct a new quaternion from a scalar and a vector

source

pub fn zero() -> Quaternion<S>

The additive identity, ie: q = 0 + 0i + 0j + 0i

source

pub fn one() -> Quaternion<S>

The multiplicative identity, ie: q = 1 + 0i + 0j + 0i

source

pub fn dot(self, q: Quaternion<S>) -> S

The dot product of the quaternion and q.

source

pub fn conjugate(self) -> Quaternion<S>

The conjugate of the quaternion.

source

pub fn magnitude2(self) -> S

The squared magnitude of the quaternion. This is useful for magnitude comparisons where the exact magnitude does not need to be calculated.

source

pub fn magnitude(&self) -> S

The magnitude of the quaternion

Performance notes

For instances where the exact magnitude of the quaternion does not need to be known, for example for quaternion-quaternion magnitude comparisons, it is advisable to use the magnitude2 method instead.

source

pub fn normalize(self) -> Quaternion<S>

Normalize this quaternion, returning the new quaternion.

source

pub fn nlerp(self, other: Quaternion<S>, amount: S) -> Quaternion<S>

Do a normalized linear interpolation with other, by amount.

source§

impl<S: BaseFloat> Quaternion<S>

source

pub fn slerp(self, other: Quaternion<S>, amount: S) -> Quaternion<S>

Spherical Linear Intoperlation

Return the spherical linear interpolation between the quaternion and other. Both quaternions should be normalized first.

Performance notes

The acos operation used in slerp is an expensive operation, so unless your quarternions are far away from each other it’s generally more advisable to use nlerp when you know your rotations are going to be small.

  • [Understanding Slerp, Then Not Using It] (http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/)
  • [Arcsynthesis OpenGL tutorial] (http://www.arcsynthesis.org/gltut/Positioning/Tut08%20Interpolation.html)
source

pub fn to_euler(self) -> (Rad<S>, Rad<S>, Rad<S>)

Convert a Quaternion to Eular angles This is a polar singularity aware conversion

Based on:

  • [Maths - Conversion Quaternion to Euler] (http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/)

Trait Implementations§

source§

impl<'a, 'b, S: BaseFloat> Add<&'b Quaternion<S>> for &'a Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the + operator.
source§

fn add(self, other: &'b Quaternion<S>) -> Quaternion<S>

Performs the + operation. Read more
source§

impl<S: BaseFloat> ApproxEq for Quaternion<S>

§

type Epsilon = S

source§

fn approx_eq_eps(&self, other: &Quaternion<S>, epsilon: &S) -> bool

source§

fn approx_epsilon() -> Self::Epsilon

source§

fn approx_eq(&self, other: &Self) -> bool

source§

impl<S: BaseFloat> AsMut<[S; 4]> for Quaternion<S>

source§

fn as_mut(&mut self) -> &mut [S; 4]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S>

source§

fn as_mut(&mut self) -> &mut (S, S, S, S)

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S: BaseFloat> AsRef<[S; 4]> for Quaternion<S>

source§

fn as_ref(&self) -> &[S; 4]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S>

source§

fn as_ref(&self) -> &(S, S, S, S)

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S: Clone> Clone for Quaternion<S>

source§

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

Returns a copy 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<S: BaseFloat> Debug for Quaternion<S>

source§

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

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

impl<S: Decodable> Decodable for Quaternion<S>

source§

fn decode<__D: Decoder>(d: &mut __D) -> Result<Quaternion<S>, __D::Error>

Deserialize a value using a Decoder.
source§

impl<'a, S: BaseFloat> Div<S> for &'a Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the / operator.
source§

fn div(self, value: S) -> Quaternion<S>

Performs the / operation. Read more
source§

impl<S: BaseFloat> Div<S> for Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the / operator.
source§

fn div(self, value: S) -> Quaternion<S>

Performs the / operation. Read more
source§

impl<S: Encodable> Encodable for Quaternion<S>

source§

fn encode<__S: Encoder>(&self, s: &mut __S) -> Result<(), __S::Error>

Serialize a value using an Encoder.
source§

impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S>

source§

fn from(v: &'a [S; 4]) -> &'a Quaternion<S>

Converts to this type from the input type.
source§

impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S>

source§

fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S>

Converts to this type from the input type.
source§

impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S>

source§

fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S>

Converts to this type from the input type.
source§

impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S>

source§

fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S>

Converts to this type from the input type.
source§

impl<S: BaseFloat> From<[S; 4]> for Quaternion<S>

source§

fn from(v: [S; 4]) -> Quaternion<S>

Converts to this type from the input type.
source§

impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S>

source§

fn from(v: (S, S, S, S)) -> Quaternion<S>

Converts to this type from the input type.
source§

impl<S: BaseFloat> From<Basis3<S>> for Quaternion<S>

source§

fn from(b: Basis3<S>) -> Quaternion<S>

Converts to this type from the input type.
source§

impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S>

source§

fn from(mat: Matrix3<S>) -> Quaternion<S>

Convert the matrix to a quaternion

source§

impl<S: BaseFloat> From<Quaternion<S>> for Basis3<S>

source§

fn from(quat: Quaternion<S>) -> Basis3<S>

Converts to this type from the input type.
source§

impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S>

source§

fn from(quat: Quaternion<S>) -> Matrix3<S>

Convert the quaternion to a 3 x 3 rotation matrix

source§

impl<S: BaseFloat> From<Quaternion<S>> for Matrix4<S>

source§

fn from(quat: Quaternion<S>) -> Matrix4<S>

Convert the quaternion to a 4 x 4 rotation matrix

source§

impl<S: BaseFloat> Index<Range<usize>> for Quaternion<S>

§

type Output = [S]

The returned type after indexing.
source§

fn index<'a>(&'a self, i: Range<usize>) -> &'a [S]

Performs the indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> Index<RangeFrom<usize>> for Quaternion<S>

§

type Output = [S]

The returned type after indexing.
source§

fn index<'a>(&'a self, i: RangeFrom<usize>) -> &'a [S]

Performs the indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> Index<RangeFull> for Quaternion<S>

§

type Output = [S]

The returned type after indexing.
source§

fn index<'a>(&'a self, i: RangeFull) -> &'a [S]

Performs the indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> Index<RangeTo<usize>> for Quaternion<S>

§

type Output = [S]

The returned type after indexing.
source§

fn index<'a>(&'a self, i: RangeTo<usize>) -> &'a [S]

Performs the indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> Index<usize> for Quaternion<S>

§

type Output = S

The returned type after indexing.
source§

fn index<'a>(&'a self, i: usize) -> &'a S

Performs the indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> IndexMut<Range<usize>> for Quaternion<S>

source§

fn index_mut<'a>(&'a mut self, i: Range<usize>) -> &'a mut [S]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> IndexMut<RangeFrom<usize>> for Quaternion<S>

source§

fn index_mut<'a>(&'a mut self, i: RangeFrom<usize>) -> &'a mut [S]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> IndexMut<RangeFull> for Quaternion<S>

source§

fn index_mut<'a>(&'a mut self, i: RangeFull) -> &'a mut [S]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> IndexMut<RangeTo<usize>> for Quaternion<S>

source§

fn index_mut<'a>(&'a mut self, i: RangeTo<usize>) -> &'a mut [S]

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> IndexMut<usize> for Quaternion<S>

source§

fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S

Performs the mutable indexing (container[index]) operation. Read more
source§

impl<S: BaseFloat> Into<[S; 4]> for Quaternion<S>

source§

fn into(self) -> [S; 4]

Converts this type into the (usually inferred) input type.
source§

impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S>

source§

fn into(self) -> (S, S, S, S)

Converts this type into the (usually inferred) input type.
source§

impl<'a, 'b, S: BaseFloat> Mul<&'b Quaternion<S>> for &'a Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the * operator.
source§

fn mul(self, other: &'b Quaternion<S>) -> Quaternion<S>

Performs the * operation. Read more
source§

impl<'a, 'b, S: BaseFloat> Mul<&'b Vector3<S>> for &'a Quaternion<S>

§

type Output = Vector3<S>

The resulting type after applying the * operator.
source§

fn mul(self, vec: &'b Vector3<S>) -> Vector3<S>

Performs the * operation. Read more
source§

impl<'a, S: BaseFloat> Mul<S> for &'a Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the * operator.
source§

fn mul(self, value: S) -> Quaternion<S>

Performs the * operation. Read more
source§

impl<S: BaseFloat> Mul<S> for Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the * operator.
source§

fn mul(self, value: S) -> Quaternion<S>

Performs the * operation. Read more
source§

impl<S: BaseFloat> Neg for Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the - operator.
source§

fn neg(self) -> Quaternion<S>

Performs the unary - operation. Read more
source§

impl<S: PartialEq> PartialEq<Quaternion<S>> for Quaternion<S>

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<S: BaseFloat + Rand> Rand for Quaternion<S>

source§

fn rand<R: Rng>(rng: &mut R) -> Quaternion<S>

Generates a random instance of this type using the specified source of randomness.
source§

impl<S: BaseFloat> Rotation<Point3<S>> for Quaternion<S>

source§

fn one() -> Quaternion<S>

Create the identity transform (causes no transformation).
source§

fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Quaternion<S>

Create a rotation to a given direction with an ‘up’ vector
source§

fn between_vectors(a: Vector3<S>, b: Vector3<S>) -> Quaternion<S>

Create a shortest rotation to transform vector ‘a’ into ‘b’. Both given vectors are assumed to have unit length.
source§

fn rotate_vector(&self, vec: Vector3<S>) -> Vector3<S>

Rotate a vector using this rotation.
source§

fn concat(&self, other: &Quaternion<S>) -> Quaternion<S>

Create a new rotation which combines both this rotation, and another.
source§

fn concat_self(&mut self, other: &Quaternion<S>)

Modify this rotation in-place by combining it with another.
source§

fn invert(&self) -> Quaternion<S>

Create a new rotation which “un-does” this rotation. That is, r.concat(r.invert()) is the identity.
source§

fn invert_self(&mut self)

Invert this rotation in-place.
source§

fn rotate_point(&self, point: P) -> P

Rotate a point using this rotation, by converting it to its representation as a vector.
source§

impl<S> Rotation3<S> for Quaternion<S>where S: 'static + BaseFloat,

source§

fn from_euler(x: Rad<S>, y: Rad<S>, z: Rad<S>) -> Quaternion<S>

  • [Maths - Conversion Euler to Quaternion] (http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm)
source§

fn from_axis_angle(axis: Vector3<S>, angle: Rad<S>) -> Quaternion<S>

Create a rotation using an angle around a given axis.
source§

fn from_angle_x(theta: Rad<S>) -> Self

Create a rotation from an angle around the x axis (pitch).
source§

fn from_angle_y(theta: Rad<S>) -> Self

Create a rotation from an angle around the y axis (yaw).
source§

fn from_angle_z(theta: Rad<S>) -> Self

Create a rotation from an angle around the z axis (roll).
source§

impl<'a, 'b, S: BaseFloat> Sub<&'b Quaternion<S>> for &'a Quaternion<S>

§

type Output = Quaternion<S>

The resulting type after applying the - operator.
source§

fn sub(self, other: &'b Quaternion<S>) -> Quaternion<S>

Performs the - operation. Read more
source§

impl<S: Copy> Copy for Quaternion<S>

source§

impl<S> StructuralPartialEq for Quaternion<S>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.