Struct nalgebra::base::Unit

source ·
#[repr(transparent)]
pub struct Unit<T> { /* private fields */ }
Expand description

A wrapper that ensures the underlying algebraic entity has a unit norm.

Use .as_ref() or .into_inner() to obtain the underlying value by-reference or by-move.

Implementations§

Computes the spherical linear interpolation between two unit vectors.

Computes the spherical linear interpolation between two unit vectors.

Returns None if the two vectors are almost collinear and with opposite direction (in this case, there is an infinity of possible results).

Normalize the given value and return it wrapped on a Unit structure.

Attempts to normalize the given value and return it wrapped on a Unit structure.

Returns None if the norm was smaller or equal to min_norm.

Normalize the given value and return it wrapped on a Unit structure and its norm.

Normalize the given value and return it wrapped on a Unit structure and its norm.

Returns None if the norm was smaller or equal to min_norm.

Normalizes this value again. This is useful when repeated computations might cause a drift in the norm because of float inaccuracies.

Returns the norm before re-normalization (should be close to 1.0).

Wraps the given value, assuming it is already normalized.

Wraps the given reference, assuming it is already normalized.

Retrieves the underlying value.

👎Deprecated: use .into_inner() instead

Retrieves the underlying value. Deprecated: use Unit::into_inner instead.

Returns a mutable reference to the underlying value. This is _unchecked because modifying the underlying value in such a way that it no longer has unit length may lead to unexpected results.

👎Deprecated: This method is unnecessary and will be removed in a future release. Use .clone() instead.

Moves this unit quaternion into one that owns its data.

👎Deprecated: This method is unnecessary and will be removed in a future release. Use .clone() instead.

Clones this unit quaternion into one that owns its data.

The rotation angle in [0; pi] of this unit quaternion.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let rot = UnitQuaternion::from_axis_angle(&axis, 1.78);
assert_eq!(rot.angle(), 1.78);

The underlying quaternion.

Same as self.as_ref().

Example
let axis = UnitQuaternion::identity();
assert_eq!(*axis.quaternion(), Quaternion::new(1.0, 0.0, 0.0, 0.0));

Compute the conjugate of this unit quaternion.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let rot = UnitQuaternion::from_axis_angle(&axis, 1.78);
let conj = rot.conjugate();
assert_eq!(conj, UnitQuaternion::from_axis_angle(&-axis, 1.78));

Inverts this quaternion if it is not zero.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let rot = UnitQuaternion::from_axis_angle(&axis, 1.78);
let inv = rot.inverse();
assert_eq!(rot * inv, UnitQuaternion::identity());
assert_eq!(inv * rot, UnitQuaternion::identity());

The rotation angle needed to make self and other coincide.

Example
let rot1 = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), 1.0);
let rot2 = UnitQuaternion::from_axis_angle(&Vector3::x_axis(), 0.1);
assert_relative_eq!(rot1.angle_to(&rot2), 1.0045657, epsilon = 1.0e-6);

The unit quaternion needed to make self and other coincide.

The result is such that: self.rotation_to(other) * self == other.

Example
let rot1 = UnitQuaternion::from_axis_angle(&Vector3::y_axis(), 1.0);
let rot2 = UnitQuaternion::from_axis_angle(&Vector3::x_axis(), 0.1);
let rot_to = rot1.rotation_to(&rot2);
assert_relative_eq!(rot_to * rot1, rot2, epsilon = 1.0e-6);

Linear interpolation between two unit quaternions.

The result is not normalized.

Example
let q1 = UnitQuaternion::new_normalize(Quaternion::new(1.0, 0.0, 0.0, 0.0));
let q2 = UnitQuaternion::new_normalize(Quaternion::new(0.0, 1.0, 0.0, 0.0));
assert_eq!(q1.lerp(&q2, 0.1), Quaternion::new(0.9, 0.1, 0.0, 0.0));

