Expand description
A 2-dimensional rotation matrix.
Implementations§
source§impl<N: Real> Rotation2<N>
impl<N: Real> Rotation2<N>
sourcepub fn new(angle: N) -> Self
pub fn new(angle: N) -> Self
Builds a 2 dimensional rotation matrix from an angle in radian.
Example
let rot = Rotation2::new(f32::consts::FRAC_PI_2);
assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0));
sourcepub fn from_scaled_axis<SB: Storage<N, U1>>(
axisangle: Vector<N, U1, SB>
) -> Self
pub fn from_scaled_axis<SB: Storage<N, U1>>(
axisangle: Vector<N, U1, SB>
) -> Self
Builds a 2 dimensional rotation matrix 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.
sourcepub fn rotation_between<SB, SC>(
a: &Vector<N, U2, SB>,
b: &Vector<N, U2, SC>
) -> Selfwhere
SB: Storage<N, U2>,
SC: Storage<N, U2>,
pub fn rotation_between<SB, SC>(
a: &Vector<N, U2, SB>,
b: &Vector<N, U2, SC>
) -> Selfwhere
SB: Storage<N, U2>,
SC: Storage<N, U2>,
The rotation matrix required to align a
and b
but with its angle.
This is the rotation R
such that (R * a).angle(b) == 0 && (R * a).dot(b).is_positive()
.
Example
let a = Vector2::new(1.0, 2.0);
let b = Vector2::new(2.0, 1.0);
let rot = Rotation2::rotation_between(&a, &b);
assert_relative_eq!(rot * a, b);
assert_relative_eq!(rot.inverse() * b, a);
sourcepub fn scaled_rotation_between<SB, SC>(
a: &Vector<N, U2, SB>,
b: &Vector<N, U2, SC>,
s: N
) -> Selfwhere
SB: Storage<N, U2>,
SC: Storage<N, U2>,
pub fn scaled_rotation_between<SB, SC>(
a: &Vector<N, U2, SB>,
b: &Vector<N, U2, SC>,
s: N
) -> Selfwhere
SB: Storage<N, U2>,
SC: Storage<N, U2>,
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 = Rotation2::scaled_rotation_between(&a, &b, 0.2);
let rot5 = Rotation2::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);
source§impl<N: Real> Rotation2<N>
impl<N: Real> Rotation2<N>
sourcepub fn angle_to(&self, other: &Rotation2<N>) -> N
pub fn angle_to(&self, other: &Rotation2<N>) -> N
The rotation angle needed to make self
and other
coincide.
Example
let rot1 = Rotation2::new(0.1);
let rot2 = Rotation2::new(1.7);
assert_relative_eq!(rot1.angle_to(&rot2), 1.6);
sourcepub fn rotation_to(&self, other: &Rotation2<N>) -> Rotation2<N>
pub fn rotation_to(&self, other: &Rotation2<N>) -> Rotation2<N>
The rotation matrix needed to make self
and other
coincide.
The result is such that: self.rotation_to(other) * self == other
.
Example
let rot1 = Rotation2::new(0.1);
let rot2 = Rotation2::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);
sourcepub fn powf(&self, n: N) -> Rotation2<N>
pub fn powf(&self, n: N) -> Rotation2<N>
Raise the quaternion to a given floating power, i.e., returns the rotation with the angle
of self
multiplied by n
.
Example
let rot = Rotation2::new(0.78);
let pow = rot.powf(2.0);
assert_eq!(pow.angle(), 2.0 * 0.78);
sourcepub fn scaled_axis(&self) -> VectorN<N, U1>
pub fn scaled_axis(&self) -> VectorN<N, U1>
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.
Trait Implementations§
source§impl<N1, N2> SubsetOf<Unit<Complex<N2>>> for Rotation2<N1>where
N1: Real,
N2: Real + SupersetOf<N1>,
impl<N1, N2> SubsetOf<Unit<Complex<N2>>> for Rotation2<N1>where
N1: Real,
N2: Real + SupersetOf<N1>,
source§fn to_superset(&self) -> UnitComplex<N2>
fn to_superset(&self) -> UnitComplex<N2>
self
to the equivalent element of its superset.source§fn is_in_subset(q: &UnitComplex<N2>) -> bool
fn is_in_subset(q: &UnitComplex<N2>) -> bool
element
is actually part of the subset Self
(and can be converted to it).source§unsafe fn from_superset_unchecked(q: &UnitComplex<N2>) -> Self
unsafe fn from_superset_unchecked(q: &UnitComplex<N2>) -> Self
self.to_superset
but without any property checks. Always succeeds.