# Struct cgmath::Quaternion [−] [src]

#[repr(C)]
pub struct Quaternion<S> { pub s: S, pub v: Vector3<S>, }

A quaternion in scalar/vector form.

This type is marked as #[repr(C)].

## Fields

The scalar part of the quaternion.

The vector part of the quaternion.

## Methods

### impl<S: BaseFloat> Quaternion<S>[src]

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

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

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

Construct a new quaternion from a scalar and a vector.

#### fn from_arc(    src: Vector3<S>,     dst: Vector3<S>,     fallback: Option<Vector3<S>>) -> Quaternion<S>

Construct a new quaternion as a closest arc between two vectors

Return the closest rotation that turns src vector into dst.

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

The conjugate of the quaternion.

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

Do a normalized linear interpolation with other, by amount.

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

### impl<S: NumCast + Copy> Quaternion<S>[src]

#### fn cast<T: BaseFloat>(&self) -> Quaternion<T>

Component-wise casting to another type.

## Trait Implementations

### impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S>[src]

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

Convert the matrix to a quaternion

### impl<S: Clone> Clone for Quaternion<S>[src]

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

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

### impl<S: Debug> Debug for Quaternion<S>[src]

#### fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.

### impl<S: PartialEq> PartialEq for Quaternion<S>[src]

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

This method tests for self and other values to be equal, and is used by ==. Read more

#### fn ne(&self, __arg_0: &Quaternion<S>) -> bool

This method tests for !=.

### impl<S: BaseFloat> Zero for Quaternion<S>[src]

#### fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.

### impl<S: BaseFloat> One for Quaternion<S>[src]

#### fn one() -> Quaternion<S>

Returns the multiplicative identity element of Self, 1. Read more

### impl<S: BaseFloat> Sum<Quaternion<S>> for Quaternion<S>[src]

#### fn sum<I: Iterator<Item = Quaternion<S>>>(iter: I) -> Quaternion<S>

Method which takes an iterator and generates Self from the elements by "summing up" the items. Read more

### impl<'a, S: 'a + BaseFloat> Sum<&'a Quaternion<S>> for Quaternion<S>[src]

#### fn sum<I: Iterator<Item = &'a Quaternion<S>>>(iter: I) -> Quaternion<S>

Method which takes an iterator and generates Self from the elements by "summing up" the items. Read more

### impl<S: BaseFloat> Product<Quaternion<S>> for Quaternion<S>[src]

#### fn product<I: Iterator<Item = Quaternion<S>>>(iter: I) -> Quaternion<S>

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

### impl<'a, S: 'a + BaseFloat> Product<&'a Quaternion<S>> for Quaternion<S>[src]

#### fn product<I: Iterator<Item = &'a Quaternion<S>>>(iter: I) -> Quaternion<S>

Method which takes an iterator and generates Self from the elements by multiplying the items. Read more

### impl<S: BaseFloat> VectorSpace for Quaternion<S>[src]

#### type Scalar = S

The associated scalar.

### impl<S: BaseFloat> MetricSpace for Quaternion<S>[src]

#### type Metric = S

The metric to be returned by the distance function.

#### fn distance2(self, other: Self) -> S

Returns the squared distance. Read more

#### fn distance(self, other: Self) -> Self::Metric

The distance between two values.

### impl<S: BaseFloat> InnerSpace for Quaternion<S>[src]

#### fn dot(self, other: Quaternion<S>) -> S

Vector dot (or inner) product.

#### fn is_perpendicular(self, other: Self) -> bool

Returns true if the vector is perpendicular (at right angles) to the other vector. Read more

#### fn magnitude2(self) -> Self::Scalar

Returns the squared magnitude. Read more

#### fn magnitude(self) -> Self::Scalar

The distance from the tail to the tip of the vector.

#### fn angle(self, other: Self) -> Rad<Self::Scalar>

Returns the angle between two vectors in radians.

#### fn normalize(self) -> Self

Returns a vector with the same direction, but with a magnitude of 1.

#### fn normalize_to(self, magnitude: Self::Scalar) -> Self

Returns a vector with the same direction and a given magnitude.

