#[repr(C)]pub struct DRot2 {
pub re: f64,
pub im: f64,
}Expand description
A 2D rotation represented as a unit complex number (f64 precision).
The rotation is stored as re + im * i where re = cos(angle) and im = sin(angle).
Fields§
§re: f64Real part (cosine of the angle).
im: f64Imaginary part (sine of the angle).
Implementations§
Source§impl DRot2
impl DRot2
Sourcepub const fn from_cos_sin_unchecked(re: f64, im: f64) -> Self
pub const fn from_cos_sin_unchecked(re: f64, im: f64) -> Self
Creates a new unit complex from cosine and sine values.
The caller must ensure that re*re + im*im = 1.
Sourcepub fn from_matrix_unchecked(mat: DMat2) -> Self
pub fn from_matrix_unchecked(mat: DMat2) -> Self
Creates a rotation from a rotation matrix (without normalization).
Sourcepub fn from_angle(angle: f64) -> Self
pub fn from_angle(angle: f64) -> Self
Creates a rotation from an angle in radians.
Sourcepub fn length(&self) -> f64
pub fn length(&self) -> f64
Computes the length (magnitude) of self.
For a valid unit rotation, this should always be 1.0.
Sourcepub fn length_squared(&self) -> f64
pub fn length_squared(&self) -> f64
Computes the squared length of self.
This is faster than length() as it avoids a square root.
For a valid unit rotation, this should always be 1.0.
Sourcepub fn length_recip(&self) -> f64
pub fn length_recip(&self) -> f64
Computes 1.0 / length().
Sourcepub fn normalize(&self) -> Self
pub fn normalize(&self) -> Self
Returns self normalized to length 1.0.
For valid unit rotations this should be a no-op.
Sourcepub fn is_normalized(&self) -> bool
pub fn is_normalized(&self) -> bool
Returns whether self is of length 1.0 or not.
Uses a precision threshold of approximately 1e-4.
Sourcepub fn transform_vector(&self, v: DVec2) -> DVec2
pub fn transform_vector(&self, v: DVec2) -> DVec2
Rotates a 2D vector by this rotation.
Sourcepub fn inverse_transform_vector(&self, v: DVec2) -> DVec2
pub fn inverse_transform_vector(&self, v: DVec2) -> DVec2
Transforms a 2D vector by the inverse of this rotation.
Sourcepub fn from_mat(mat: DMat2) -> Self
pub fn from_mat(mat: DMat2) -> Self
Creates a rotation from a 2x2 rotation matrix.
The matrix should be a valid rotation matrix (orthogonal with determinant 1).
Sourcepub fn from_mat_unchecked(mat: DMat2) -> Self
pub fn from_mat_unchecked(mat: DMat2) -> Self
Creates a rotation from a 2x2 matrix without normalization.
Alias for from_matrix_unchecked.
Sourcepub fn from_rotation_arc(from: DVec2, to: DVec2) -> Self
pub fn from_rotation_arc(from: DVec2, to: DVec2) -> Self
Gets the minimal rotation for transforming from to to.
Both vectors must be normalized. The rotation is in the plane spanned by the two vectors.
Sourcepub fn slerp(&self, other: &Self, t: f64) -> Self
pub fn slerp(&self, other: &Self, t: f64) -> Self
Spherical linear interpolation between two rotations.
Sourcepub fn powf(&self, n: f64) -> Self
pub fn powf(&self, n: f64) -> Self
Raises this rotation to a power.
For example, powf(2.0) will return a rotation with double the angle.
Sourcepub fn rotate_towards(&self, rhs: &Self, max_angle: f64) -> Self
pub fn rotate_towards(&self, rhs: &Self, max_angle: f64) -> Self
Rotates self towards rhs up to max_angle (in radians).
When max_angle is 0.0, the result will be equal to self. When max_angle is
equal to self.angle_between(rhs), the result will be equal to rhs. If
max_angle is negative, rotates towards the exact opposite of rhs.
Will not go past the target.
Sourcepub fn angle_between(&self, rhs: &Self) -> f64
pub fn angle_between(&self, rhs: &Self) -> f64
Returns the angle (in radians) between self and rhs.
Sourcepub fn dot(&self, rhs: Self) -> f64
pub fn dot(&self, rhs: Self) -> f64
Computes the dot product of self and rhs.
The dot product is equal to the cosine of the angle between two rotations.
Sourcepub fn lerp(&self, rhs: Self, s: f64) -> Self
pub fn lerp(&self, rhs: Self, s: f64) -> Self
Performs a linear interpolation between self and rhs based on
the value s.
When s is 0.0, the result will be equal to self. When s is
1.0, the result will be equal to rhs. For rotations, slerp is
usually preferred over lerp.
Sourcepub fn normalize_mut(&mut self)
pub fn normalize_mut(&mut self)
Normalizes self in place.
Does nothing if self is already normalized or zero length.
Trait Implementations§
Source§impl AbsDiffEq for DRot2
Available on crate feature approx only.
impl AbsDiffEq for DRot2
approx only.Source§fn default_epsilon() -> Self::Epsilon
fn default_epsilon() -> Self::Epsilon
Source§fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool
Source§fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
AbsDiffEq::abs_diff_eq.Source§impl MulAssign<DRot2> for DPose2
impl MulAssign<DRot2> for DPose2
Source§fn mul_assign(&mut self, rhs: DRot2)
fn mul_assign(&mut self, rhs: DRot2)
*= operation. Read moreSource§impl MulAssign for DRot2
impl MulAssign for DRot2
Source§fn mul_assign(&mut self, rhs: Self)
fn mul_assign(&mut self, rhs: Self)
*= operation. Read moreSource§impl RelativeEq for DRot2
Available on crate feature approx only.
impl RelativeEq for DRot2
approx only.Source§fn default_max_relative() -> Self::Epsilon
fn default_max_relative() -> Self::Epsilon
Source§fn relative_eq(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
Source§fn relative_ne(
&self,
other: &Rhs,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon,
) -> bool
fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool
RelativeEq::relative_eq.Source§impl UlpsEq for DRot2
Available on crate feature approx only.
impl UlpsEq for DRot2
approx only.impl Copy for DRot2
impl StructuralPartialEq for DRot2
Auto Trait Implementations§
impl Freeze for DRot2
impl RefUnwindSafe for DRot2
impl Send for DRot2
impl Sync for DRot2
impl Unpin for DRot2
impl UnwindSafe for DRot2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.