Normalized linear interpolation between two unit quaternions.

This is the same as self.lerp except that the result is normalized.

Example
let q1 = UnitQuaternion::new_normalize(Quaternion::new(1.0, 0.0, 0.0, 0.0));
let q2 = UnitQuaternion::new_normalize(Quaternion::new(0.0, 1.0, 0.0, 0.0));
assert_eq!(q1.nlerp(&q2, 0.1), UnitQuaternion::new_normalize(Quaternion::new(0.9, 0.1, 0.0, 0.0)));

Spherical linear interpolation between two unit quaternions.

Panics if the angle between both quaternion is 180 degrees (in which case the interpolation is not well-defined). Use .try_slerp instead to avoid the panic.

Computes the spherical linear interpolation between two unit quaternions or returns None if both quaternions are approximately 180 degrees apart (in which case the interpolation is not well-defined).

Arguments
  • self: the first quaternion to interpolate from.
  • other: the second quaternion to interpolate toward.
  • t: the interpolation parameter. Should be between 0 and 1.
  • epsilon: the value below which the sinus of the angle separating both quaternion must be to return None.

Compute the conjugate of this unit quaternion in-place.

Inverts this quaternion if it is not zero.

Example
let axisangle = Vector3::new(0.1, 0.2, 0.3);
let mut rot = UnitQuaternion::new(axisangle);
rot.inverse_mut();
assert_relative_eq!(rot * UnitQuaternion::new(axisangle), UnitQuaternion::identity());
assert_relative_eq!(UnitQuaternion::new(axisangle) * rot, UnitQuaternion::identity());

The rotation axis of this unit quaternion or None if the rotation is zero.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let angle = 1.2;
let rot = UnitQuaternion::from_axis_angle(&axis, angle);
assert_eq!(rot.axis(), Some(axis));

// Case with a zero angle.
let rot = UnitQuaternion::from_axis_angle(&axis, 0.0);
assert!(rot.axis().is_none());

The rotation axis of this unit quaternion multiplied by the rotation angle.

Example
let axisangle = Vector3::new(0.1, 0.2, 0.3);
let rot = UnitQuaternion::new(axisangle);
assert_relative_eq!(rot.scaled_axis(), axisangle, epsilon = 1.0e-6);

The rotation axis and angle in ]0, pi] of this unit quaternion.

Returns None if the angle is zero.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let angle = 1.2;
let rot = UnitQuaternion::from_axis_angle(&axis, angle);
assert_eq!(rot.axis_angle(), Some((axis, angle)));

// Case with a zero angle.
let rot = UnitQuaternion::from_axis_angle(&axis, 0.0);
assert!(rot.axis_angle().is_none());

Compute the exponential of a quaternion.

Note that this function yields a Quaternion<N> because it looses the unit property.

Compute the natural logarithm of a quaternion.

Note that this function yields a Quaternion<N> because it looses the unit property. The vector part of the return value corresponds to the axis-angle representation (divided by 2.0) of this unit quaternion.

Example
let axisangle = Vector3::new(0.1, 0.2, 0.3);
let q = UnitQuaternion::new(axisangle);
assert_relative_eq!(q.ln().vector().into_owned(), axisangle, epsilon = 1.0e-6);

Raise the quaternion to a given floating power.

This returns the unit quaternion that identifies a rotation with axis self.axis() and angle self.angle() × n.

Example
let axis = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let angle = 1.2;
let rot = UnitQuaternion::from_axis_angle(&axis, angle);
let pow = rot.powf(2.0);
assert_relative_eq!(pow.axis().unwrap(), axis, epsilon = 1.0e-6);
assert_eq!(pow.angle(), 2.4);

Builds a rotation matrix from this unit quaternion.

Example
let q = UnitQuaternion::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6);
let rot = q.to_rotation_matrix();
let expected = Matrix3::new(0.8660254, -0.5,      0.0,
                            0.5,       0.8660254, 0.0,
                            0.0,       0.0,       1.0);