#### fn lerp(self, other: Self, amount: Self::Scalar) -> Self

Returns the result of linearly interpolating the magnitude of the vector towards the magnitude of other by the specified amount. Read more

### impl<A> From<Euler<A>> for Quaternion<A::Unitless> where    A: Angle + Into<Rad<<A as Angle>::Unitless>>, [src]

#### fn from(src: Euler<A>) -> Quaternion<A::Unitless>

Performs the conversion.

### impl<S: BaseFloat> Neg for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

#### fn neg(self) -> Quaternion<S>

The method for the unary - operator

### impl<'a, S: BaseFloat> Neg for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

#### fn neg(self) -> Quaternion<S>

The method for the unary - operator

### impl<S: BaseFloat> Mul<S> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<'a, S: BaseFloat> Mul<S> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<S: BaseFloat + MulAssign<S>> MulAssign<S> for Quaternion<S>[src]

#### fn mul_assign(&mut self, scalar: S)

The method for the *= operator

### impl<S: BaseFloat> Div<S> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the / operator

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

The method for the / operator

### impl<'a, S: BaseFloat> Div<S> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the / operator

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

The method for the / operator

### impl<S: BaseFloat + DivAssign<S>> DivAssign<S> for Quaternion<S>[src]

#### fn div_assign(&mut self, scalar: S)

The method for the /= operator

### impl<S: BaseFloat> Rem<S> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the % operator

#### fn rem(self, other: S) -> Quaternion<S>

The method for the % operator

### impl<'a, S: BaseFloat> Rem<S> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the % operator

#### fn rem(self, other: S) -> Quaternion<S>

The method for the % operator

### impl<S: BaseFloat + RemAssign<S>> RemAssign<S> for Quaternion<S>[src]

#### fn rem_assign(&mut self, scalar: S)

The method for the %= operator

### impl<S: BaseFloat> Mul<Vector3<S>> for Quaternion<S>[src]

#### type Output = Vector3<S>

The resulting type after applying the * operator

#### fn mul(self, other: Vector3<S>) -> Vector3<S>

The method for the * operator

### impl<'a, S: BaseFloat> Mul<&'a Vector3<S>> for Quaternion<S>[src]

#### type Output = Vector3<S>

The resulting type after applying the * operator

#### fn mul(self, other: &'a Vector3<S>) -> Vector3<S>

The method for the * operator

### impl<'a, S: BaseFloat> Mul<Vector3<S>> for &'a Quaternion<S>[src]

#### type Output = Vector3<S>

The resulting type after applying the * operator

#### fn mul(self, other: Vector3<S>) -> Vector3<S>

The method for the * operator

### impl<'a, 'b, S: BaseFloat> Mul<&'a Vector3<S>> for &'b Quaternion<S>[src]

#### type Output = Vector3<S>

The resulting type after applying the * operator

#### fn mul(self, other: &'a Vector3<S>) -> Vector3<S>

The method for the * operator

### impl<S: BaseFloat> Add<Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the + operator

#### fn add(self, other: Quaternion<S>) -> Quaternion<S>

The method for the + operator

### impl<'a, S: BaseFloat> Add<&'a Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the + operator

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

The method for the + operator

### impl<'a, S: BaseFloat> Add<Quaternion<S>> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the + operator

#### fn add(self, other: Quaternion<S>) -> Quaternion<S>

The method for the + operator

### impl<'a, 'b, S: BaseFloat> Add<&'a Quaternion<S>> for &'b Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the + operator

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

The method for the + operator

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

The method for the += operator

### impl<S: BaseFloat> Sub<Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

#### fn sub(self, other: Quaternion<S>) -> Quaternion<S>

The method for the - operator

### impl<'a, S: BaseFloat> Sub<&'a Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

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

The method for the - operator

### impl<'a, S: BaseFloat> Sub<Quaternion<S>> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

#### fn sub(self, other: Quaternion<S>) -> Quaternion<S>

The method for the - operator

### impl<'a, 'b, S: BaseFloat> Sub<&'a Quaternion<S>> for &'b Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the - operator

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

The method for the - operator

### impl<S: BaseFloat + SubAssign<S>> SubAssign<Quaternion<S>> for Quaternion<S>[src]

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

