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>
impl<S: BaseFloat> Quaternion<S>
sourcepub fn new(w: S, xi: S, yj: S, zk: S) -> Quaternion<S>
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
sourcepub fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S>
pub fn from_sv(s: S, v: Vector3<S>) -> Quaternion<S>
Construct a new quaternion from a scalar and a vector
sourcepub fn zero() -> Quaternion<S>
pub fn zero() -> Quaternion<S>
The additive identity, ie: q = 0 + 0i + 0j + 0i
sourcepub fn one() -> Quaternion<S>
pub fn one() -> Quaternion<S>
The multiplicative identity, ie: q = 1 + 0i + 0j + 0i
sourcepub fn dot(self, q: Quaternion<S>) -> S
pub fn dot(self, q: Quaternion<S>) -> S
The dot product of the quaternion and q
.
sourcepub fn conjugate(self) -> Quaternion<S>
pub fn conjugate(self) -> Quaternion<S>
The conjugate of the quaternion.
sourcepub fn magnitude2(self) -> S
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.
sourcepub fn magnitude(&self) -> S
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.
sourcepub fn normalize(self) -> Quaternion<S>
pub fn normalize(self) -> Quaternion<S>
Normalize this quaternion, returning the new quaternion.
sourcepub fn nlerp(self, other: Quaternion<S>, amount: S) -> Quaternion<S>
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>
impl<S: BaseFloat> Quaternion<S>
sourcepub fn slerp(self, other: Quaternion<S>, amount: S) -> Quaternion<S>
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)
Trait Implementations§
source§impl<'a, 'b, S: BaseFloat> Add<&'b Quaternion<S>> for &'a Quaternion<S>
impl<'a, 'b, S: BaseFloat> Add<&'b Quaternion<S>> for &'a Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
+
operator.source§fn add(self, other: &'b Quaternion<S>) -> Quaternion<S>
fn add(self, other: &'b Quaternion<S>) -> Quaternion<S>
+
operation. Read moresource§impl<S: BaseFloat> ApproxEq for Quaternion<S>
impl<S: BaseFloat> ApproxEq for Quaternion<S>
source§impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S>
impl<S: BaseFloat> AsMut<(S, S, S, S)> for Quaternion<S>
source§fn as_mut(&mut self) -> &mut (S, S, S, S)
fn as_mut(&mut self) -> &mut (S, S, S, S)
source§impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S>
impl<S: BaseFloat> AsRef<(S, S, S, S)> for Quaternion<S>
source§fn as_ref(&self) -> &(S, S, S, S)
fn as_ref(&self) -> &(S, S, S, S)
source§impl<S: Clone> Clone for Quaternion<S>
impl<S: Clone> Clone for Quaternion<S>
source§fn clone(&self) -> Quaternion<S>
fn clone(&self) -> Quaternion<S>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<S: BaseFloat> Debug for Quaternion<S>
impl<S: BaseFloat> Debug for Quaternion<S>
source§impl<S: Decodable> Decodable for Quaternion<S>
impl<S: Decodable> Decodable for Quaternion<S>
source§impl<'a, S: BaseFloat> Div<S> for &'a Quaternion<S>
impl<'a, S: BaseFloat> Div<S> for &'a Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
/
operator.source§fn div(self, value: S) -> Quaternion<S>
fn div(self, value: S) -> Quaternion<S>
/
operation. Read moresource§impl<S: BaseFloat> Div<S> for Quaternion<S>
impl<S: BaseFloat> Div<S> for Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
/
operator.source§fn div(self, value: S) -> Quaternion<S>
fn div(self, value: S) -> Quaternion<S>
/
operation. Read moresource§impl<S: Encodable> Encodable for Quaternion<S>
impl<S: Encodable> Encodable for Quaternion<S>
source§impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S>
impl<'a, S: BaseFloat> From<&'a [S; 4]> for &'a Quaternion<S>
source§fn from(v: &'a [S; 4]) -> &'a Quaternion<S>
fn from(v: &'a [S; 4]) -> &'a Quaternion<S>
source§impl<'a, S: BaseFloat> From<&'a (S, S, S, S)> for &'a Quaternion<S>
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>
fn from(v: &'a (S, S, S, S)) -> &'a Quaternion<S>
source§impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S>
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>
fn from(v: &'a mut [S; 4]) -> &'a mut Quaternion<S>
source§impl<'a, S: BaseFloat> From<&'a mut (S, S, S, S)> for &'a mut Quaternion<S>
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>
fn from(v: &'a mut (S, S, S, S)) -> &'a mut Quaternion<S>
source§impl<S: BaseFloat> From<[S; 4]> for Quaternion<S>
impl<S: BaseFloat> From<[S; 4]> for Quaternion<S>
source§fn from(v: [S; 4]) -> Quaternion<S>
fn from(v: [S; 4]) -> Quaternion<S>
source§impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S>
impl<S: BaseFloat> From<(S, S, S, S)> for Quaternion<S>
source§fn from(v: (S, S, S, S)) -> Quaternion<S>
fn from(v: (S, S, S, S)) -> Quaternion<S>
source§impl<S: BaseFloat> From<Basis3<S>> for Quaternion<S>
impl<S: BaseFloat> From<Basis3<S>> for Quaternion<S>
source§fn from(b: Basis3<S>) -> Quaternion<S>
fn from(b: Basis3<S>) -> Quaternion<S>
source§impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S>
impl<S: BaseFloat> From<Matrix3<S>> for Quaternion<S>
source§fn from(mat: Matrix3<S>) -> Quaternion<S>
fn from(mat: Matrix3<S>) -> Quaternion<S>
Convert the matrix to a quaternion
source§impl<S: BaseFloat> From<Quaternion<S>> for Basis3<S>
impl<S: BaseFloat> From<Quaternion<S>> for Basis3<S>
source§fn from(quat: Quaternion<S>) -> Basis3<S>
fn from(quat: Quaternion<S>) -> Basis3<S>
source§impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S>
impl<S: BaseFloat> From<Quaternion<S>> for Matrix3<S>
source§fn from(quat: Quaternion<S>) -> Matrix3<S>
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>
impl<S: BaseFloat> From<Quaternion<S>> for Matrix4<S>
source§fn from(quat: Quaternion<S>) -> Matrix4<S>
fn from(quat: Quaternion<S>) -> Matrix4<S>
Convert the quaternion to a 4 x 4 rotation matrix
source§impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S>
impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S>
source§fn into(self) -> (S, S, S, S)
fn into(self) -> (S, S, S, S)
source§impl<'a, 'b, S: BaseFloat> Mul<&'b Quaternion<S>> for &'a Quaternion<S>
impl<'a, 'b, S: BaseFloat> Mul<&'b Quaternion<S>> for &'a Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
*
operator.source§fn mul(self, other: &'b Quaternion<S>) -> Quaternion<S>
fn mul(self, other: &'b Quaternion<S>) -> Quaternion<S>
*
operation. Read moresource§impl<'a, S: BaseFloat> Mul<S> for &'a Quaternion<S>
impl<'a, S: BaseFloat> Mul<S> for &'a Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
*
operator.source§fn mul(self, value: S) -> Quaternion<S>
fn mul(self, value: S) -> Quaternion<S>
*
operation. Read moresource§impl<S: BaseFloat> Mul<S> for Quaternion<S>
impl<S: BaseFloat> Mul<S> for Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
*
operator.source§fn mul(self, value: S) -> Quaternion<S>
fn mul(self, value: S) -> Quaternion<S>
*
operation. Read moresource§impl<S: BaseFloat> Neg for Quaternion<S>
impl<S: BaseFloat> Neg for Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
-
operator.source§fn neg(self) -> Quaternion<S>
fn neg(self) -> Quaternion<S>
-
operation. Read moresource§impl<S: PartialEq> PartialEq<Quaternion<S>> for Quaternion<S>
impl<S: PartialEq> PartialEq<Quaternion<S>> for Quaternion<S>
source§fn eq(&self, other: &Quaternion<S>) -> bool
fn eq(&self, other: &Quaternion<S>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<S: BaseFloat> Rotation<Point3<S>> for Quaternion<S>
impl<S: BaseFloat> Rotation<Point3<S>> for Quaternion<S>
source§fn one() -> Quaternion<S>
fn one() -> Quaternion<S>
source§fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Quaternion<S>
fn look_at(dir: Vector3<S>, up: Vector3<S>) -> Quaternion<S>
source§fn between_vectors(a: Vector3<S>, b: Vector3<S>) -> Quaternion<S>
fn between_vectors(a: Vector3<S>, b: Vector3<S>) -> Quaternion<S>
source§fn rotate_vector(&self, vec: Vector3<S>) -> Vector3<S>
fn rotate_vector(&self, vec: Vector3<S>) -> Vector3<S>
source§fn concat(&self, other: &Quaternion<S>) -> Quaternion<S>
fn concat(&self, other: &Quaternion<S>) -> Quaternion<S>
source§fn concat_self(&mut self, other: &Quaternion<S>)
fn concat_self(&mut self, other: &Quaternion<S>)
source§fn invert(&self) -> Quaternion<S>
fn invert(&self) -> Quaternion<S>
r.concat(r.invert())
is the identity.source§fn invert_self(&mut self)
fn invert_self(&mut self)
source§fn rotate_point(&self, point: P) -> P
fn rotate_point(&self, point: P) -> P
source§impl<S> Rotation3<S> for Quaternion<S>where
S: 'static + BaseFloat,
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>
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>
fn from_axis_angle(axis: Vector3<S>, angle: Rad<S>) -> Quaternion<S>
source§fn from_angle_x(theta: Rad<S>) -> Self
fn from_angle_x(theta: Rad<S>) -> Self
x
axis (pitch).source§fn from_angle_y(theta: Rad<S>) -> Self
fn from_angle_y(theta: Rad<S>) -> Self
y
axis (yaw).source§fn from_angle_z(theta: Rad<S>) -> Self
fn from_angle_z(theta: Rad<S>) -> Self
z
axis (roll).source§impl<'a, 'b, S: BaseFloat> Sub<&'b Quaternion<S>> for &'a Quaternion<S>
impl<'a, 'b, S: BaseFloat> Sub<&'b Quaternion<S>> for &'a Quaternion<S>
§type Output = Quaternion<S>
type Output = Quaternion<S>
-
operator.source§fn sub(self, other: &'b Quaternion<S>) -> Quaternion<S>
fn sub(self, other: &'b Quaternion<S>) -> Quaternion<S>
-
operation. Read more