Struct vek::quaternion::repr_c::Quaternion [−][src]
#[repr(C)]pub struct Quaternion<T> { pub x: T, pub y: T, pub z: T, pub w: T, }
Expand description
Quaternions are a convenient representation for rotations in 3D spaces.
IMPORTANT: Quaternions are only valid as rotations as long as they are normalized (i.e their magnitude is 1). Most operations assume this, instead of normalizing inputs behind your back, so be careful.
They essentially consist of a vector part (x
, y
, z
), and scalar part (w
).
For unit quaternions, the vector part is the unit axis of rotation scaled by the sine of
the half-angle of the rotation, and the scalar part is the cosine of the half-angle.
Fields
x: T
y: T
z: T
w: T
Implementations
impl<T> Quaternion<T>
[src]
impl<T> Quaternion<T>
[src]pub fn from_xyzw(x: T, y: T, z: T, w: T) -> Self
[src]
pub fn from_xyzw(x: T, y: T, z: T, w: T) -> Self
[src]Creates a new quaternion with x
, y
, z
and w
elements in order.
You are responsible for ensuring that the resulting quaternion is normalized.
pub fn from_scalar_and_vec3<V: Into<Vec3<T>>>(pair: (T, V)) -> Self
[src]
pub fn from_scalar_and_vec3<V: Into<Vec3<T>>>(pair: (T, V)) -> Self
[src]Creates a new quaternion from a scalar-and-vector pair.
You are responsible for ensuring that the resulting quaternion is normalized.
pub fn into_scalar_and_vec3(self) -> (T, Vec3<T>)
[src]
pub fn into_scalar_and_vec3(self) -> (T, Vec3<T>)
[src]Converts this quaternion into a scalar-and-vector pair by destructuring.
Not to be confused with into_angle_axis()
.
pub fn zero() -> Self where
T: Zero,
[src]
pub fn zero() -> Self where
T: Zero,
[src]Creates a new quaternion with all elements set to zero.
Be careful: since it has a magnitude equal to zero, it is not valid to use for most operations.
pub fn identity() -> Self where
T: Zero + One,
[src]
pub fn identity() -> Self where
T: Zero + One,
[src]Creates the identity quaternion.
use std::f32::consts::PI; let id = Quaternion::<f32>::identity(); assert_eq!(id, Default::default()); assert_relative_eq!(id, id.conjugate()); assert_relative_eq!(id, id.inverse()); let q = Quaternion::rotation_y(PI); assert_relative_eq!(id * q, q); assert_relative_eq!(q * id, q);
pub fn conjugate(self) -> Self where
T: Neg<Output = T>,
[src]
pub fn conjugate(self) -> Self where
T: Neg<Output = T>,
[src]Gets this quaternion’s conjugate (copy with negated vector part).
On normalized quaternions, the conjugate also happens to be the inverse.
use std::f32::consts::PI; let p = Quaternion::rotation_x(PI); let q = Quaternion::rotation_z(PI); assert_relative_eq!((p*q).conjugate(), q.conjugate() * p.conjugate()); // Rotation quaternions are normalized, so their conjugate is also their inverse. assert_relative_eq!(q.conjugate(), q.inverse());
pub fn inverse(self) -> Self where
T: Neg<Output = T> + Copy + Add<T, Output = T> + Mul<Output = T> + Div<Output = T>,
[src]
pub fn inverse(self) -> Self where
T: Neg<Output = T> + Copy + Add<T, Output = T> + Mul<Output = T> + Div<Output = T>,
[src]Gets this quaternion’s inverse, i.e the one that reverses its effect.
On normalized quaternions, the inverse happens to be the conjugate.
use std::f32::consts::PI; let rot = Quaternion::rotation_y(PI); let inv = rot.inverse(); assert_relative_eq!(rot*inv, Quaternion::identity()); assert_relative_eq!(inv*rot, Quaternion::identity()); let p = Quaternion::rotation_x(PI); let q = Quaternion::rotation_z(PI); assert_relative_eq!((p*q).inverse(), q.inverse() * p.inverse());
pub fn dot(self, q: Self) -> T where
T: Copy + Add<T, Output = T> + Mul<Output = T>,
[src]
pub fn dot(self, q: Self) -> T where
T: Copy + Add<T, Output = T> + Mul<Output = T>,
[src]Gets the dot product between two quaternions.
pub fn normalized(self) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn normalized(self) -> Self where
T: Real + Add<T, Output = T>,
[src]Gets a normalized copy of this quaternion.
pub fn magnitude_squared(self) -> T where
T: Real + Add<T, Output = T>,
[src]
pub fn magnitude_squared(self) -> T where
T: Real + Add<T, Output = T>,
[src]Gets this quaternion’s magnitude, squared.
pub fn magnitude(self) -> T where
T: Real + Add<T, Output = T>,
[src]
pub fn magnitude(self) -> T where
T: Real + Add<T, Output = T>,
[src]Gets this quaternion’s magnitude.
pub fn rotation_from_to_3d<V: Into<Vec3<T>>>(from: V, to: V) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotation_from_to_3d<V: Into<Vec3<T>>>(from: V, to: V) -> Self where
T: Real + Add<T, Output = T>,
[src]Creates a quaternion that would rotate a from
direction to to
.
let (from, to) = (Vec4::<f32>::unit_x(), Vec4::<f32>::unit_y()); let q = Quaternion::<f32>::rotation_from_to_3d(from, to); assert_relative_eq!(q * from, to); assert_relative_eq!(q * Vec4::unit_y(), -Vec4::unit_x()); let (from, to) = (Vec4::<f32>::unit_x(), -Vec4::<f32>::unit_x()); let q = Quaternion::<f32>::rotation_from_to_3d(from, to); assert_relative_eq!(q * from, to);
pub fn rotation_3d<V: Into<Vec3<T>>>(angle_radians: T, axis: V) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotation_3d<V: Into<Vec3<T>>>(angle_radians: T, axis: V) -> Self where
T: Real + Add<T, Output = T>,
[src]Creates a quaternion from an angle and axis. The axis is not required to be normalized.
pub fn rotation_x(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotation_x(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Creates a quaternion from an angle for a rotation around the X axis.
pub fn rotation_y(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotation_y(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Creates a quaternion from an angle for a rotation around the Y axis.
pub fn rotation_z(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotation_z(angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Creates a quaternion from an angle for a rotation around the Y axis.
pub fn rotated_3d<V: Into<Vec3<T>>>(self, angle_radians: T, axis: V) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotated_3d<V: Into<Vec3<T>>>(self, angle_radians: T, axis: V) -> Self where
T: Real + Add<T, Output = T>,
[src]Returns this quaternion rotated around the given axis with given angle. The axis is not required to be normalized.
pub fn rotated_x(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotated_x(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Returns this quaternion rotated around the X axis with given angle.
pub fn rotated_y(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotated_y(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Returns this quaternion rotated around the Y axis with given angle.
pub fn rotated_z(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]
pub fn rotated_z(self, angle_radians: T) -> Self where
T: Real + Add<T, Output = T>,
[src]Returns this quaternion rotated around the Z axis with given angle.
pub fn rotate_3d<V: Into<Vec3<T>>>(&mut self, angle_radians: T, axis: V) where
T: Real + Add<T, Output = T>,
[src]
pub fn rotate_3d<V: Into<Vec3<T>>>(&mut self, angle_radians: T, axis: V) where
T: Real + Add<T, Output = T>,
[src]Rotates this quaternion around the given axis with given angle. The axis is not required to be normalized.
pub fn rotate_x(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]
pub fn rotate_x(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]Rotates this quaternion around the X axis with given angle.
pub fn rotate_y(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]
pub fn rotate_y(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]Rotates this quaternion around the Y axis with given angle.
pub fn rotate_z(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]
pub fn rotate_z(&mut self, angle_radians: T) where
T: Real + Add<T, Output = T>,
[src]Rotates this quaternion around the Z axis with given angle.
pub fn into_angle_axis(self) -> (T, Vec3<T>) where
T: Real,
[src]
pub fn into_angle_axis(self) -> (T, Vec3<T>) where
T: Real,
[src]Convert this quaternion to angle-axis representation, assuming the quaternion is normalized.
use std::f32::consts::PI; let q = Quaternion::rotation_x(PI/2.); let (angle, axis) = q.into_angle_axis(); assert_relative_eq!(angle, PI/2.); assert_relative_eq!(axis, Vec3::unit_x()); let angle = PI*4./5.; let axis = Vec3::new(1_f32, 2., 3.); let q = Quaternion::rotation_3d(angle, axis); let (a, v) = q.into_angle_axis(); assert_relative_eq!(a, angle); assert_relative_eq!(v, axis.normalized());
impl<T> Quaternion<T> where
T: Copy + One + Mul<Output = T> + Sub<Output = T> + MulAdd<T, T, Output = T>,
[src]
impl<T> Quaternion<T> where
T: Copy + One + Mul<Output = T> + Sub<Output = T> + MulAdd<T, T, Output = T>,
[src]pub fn lerp_precise_unnormalized(from: Self, to: Self, factor: T) -> Self where
T: Clamp + Zero,
[src]
pub fn lerp_precise_unnormalized(from: Self, to: Self, factor: T) -> Self where
T: Clamp + Zero,
[src]Performs linear interpolation without normalizing the result, using an implementation that supposedly yields a more precise result.
This is probably not what you’re looking for.
For an implementation that normalizes the result (which is more commonly wanted), see the Lerp
implementation.
pub fn lerp_unclamped_precise_unnormalized(
from: Self,
to: Self,
factor: T
) -> Self
[src]
pub fn lerp_unclamped_precise_unnormalized(
from: Self,
to: Self,
factor: T
) -> Self
[src]Performs linear interpolation without normalizing the result and without
implicitly constraining factor
to be between 0 and 1,
using an implementation that supposedly yields a more precise result.
This is probably not what you’re looking for.
For an implementation that normalizes the result (which is more commonly wanted), see the Lerp
implementation.
impl<T> Quaternion<T> where
T: Copy + Sub<Output = T> + MulAdd<T, T, Output = T>,
[src]
impl<T> Quaternion<T> where
T: Copy + Sub<Output = T> + MulAdd<T, T, Output = T>,
[src]pub fn lerp_unnormalized(from: Self, to: Self, factor: T) -> Self where
T: Clamp + Zero + One,
[src]
pub fn lerp_unnormalized(from: Self, to: Self, factor: T) -> Self where
T: Clamp + Zero + One,
[src]Performs linear interpolation without normalizing the result.
This is probably not what you’re looking for.
For an implementation that normalizes the result (which is more commonly wanted), see the Lerp
implementation.
pub fn lerp_unclamped_unnormalized(from: Self, to: Self, factor: T) -> Self
[src]
pub fn lerp_unclamped_unnormalized(from: Self, to: Self, factor: T) -> Self
[src]Performs linear interpolation without normalizing the result and without
implicitly constraining factor
to be between 0 and 1.
This is probably not what you’re looking for.
For an implementation that normalizes the result (which is more commonly wanted), see the Lerp
implementation.
impl<T> Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
[src]
impl<T> Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
[src]pub fn slerp_unclamped(from: Self, to: Self, factor: T) -> Self
[src]
pub fn slerp_unclamped(from: Self, to: Self, factor: T) -> Self
[src]Performs spherical linear interpolation without implictly constraining factor
to
be between 0 and 1.
use std::f32::consts::PI; let from = Quaternion::rotation_z(0_f32); let to = Quaternion::rotation_z(PI*9./10.); let angles = 32; for i in 0..angles { let factor = (i as f32) / (angles as f32); let expected = Quaternion::rotation_z(factor * PI*9./10.); let slerp = Quaternion::slerp(from, to, factor); assert_relative_eq!(slerp, expected); }
Trait Implementations
impl<T: AbsDiffEq> AbsDiffEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]
impl<T: AbsDiffEq> AbsDiffEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]fn default_epsilon() -> T::Epsilon
[src]
fn default_epsilon() -> T::Epsilon
[src]The default tolerance to use when testing values that are close together. Read more
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
[src]
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
[src]A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
[src]
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
[src]The inverse of AbsDiffEq::abs_diff_eq
.
impl<T> Add<Quaternion<T>> for Quaternion<T> where
T: Add<Output = T>,
[src]
impl<T> Add<Quaternion<T>> for Quaternion<T> where
T: Add<Output = T>,
[src]impl<T: Clone> Clone for Quaternion<T>
[src]
impl<T: Clone> Clone for Quaternion<T>
[src]fn clone(&self) -> Quaternion<T>
[src]
fn clone(&self) -> Quaternion<T>
[src]Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]Performs copy-assignment from source
. Read more
impl<T: Debug> Debug for Quaternion<T>
[src]
impl<T: Debug> Debug for Quaternion<T>
[src]impl<T: Zero + One> Default for Quaternion<T>
[src]
impl<T: Zero + One> Default for Quaternion<T>
[src]The default value for a quaternion is the identity.
assert_eq!(Quaternion::<f32>::identity(), Quaternion::default());
impl<'de, T> Deserialize<'de> for Quaternion<T> where
T: Deserialize<'de>,
[src]
impl<'de, T> Deserialize<'de> for Quaternion<T> where
T: Deserialize<'de>,
[src]fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]Deserialize this value from the given Serde deserializer. Read more
impl<T> Div<T> for Quaternion<T> where
T: Copy + Div<Output = T>,
[src]
impl<T> Div<T> for Quaternion<T> where
T: Copy + Div<Output = T>,
[src]impl<T> From<Quaternion<T>> for Mat4<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]
impl<T> From<Quaternion<T>> for Mat4<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]Rotation matrices can be obtained from quaternions. This implementation only works properly if the quaternion is normalized.
use std::f32::consts::PI; let angles = 32; for i in 0..angles { let theta = PI * 2. * (i as f32) / (angles as f32); assert_relative_eq!(Mat4::rotation_x(theta), Mat4::from(Quaternion::rotation_x(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_y(theta), Mat4::from(Quaternion::rotation_y(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_z(theta), Mat4::from(Quaternion::rotation_z(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_x(theta), Mat4::rotation_3d(theta, Vec4::unit_x())); assert_relative_eq!(Mat4::rotation_y(theta), Mat4::rotation_3d(theta, Vec4::unit_y())); assert_relative_eq!(Mat4::rotation_z(theta), Mat4::rotation_3d(theta, Vec4::unit_z())); // See what rotating unit vectors do for most angles between 0 and 2*PI. // It's helpful to picture this as a right-handed coordinate system. let v = Vec4::unit_y(); let m = Mat4::rotation_x(theta); assert_relative_eq!(m * v, Vec4::new(0., theta.cos(), theta.sin(), 0.)); let v = Vec4::unit_z(); let m = Mat4::rotation_y(theta); assert_relative_eq!(m * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.)); let v = Vec4::unit_x(); let m = Mat4::rotation_z(theta); assert_relative_eq!(m * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.)); }
fn from(q: Quaternion<T>) -> Self
[src]
fn from(q: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for Mat3<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]
impl<T> From<Quaternion<T>> for Mat3<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]fn from(q: Quaternion<T>) -> Self
[src]
fn from(q: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for Mat4<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]
impl<T> From<Quaternion<T>> for Mat4<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]Rotation matrices can be obtained from quaternions. This implementation only works properly if the quaternion is normalized.
use std::f32::consts::PI; let angles = 32; for i in 0..angles { let theta = PI * 2. * (i as f32) / (angles as f32); assert_relative_eq!(Mat4::rotation_x(theta), Mat4::from(Quaternion::rotation_x(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_y(theta), Mat4::from(Quaternion::rotation_y(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_z(theta), Mat4::from(Quaternion::rotation_z(theta)), epsilon = 0.000001); assert_relative_eq!(Mat4::rotation_x(theta), Mat4::rotation_3d(theta, Vec4::unit_x())); assert_relative_eq!(Mat4::rotation_y(theta), Mat4::rotation_3d(theta, Vec4::unit_y())); assert_relative_eq!(Mat4::rotation_z(theta), Mat4::rotation_3d(theta, Vec4::unit_z())); // See what rotating unit vectors do for most angles between 0 and 2*PI. // It's helpful to picture this as a right-handed coordinate system. let v = Vec4::unit_y(); let m = Mat4::rotation_x(theta); assert_relative_eq!(m * v, Vec4::new(0., theta.cos(), theta.sin(), 0.)); let v = Vec4::unit_z(); let m = Mat4::rotation_y(theta); assert_relative_eq!(m * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.)); let v = Vec4::unit_x(); let m = Mat4::rotation_z(theta); assert_relative_eq!(m * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.)); }
fn from(q: Quaternion<T>) -> Self
[src]
fn from(q: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for Mat3<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]
impl<T> From<Quaternion<T>> for Mat3<T> where
T: Copy + Zero + One + Mul<Output = T> + Add<Output = T> + Sub<Output = T>,
[src]fn from(q: Quaternion<T>) -> Self
[src]
fn from(q: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for Vec4<T>
[src]
impl<T> From<Quaternion<T>> for Vec4<T>
[src]A Vec4
can be created directly from a quaternion’s x
, y
, z
and w
elements.
fn from(v: Quaternion<T>) -> Self
[src]
fn from(v: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for Vec3<T>
[src]
impl<T> From<Quaternion<T>> for Vec3<T>
[src]A Vec3
can be created directly from a quaternion’s x
, y
and z
elements.
fn from(v: Quaternion<T>) -> Self
[src]
fn from(v: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for SimdVec4<T>
[src]
impl<T> From<Quaternion<T>> for SimdVec4<T>
[src]A Vec4
can be created directly from a quaternion’s x
, y
, z
and w
elements.
fn from(v: Quaternion<T>) -> Self
[src]
fn from(v: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Quaternion<T>> for SimdVec3<T>
[src]
impl<T> From<Quaternion<T>> for SimdVec3<T>
[src]A Vec3
can be created directly from a quaternion’s x
, y
and z
elements.
fn from(v: Quaternion<T>) -> Self
[src]
fn from(v: Quaternion<T>) -> Self
[src]Performs the conversion.
impl<T> From<Vec4<T>> for Quaternion<T>
[src]
impl<T> From<Vec4<T>> for Quaternion<T>
[src]A quaternion can be created directly from a Vec4
’s x
, y
, z
and w
elements.
You are responsible for ensuring that the resulting quaternion is normalized.
impl<T> From<Vec4<T>> for Quaternion<T>
[src]
impl<T> From<Vec4<T>> for Quaternion<T>
[src]A quaternion can be created directly from a Vec4
’s x
, y
, z
and w
elements.
You are responsible for ensuring that the resulting quaternion is normalized.
impl<T: Hash> Hash for Quaternion<T>
[src]
impl<T: Hash> Hash for Quaternion<T>
[src]impl<T, Factor> Lerp<Factor> for Quaternion<T> where
T: Lerp<Factor, Output = T> + Add<T, Output = T> + Real,
Factor: Copy,
[src]
impl<T, Factor> Lerp<Factor> for Quaternion<T> where
T: Lerp<Factor, Output = T> + Add<T, Output = T> + Real,
Factor: Copy,
[src]The Lerp
implementation for quaternion is the “Normalized LERP”.
type Output = Self
type Output = Self
The resulting type after performing the LERP operation.
fn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Self
[src]
fn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Self
[src]Returns the linear interpolation of from
to to
with factor
unconstrained,
using a possibly slower but more precise operation. Read more
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Self
[src]
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Self
[src]Returns the linear interpolation of from
to to
with factor
unconstrained,
using the supposedly fastest but less precise implementation. Read more
impl<'a, T, Factor> Lerp<Factor> for &'a Quaternion<T> where
T: Lerp<Factor, Output = T> + Add<T, Output = T> + Real,
Factor: Copy,
[src]
impl<'a, T, Factor> Lerp<Factor> for &'a Quaternion<T> where
T: Lerp<Factor, Output = T> + Add<T, Output = T> + Real,
Factor: Copy,
[src]The Lerp
implementation for quaternion is the “Normalized LERP”.
type Output = Quaternion<T>
type Output = Quaternion<T>
The resulting type after performing the LERP operation.
fn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]
fn lerp_unclamped_precise(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]Returns the linear interpolation of from
to to
with factor
unconstrained,
using a possibly slower but more precise operation. Read more
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]
fn lerp_unclamped(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]Returns the linear interpolation of from
to to
with factor
unconstrained,
using the supposedly fastest but less precise implementation. Read more
impl<T> Mul<Quaternion<T>> for Quaternion<T> where
T: Copy + Mul<Output = T> + Sub<Output = T> + Zero + Add<T, Output = T>,
[src]
impl<T> Mul<Quaternion<T>> for Quaternion<T> where
T: Copy + Mul<Output = T> + Sub<Output = T> + Zero + Add<T, Output = T>,
[src]The Mul
implementation for quaternions is concatenation, a.k.a Grassman product.
use std::f32::consts::PI; let v = Vec4::unit_x(); let p = Quaternion::rotation_y(PI/2.); let q = Quaternion::rotation_z(PI/2.); assert_relative_eq!((p*q)*v, p*(q*v)); assert_relative_eq!(p*q*v, Vec4::unit_y()); assert_relative_eq!(q*p*v, -Vec4::unit_z());
impl<T> Mul<T> for Quaternion<T> where
T: Mul<Output = T> + Copy,
[src]
impl<T> Mul<T> for Quaternion<T> where
T: Mul<Output = T> + Copy,
[src]impl<T: Real + Add<T, Output = T>> Mul<Vec3<T>> for Quaternion<T>
[src]
impl<T: Real + Add<T, Output = T>> Mul<Vec3<T>> for Quaternion<T>
[src]3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized.
impl<T: Real + Add<T, Output = T>> Mul<Vec3<T>> for Quaternion<T>
[src]
impl<T: Real + Add<T, Output = T>> Mul<Vec3<T>> for Quaternion<T>
[src]3D vectors can be rotated by being premultiplied by a quaternion, assuming the quaternion is normalized.
impl<T: Real + Add<T, Output = T>> Mul<Vec4<T>> for Quaternion<T>
[src]
impl<T: Real + Add<T, Output = T>> Mul<Vec4<T>> for Quaternion<T>
[src]3D vectors can be rotated by being premultiplied by a quaternion, assuming the
quaternion is normalized.
On Vec4
s, the w
element is preserved, so you can safely rotate
points and directions.
use std::f32::consts::PI; let v = Vec4::unit_x(); let q = Quaternion::<f32>::identity(); assert_relative_eq!(q * v, v); let q = Quaternion::rotation_z(PI); assert_relative_eq!(q * v, -v); let q = Quaternion::rotation_z(PI * 0.5); assert_relative_eq!(q * v, Vec4::unit_y()); let q = Quaternion::rotation_z(PI * 1.5); assert_relative_eq!(q * v, -Vec4::unit_y()); let angles = 32; for i in 0..angles { let theta = PI * 2. * (i as f32) / (angles as f32); // See what rotating unit vectors do for most angles between 0 and 2*PI. // It's helpful to picture this as a right-handed coordinate system. let v = Vec4::unit_y(); let q = Quaternion::rotation_x(theta); assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.)); let v = Vec4::unit_z(); let q = Quaternion::rotation_y(theta); assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.)); let v = Vec4::unit_x(); let q = Quaternion::rotation_z(theta); assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.)); }
impl<T: Real + Add<T, Output = T>> Mul<Vec4<T>> for Quaternion<T>
[src]
impl<T: Real + Add<T, Output = T>> Mul<Vec4<T>> for Quaternion<T>
[src]3D vectors can be rotated by being premultiplied by a quaternion, assuming the
quaternion is normalized.
On Vec4
s, the w
element is preserved, so you can safely rotate
points and directions.
use std::f32::consts::PI; let v = Vec4::unit_x(); let q = Quaternion::<f32>::identity(); assert_relative_eq!(q * v, v); let q = Quaternion::rotation_z(PI); assert_relative_eq!(q * v, -v); let q = Quaternion::rotation_z(PI * 0.5); assert_relative_eq!(q * v, Vec4::unit_y()); let q = Quaternion::rotation_z(PI * 1.5); assert_relative_eq!(q * v, -Vec4::unit_y()); let angles = 32; for i in 0..angles { let theta = PI * 2. * (i as f32) / (angles as f32); // See what rotating unit vectors do for most angles between 0 and 2*PI. // It's helpful to picture this as a right-handed coordinate system. let v = Vec4::unit_y(); let q = Quaternion::rotation_x(theta); assert_relative_eq!(q * v, Vec4::new(0., theta.cos(), theta.sin(), 0.)); let v = Vec4::unit_z(); let q = Quaternion::rotation_y(theta); assert_relative_eq!(q * v, Vec4::new(theta.sin(), 0., theta.cos(), 0.)); let v = Vec4::unit_x(); let q = Quaternion::rotation_z(theta); assert_relative_eq!(q * v, Vec4::new(theta.cos(), theta.sin(), 0., 0.)); }
impl<T> Neg for Quaternion<T> where
T: Neg<Output = T>,
[src]
impl<T> Neg for Quaternion<T> where
T: Neg<Output = T>,
[src]impl<T: PartialEq> PartialEq<Quaternion<T>> for Quaternion<T>
[src]
impl<T: PartialEq> PartialEq<Quaternion<T>> for Quaternion<T>
[src]fn eq(&self, other: &Quaternion<T>) -> bool
[src]
fn eq(&self, other: &Quaternion<T>) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &Quaternion<T>) -> bool
[src]
fn ne(&self, other: &Quaternion<T>) -> bool
[src]This method tests for !=
.
impl<T: RelativeEq> RelativeEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]
impl<T: RelativeEq> RelativeEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]fn default_max_relative() -> T::Epsilon
[src]
fn default_max_relative() -> T::Epsilon
[src]The default relative tolerance for testing values that are far-apart. Read more
fn relative_eq(
&self,
other: &Self,
epsilon: T::Epsilon,
max_relative: T::Epsilon
) -> bool
[src]
fn relative_eq(
&self,
other: &Self,
epsilon: T::Epsilon,
max_relative: T::Epsilon
) -> bool
[src]A test for equality that uses a relative comparison if the values are far apart.
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
[src]
fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
[src]The inverse of RelativeEq::relative_eq
.
impl<T> Serialize for Quaternion<T> where
T: Serialize,
[src]
impl<T> Serialize for Quaternion<T> where
T: Serialize,
[src]impl<T, Factor> Slerp<Factor> for Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
Factor: Into<T>,
[src]
impl<T, Factor> Slerp<Factor> for Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
Factor: Into<T>,
[src]type Output = Self
type Output = Self
The resulting type after performing the SLERP operation.
fn slerp_unclamped(from: Self, to: Self, factor: Factor) -> Self
[src]
fn slerp_unclamped(from: Self, to: Self, factor: Factor) -> Self
[src]Performs spherical linear interpolation without implictly constraining factor
to
be between 0 and 1. Read more
impl<'a, T, Factor> Slerp<Factor> for &'a Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
Factor: Into<T>,
[src]
impl<'a, T, Factor> Slerp<Factor> for &'a Quaternion<T> where
T: Lerp<T, Output = T> + Add<T, Output = T> + Real,
Factor: Into<T>,
[src]type Output = Quaternion<T>
type Output = Quaternion<T>
The resulting type after performing the SLERP operation.
fn slerp_unclamped(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]
fn slerp_unclamped(from: Self, to: Self, factor: Factor) -> Quaternion<T>
[src]Performs spherical linear interpolation without implictly constraining factor
to
be between 0 and 1. Read more
impl<T> Sub<Quaternion<T>> for Quaternion<T> where
T: Sub<Output = T>,
[src]
impl<T> Sub<Quaternion<T>> for Quaternion<T> where
T: Sub<Output = T>,
[src]impl<T: UlpsEq> UlpsEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]
impl<T: UlpsEq> UlpsEq<Quaternion<T>> for Quaternion<T> where
T::Epsilon: Copy,
[src]impl<T: Copy> Copy for Quaternion<T>
[src]
impl<T: Eq> Eq for Quaternion<T>
[src]
impl<T> StructuralEq for Quaternion<T>
[src]
impl<T> StructuralPartialEq for Quaternion<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Quaternion<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Quaternion<T> where
T: Send,
T: Send,
impl<T> Sync for Quaternion<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Quaternion<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Quaternion<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,