assert_relative_eq!(*rot.matrix(), expected, epsilon = 1.0e-6);
👎Deprecated: This is renamed to use .euler_angles().

Converts this unit quaternion into its equivalent Euler angles.

The angles are produced in the form (roll, pitch, yaw).

Retrieves the euler angles corresponding to this unit quaternion.

The angles are produced in the form (roll, pitch, yaw).

Example
let rot = UnitQuaternion::from_euler_angles(0.1, 0.2, 0.3);
let euler = rot.euler_angles();
assert_relative_eq!(euler.0, 0.1, epsilon = 1.0e-6);
assert_relative_eq!(euler.1, 0.2, epsilon = 1.0e-6);
assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6);

Converts this unit quaternion into its equivalent homogeneous transformation matrix.

Example
let rot = UnitQuaternion::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6);
let expected = Matrix4::new(0.8660254, -0.5,      0.0, 0.0,
                            0.5,       0.8660254, 0.0, 0.0,
                            0.0,       0.0,       1.0, 0.0,
                            0.0,       0.0,       0.0, 1.0);

assert_relative_eq!(rot.to_homogeneous(), expected, epsilon = 1.0e-6);

The rotation identity.

Example
let q = UnitQuaternion::identity();
let q2 = UnitQuaternion::new(Vector3::new(1.0, 2.0, 3.0));
let v = Vector3::new_random();
let p = Point3::from(v);

assert_eq!(q * q2, q2);
assert_eq!(q2 * q, q2);
assert_eq!(q * v, v);
assert_eq!(q * p, p);

Creates a new quaternion from a unit vector (the rotation axis) and an angle (the rotation angle).

Example
let axis = Vector3::y_axis();
let angle = f32::consts::FRAC_PI_2;
// Point and vector being transformed in the tests.
let pt = Point3::new(4.0, 5.0, 6.0);
let vec = Vector3::new(4.0, 5.0, 6.0);
let q = UnitQuaternion::from_axis_angle(&axis, angle);

assert_eq!(q.axis().unwrap(), axis);
assert_eq!(q.angle(), angle);
assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);

// A zero vector yields an identity.
assert_eq!(UnitQuaternion::from_scaled_axis(Vector3::<f32>::zeros()), UnitQuaternion::identity());

Creates a new unit quaternion from a quaternion.

The input quaternion will be normalized.

Creates a new unit quaternion from Euler angles.

The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw.

Example
let rot = UnitQuaternion::from_euler_angles(0.1, 0.2, 0.3);
let euler = rot.euler_angles();
assert_relative_eq!(euler.0, 0.1, epsilon = 1.0e-6);
assert_relative_eq!(euler.1, 0.2, epsilon = 1.0e-6);
assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6);

Builds an unit quaternion from a rotation matrix.

Example
let axis = Vector3::y_axis();
let angle = 0.1;
let rot = Rotation3::from_axis_angle(&axis, angle);
let q = UnitQuaternion::from_rotation_matrix(&rot);
assert_relative_eq!(q.to_rotation_matrix(), rot, epsilon = 1.0e-6);
assert_relative_eq!(q.axis().unwrap(), rot.axis().unwrap(), epsilon = 1.0e-6);
assert_relative_eq!(q.angle(), rot.angle(), epsilon = 1.0e-6);

The unit quaternion needed to make a and b be collinear and point toward the same direction.

Example
let a = Vector3::new(1.0, 2.0, 3.0);
let b = Vector3::new(3.0, 1.0, 2.0);
let q = UnitQuaternion::rotation_between(&a, &b).unwrap();
assert_relative_eq!(q * a, b);
assert_relative_eq!(q.inverse() * b, a);

The smallest rotation needed to make a and b collinear and point toward the same direction, raised to the power s.