The method for the -= operator

### impl<S: BaseFloat> Mul<Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<'a, S: BaseFloat> Mul<&'a Quaternion<S>> for Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<'a, S: BaseFloat> Mul<Quaternion<S>> for &'a Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<'a, 'b, S: BaseFloat> Mul<&'a Quaternion<S>> for &'b Quaternion<S>[src]

#### type Output = Quaternion<S>

The resulting type after applying the * operator

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

The method for the * operator

### impl<S: BaseFloat> ApproxEq for Quaternion<S>[src]

#### type Epsilon = S::Epsilon

Used for specifying relative comparisons.

#### fn default_epsilon() -> S::Epsilon

The default tolerance to use when testing values that are close together. Read more

#### fn default_max_relative() -> S::Epsilon

The default relative tolerance for testing values that are far-apart. Read more

#### fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more

#### fn relative_eq(    &self,     other: &Self,     epsilon: S::Epsilon,     max_relative: S::Epsilon) -> bool

A test for equality that uses a relative comparison if the values are far apart.

#### fn ulps_eq(&self, other: &Self, epsilon: S::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.

#### fn relative_ne(    &self,     other: &Self,     epsilon: Self::Epsilon,     max_relative: Self::Epsilon) -> bool

The inverse of ApproxEq::relative_eq.

#### fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of ApproxEq::ulps_eq.

### impl<S: BaseFloat> Rotation<Point3<S>> for Quaternion<S>[src]

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

Create a rotation to a given direction with an 'up' vector.

#### 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. Read more

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

Rotate a vector using this rotation.

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

Create a new rotation which "un-does" this rotation. That is, r * r.invert() is the identity. Read more

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

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

### impl<S: BaseFloat> Rotation3<S> for Quaternion<S>[src]

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

Create a rotation using an angle around a given axis. Read more

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

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

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

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

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

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

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

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

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

Performs the conversion.

### impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S>[src]

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

Performs the conversion.

### impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S>[src]

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

Performs the conversion.

### impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S>[src]

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

Performs the conversion.

### impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S>[src]

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

Performs the conversion.

### impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S>[src]

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

Performs the conversion.

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

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

Performs the conversion.

### impl<S: BaseFloat> Index<usize> for Quaternion<S>[src]

#### type Output = S

The returned type after indexing

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

The method for the indexing (container[index]) operation

### impl<S: BaseFloat> IndexMut<usize> for Quaternion<S>[src]

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

The method for the mutable indexing (container[index]) operation

### impl<S: BaseFloat> Index<Range<usize>> for Quaternion<S>[src]

#### type Output = [S]

The returned type after indexing

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

The method for the indexing (container[index]) operation

### impl<S: BaseFloat> IndexMut<Range<usize>> for Quaternion<S>[src]

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

The method for the mutable indexing (container[index]) operation

### impl<S: BaseFloat> Index<RangeTo<usize>> for Quaternion<S>[src]

#### type Output = [S]

The returned type after indexing

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

The method for the indexing (container[index]) operation

### impl<S: BaseFloat> IndexMut<RangeTo<usize>> for Quaternion<S>[src]

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

The method for the mutable indexing (container[index]) operation

### impl<S: BaseFloat> Index<RangeFrom<usize>> for Quaternion<S>[src]

#### type Output = [S]

The returned type after indexing

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

The method for the indexing (container[index]) operation

### impl<S: BaseFloat> IndexMut<RangeFrom<usize>> for Quaternion<S>[src]

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

The method for the mutable indexing (container[index]) operation

### impl<S: BaseFloat> Index<RangeFull> for Quaternion<S>[src]

#### type Output = [S]

The returned type after indexing

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

The method for the indexing (container[index]) operation

### impl<S: BaseFloat> IndexMut<RangeFull> for Quaternion<S>[src]

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

The method for the mutable indexing (container[index]) operation

### impl<S: BaseFloat + Rand> Rand for Quaternion<S>[src]

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

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

### impl<S: BaseFloat> From<Basis3<S>> for Quaternion<S>[src]

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

Performs the conversion.