Example
let a = Vector3::new(1.0, 2.0, 3.0);
let b = Vector3::new(3.0, 1.0, 2.0);
let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).unwrap();
let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).unwrap();
assert_relative_eq!(q2 * q2 * q2 * q2 * q2 * a, b, epsilon = 1.0e-6);
assert_relative_eq!(q5 * q5 * a, b, epsilon = 1.0e-6);

The unit quaternion needed to make a and b be collinear and point toward the same direction.

Example
let a = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let b = Unit::new_normalize(Vector3::new(3.0, 1.0, 2.0));
let q = UnitQuaternion::rotation_between(&a, &b).unwrap();
assert_relative_eq!(q * a, b);
assert_relative_eq!(q.inverse() * b, a);

The smallest rotation needed to make a and b collinear and point toward the same direction, raised to the power s.

Example
let a = Unit::new_normalize(Vector3::new(1.0, 2.0, 3.0));
let b = Unit::new_normalize(Vector3::new(3.0, 1.0, 2.0));
let q2 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.2).unwrap();
let q5 = UnitQuaternion::scaled_rotation_between(&a, &b, 0.5).unwrap();
assert_relative_eq!(q2 * q2 * q2 * q2 * q2 * a, b, epsilon = 1.0e-6);
assert_relative_eq!(q5 * q5 * a, b, epsilon = 1.0e-6);

Creates an unit quaternion that corresponds to the local frame of an observer standing at the origin and looking toward dir.

It maps the z axis to the direction dir.

Arguments
  • dir - The look direction. It does not need to be normalized.
  • up - The vertical direction. It does not need to be normalized. The only requirement of this parameter is to not be collinear to dir. Non-collinearity is not checked.
Example
let dir = Vector3::new(1.0, 2.0, 3.0);
let up = Vector3::y();

let q = UnitQuaternion::new_observer_frame(&dir, &up);
assert_relative_eq!(q * Vector3::z(), dir.normalize());

Builds a right-handed look-at view matrix without translation.

It maps the view direction dir to the negative z axis. This conforms to the common notion of right handed look-at matrix from the computer graphics community.

Arguments
  • dir − The view direction. It does not need to be normalized.
  • up - A vector approximately aligned with required the vertical axis. It does not need to be normalized. The only requirement of this parameter is to not be collinear to dir.
Example
let dir = Vector3::new(1.0, 2.0, 3.0);
let up = Vector3::y();

let q = UnitQuaternion::look_at_rh(&dir, &up);
assert_relative_eq!(q * dir.normalize(), -Vector3::z());

Builds a left-handed look-at view matrix without translation.

It maps the view direction dir to the positive z axis. This conforms to the common notion of left handed look-at matrix from the computer graphics community.

Arguments
  • dir − The view direction. It does not need to be normalized.
  • up - A vector approximately aligned with required the vertical axis. The only requirement of this parameter is to not be collinear to dir.
Example
let dir = Vector3::new(1.0, 2.0, 3.0);
let up = Vector3::y();

let q = UnitQuaternion::look_at_lh(&dir, &up);
assert_relative_eq!(q * dir.normalize(), Vector3::z());

Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle.

If axisangle has a magnitude smaller than N::default_epsilon(), this returns the identity rotation.

Example
let axisangle = Vector3::y() * f32::consts::FRAC_PI_2;
// Point and vector being transformed in the tests.
let pt = Point3::new(4.0, 5.0, 6.0);
let vec = Vector3::new(4.0, 5.0, 6.0);
let q = UnitQuaternion::new(axisangle);

assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);

// A zero vector yields an identity.
assert_eq!(UnitQuaternion::new(Vector3::<f32>::zeros()), UnitQuaternion::identity());

Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle.

If axisangle has a magnitude smaller than eps, this returns the identity rotation.

Example
let axisangle = Vector3::y() * f32::consts::FRAC_PI_2;
// Point and vector being transformed in the tests.
let pt = Point3::new(4.0, 5.0, 6.0);
let vec = Vector3::new(4.0, 5.0, 6.0);
let q = UnitQuaternion::new_eps(axisangle, 1.0e-6);

assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);

// An almost zero vector yields an identity.
assert_eq!(UnitQuaternion::new_eps(Vector3::new(1.0e-8, 1.0e-9, 1.0e-7), 1.0e-6), UnitQuaternion::identity());

Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle.

If axisangle has a magnitude smaller than N::default_epsilon(), this returns the identity rotation. Same as Self::new(axisangle).

Example
let axisangle = Vector3::y() * f32::consts::FRAC_PI_2;
// Point and vector being transformed in the tests.
let pt = Point3::new(4.0, 5.0, 6.0);
let vec = Vector3::new(4.0, 5.0, 6.0);
let q = UnitQuaternion::from_scaled_axis(axisangle);

assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);

// A zero vector yields an identity.
assert_eq!(UnitQuaternion::from_scaled_axis(Vector3::<f32>::zeros()), UnitQuaternion::identity());

Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle.

If axisangle has a magnitude smaller than eps, this returns the identity rotation. Same as Self::new_eps(axisangle, eps).

Example
let axisangle = Vector3::y() * f32::consts::FRAC_PI_2;
// Point and vector being transformed in the tests.
let pt = Point3::new(4.0, 5.0, 6.0);
let vec = Vector3::new(4.0, 5.0, 6.0);
let q = UnitQuaternion::from_scaled_axis_eps(axisangle, 1.0e-6);

assert_relative_eq!(q * pt, Point3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);
assert_relative_eq!(q * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6);

// An almost zero vector yields an identity.
assert_eq!(UnitQuaternion::from_scaled_axis_eps(Vector3::new(1.0e-8, 1.0e-9, 1.0e-7), 1.0e-6), UnitQuaternion::identity());

The rotation angle in ]-pi; pi] of this unit complex number.

Example
let rot = UnitComplex::new(1.78);
assert_eq!(rot.angle(), 1.78);

The sine of the rotation angle.

Example
let angle = 1.78f32;
let rot = UnitComplex::new(angle);
assert_eq!(rot.sin_angle(), angle.sin());

The cosine of the rotation angle.

Example
let angle = 1.78f32;
let rot = UnitComplex::new(angle);
assert_eq!(rot.cos_angle(),angle.cos());

The rotation angle returned as a 1-dimensional vector.

This is generally used in the context of generic programming. Using the .angle() method instead is more common.

The rotation axis and angle in ]0, pi] of this complex number.

This is generally used in the context of generic programming. Using the .angle() method instead is more common. Returns None if the angle is zero.

The underlying complex number.

Same as self.as_ref().

Example
let angle = 1.78f32;
let rot = UnitComplex::new(angle);
assert_eq!(*rot.complex(), Complex::new(angle.cos(), angle.sin()));

Compute the conjugate of this unit complex number.

Example
let rot = UnitComplex::new(1.78);
let conj = rot.conjugate();
assert_eq!(rot.complex().im, -conj.complex().im);
assert_eq!(rot.complex().re, conj.complex().re);

Inverts this complex number if it is not zero.

Example
let rot = UnitComplex::new(1.2);
let inv = rot.inverse();
assert_relative_eq!(rot * inv, UnitComplex::identity(), epsilon = 1.0e-6);
assert_relative_eq!(inv * rot, UnitComplex::identity(), epsilon = 1.0e-6);

The rotation angle needed to make self and other coincide.

Example
let rot1 = UnitComplex::new(0.1);
let rot2 = UnitComplex::new(1.7);
assert_relative_eq!(rot1.angle_to(&rot2), 1.6);

The unit complex number needed to make self and other coincide.

The result is such that: self.rotation_to(other) * self == other.

Example
let rot1 = UnitComplex::new(0.1);
let rot2 = UnitComplex::new(1.7);
let rot_to = rot1.rotation_to(&rot2);

assert_relative_eq!(rot_to * rot1, rot2);
assert_relative_eq!(rot_to.inverse() * rot2, rot1);

Compute in-place the conjugate of this unit complex number.

Example
let angle = 1.7;
let rot = UnitComplex::new(angle);
let mut conj = UnitComplex::new(angle);
conj.conjugate_mut();
assert_eq!(rot.complex().im, -conj.complex().im);
assert_eq!(rot.complex().re, conj.complex().re);

Inverts in-place this unit complex number.

Example
let angle = 1.7;
let mut rot = UnitComplex::new(angle);
rot.inverse_mut();
assert_relative_eq!(rot * UnitComplex::new(angle), UnitComplex::identity());
assert_relative_eq!(UnitComplex::new(angle) * rot, UnitComplex::identity());

Raise this unit complex number to a given floating power.

This returns the unit complex number that identifies a rotation angle equal to self.angle() × n.

Example
let rot = UnitComplex::new(0.78);
let pow = rot.powf(2.0);
assert_eq!(pow.angle(), 2.0 * 0.78);

Builds the rotation matrix corresponding to this unit complex number.

Example
let rot = UnitComplex::new(f32::consts::FRAC_PI_6);
let expected = Rotation2::new(f32::consts::FRAC_PI_6);
assert_eq!(rot.to_rotation_matrix(), expected);

Converts this unit complex number into its equivalent homogeneous transformation matrix.

Example
let rot = UnitComplex::new(f32::consts::FRAC_PI_6);
let expected = Matrix3::new(0.8660254, -0.5,      0.0,
                            0.5,       0.8660254, 0.0,
                            0.0,       0.0,       1.0);
assert_eq!(rot.to_homogeneous(), expected);

The unit complex number multiplicative identity.

Example
let rot1 = UnitComplex::identity();
let rot2 = UnitComplex::new(1.7);

assert_eq!(rot1 * rot2, rot2);
assert_eq!(rot2 * rot1, rot2);

Builds the unit complex number corresponding to the rotation with the given angle.

Example
let rot = UnitComplex::new(f32::consts::FRAC_PI_2);

assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0));

Builds the unit complex number corresponding to the rotation with the angle.

Same as Self::new(angle).

Example
let rot = UnitComplex::from_angle(f32::consts::FRAC_PI_2);

assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0));

Builds the unit complex number from the sinus and cosinus of the rotation angle.

The input values are not checked to actually be cosines and sine of the same value. Is is generally preferable to use the ::new(angle) constructor instead.

Example
let angle = f32::consts::FRAC_PI_2;
let rot = UnitComplex::from_cos_sin_unchecked(angle.cos(), angle.sin());

assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0));

Builds a unit complex rotation from an angle in radian wrapped in a 1-dimensional vector.

This is generally used in the context of generic programming. Using the ::new(angle) method instead is more common.

Creates a new unit complex number from a complex number.

The input complex number will be normalized.

Creates a new unit complex number from a complex number.

The input complex number will be normalized. Returns the norm of the complex number as well.

Builds the unit complex number from the corresponding 2D rotation matrix.

Example
let rot = Rotation2::new(1.7);
let complex = UnitComplex::from_rotation_matrix(&rot);
assert_eq!(complex, UnitComplex::new(1.7));

The unit complex needed to make a and b be collinear and point toward the same direction.

Example
let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(2.0, 1.0);
let rot = UnitComplex::rotation_between(&a, &b);
assert_relative_eq!(rot * a, b);
assert_relative_eq!(rot.inverse() * b, a);

The smallest rotation needed to make a and b collinear and point toward the same direction, raised to the power s.

Example
let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(2.0, 1.0);
let rot2 = UnitComplex::scaled_rotation_between(&a, &b, 0.2);
let rot5 = UnitComplex::scaled_rotation_between(&a, &b, 0.5);
assert_relative_eq!(rot2 * rot2 * rot2 * rot2 * rot2 * a, b, epsilon = 1.0e-6);
assert_relative_eq!(rot5 * rot5 * a, b, epsilon = 1.0e-6);

The unit complex needed to make a and b be collinear and point toward the same direction.

Example
let a = Unit::new_normalize(Vector2::new(1.0, 2.0));
let b = Unit::new_normalize(Vector2::new(2.0, 1.0));
let rot = UnitComplex::rotation_between_axis(&a, &b);
assert_relative_eq!(rot * a, b);
assert_relative_eq!(rot.inverse() * b, a);

The smallest rotation needed to make a and b collinear and point toward the same direction, raised to the power s.

Example
let a = Unit::new_normalize(Vector2::new(1.0, 2.0));
let b = Unit::new_normalize(Vector2::new(2.0, 1.0));
let rot2 = UnitComplex::scaled_rotation_between_axis(&a, &b, 0.2);
let rot5 = UnitComplex::scaled_rotation_between_axis(&a, &b, 0.5);
assert_relative_eq!(rot2 * rot2 * rot2 * rot2 * rot2 * a, b, epsilon = 1.0e-6);
assert_relative_eq!(rot5 * rot5 * a, b, epsilon = 1.0e-6);

Performs the multiplication rhs = self * rhs in-place.

Performs the multiplication lhs = lhs * self in-place.

Trait Implementations§

Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
The inverse of ApproxEq::abs_diff_eq.
Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
The inverse of ApproxEq::abs_diff_eq.
Used for specifying relative comparisons.
The default tolerance to use when testing values that are close together. Read more
A test for equality that uses the absolute difference to compute the approximate equality of two numbers. Read more
The inverse of ApproxEq::abs_diff_eq.
Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.

Generate a uniformly distributed random UnitComplex.

Create an iterator that generates random values of T, using rng as the source of randomness. Read more

Generate a uniformly distributed random unit vector.

Create an iterator that generates random values of T, using rng as the source of randomness. Read more

Generate a uniformly distributed random rotation quaternion.

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
The resulting type after applying the / operator.
Performs the / operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Performs the /= operation. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
Performs the *= operation. Read more
The resulting type after applying the - operator.
Performs the unary - operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
The default relative tolerance for testing values that are far-apart. Read more
A test for equality that uses a relative comparison if the values are far apart.
The inverse of ApproxEq::relative_eq.
The default relative tolerance for testing values that are far-apart. Read more
A test for equality that uses a relative comparison if the values are far apart.
The inverse of ApproxEq::relative_eq.
The default relative tolerance for testing values that are far-apart. Read more
A test for equality that uses a relative comparison if the values are far apart.
The inverse of ApproxEq::relative_eq.
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
The inclusion map: converts self to the equivalent element of its superset.
Checks if element is actually part of the subset Self (and can be converted to it).
Use with care! Same as self.to_superset but without any property checks. Always succeeds.
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
The default ULPs to tolerate when testing values that are far-apart. Read more
A test for equality that uses units in the last place (ULP) if the values are far apart.
The inverse of ApproxEq::ulps_eq.
The default ULPs to tolerate when testing values that are far-apart. Read more
A test for equality that uses units in the last place (ULP) if the values are far apart.
The inverse of ApproxEq::ulps_eq.
The default ULPs to tolerate when testing values that are far-apart. Read more
A test for equality that uses units in the last place (ULP) if the values are far apart.
The inverse of ApproxEq::ulps_eq.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

👎Deprecated since 0.5.0: replaced by distributions::Standard
Generates a random instance of this type using the specified source of randomness. Read more
Should always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Checks if self is actually part of its subset T (and can be converted to it).
Use with care! Same as self.to_subset but without any property checks. Always succeeds.
The inclusion map: converts self to the equivalent element of its superset.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.