pub struct Angle {
pub theta: f64,
}Expand description
Rotation in the plane.
The rotation is represented by an angle theta in radians. Positive values rotate
counter-clockwise.
§Constructing Angle
The default Angle rotates by 0 radians:
use hoomd_vector::Angle;
let a = Angle::default();
assert_eq!(a.theta, 0.0)Create an Angle with a given value:
use hoomd_vector::Angle;
use std::f64::consts::PI;
let a = Angle::from(PI / 2.0);
assert_eq!(a.theta, PI / 2.0);Create a random Angle from the uniform distribution over all rotations:
use hoomd_vector::Angle;
use rand::{RngExt, SeedableRng, rngs::StdRng};
let mut rng = StdRng::seed_from_u64(1);
let a: Angle = rng.random();§Operations using Angle
Rotate a Cartesian<2> vector by an Angle:
use approxim::assert_relative_eq;
use hoomd_vector::{Angle, Cartesian, Rotate, Rotation};
use std::f64::consts::PI;
let v = Cartesian::from([-1.0, 0.0]);
let a = Angle::from(PI / 2.0);
let rotated = a.rotate(&v);
assert_relative_eq!(rotated, [0.0, -1.0].into())Combine two rotations together:
use hoomd_vector::{Angle, Rotation};
use std::f64::consts::PI;
let a = Angle::from(PI / 2.0);
let b = Angle::from(-PI / 4.0);
let c = a.combine(&b);
assert_eq!(c.theta, PI / 4.0);Fields§
§theta: f64Rotation angle (radians).
Implementations§
Source§impl Angle
impl Angle
Sourcepub fn to_reduced(self) -> Self
pub fn to_reduced(self) -> Self
Reduce the rotation.
Angle rotations are well-defined for any value of theta. However, combining small
rotations with large ones will introduce floating point round-off error. Reducing an Angle
creates an equivalent rotation with theta in the range from 0 to 2 pi.
§Example
use hoomd_vector::Angle;
use std::f64::consts::PI;
let a = Angle::from(20.0 * PI);
let b = a.to_reduced();
assert_eq!(b.theta, 0.0)Trait Implementations§
Source§impl AbsDiffEq for Angle
impl AbsDiffEq for Angle
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<'de> Deserialize<'de> for Angle
impl<'de> Deserialize<'de> for Angle
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Distribution<Angle> for StandardUniform
impl Distribution<Angle> for StandardUniform
Source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Angle
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Angle
Sample a random angle from the uniform distribution over all rotations.
§Example
use hoomd_vector::Angle;
use rand::{RngExt, SeedableRng, rngs::StdRng};
let mut rng = StdRng::seed_from_u64(1);
let v: Angle = rng.random();Source§fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
fn sample_iter<R>(self, rng: R) -> Iter<Self, R, T>
T, using rng as
the source of randomness. Read moreSource§impl From<Angle> for RotationMatrix<2>
impl From<Angle> for RotationMatrix<2>
Source§fn from(angle: Angle) -> RotationMatrix<2>
fn from(angle: Angle) -> RotationMatrix<2>
Construct a rotation matrix equivalent to this angle’s rotation.
When rotating many vectors by the same Angle, improve performance
by converting to a matrix first and applying that matrix to the vectors.
§Example
use approxim::assert_relative_eq;
use hoomd_vector::{Angle, Cartesian, Rotate, RotationMatrix};
use std::f64::consts::PI;
let v = Cartesian::from([-1.0, 0.0]);
let a = Angle::from(PI / 2.0);
let matrix = RotationMatrix::from(a);
let rotated = matrix.rotate(&v);
assert_relative_eq!(rotated, [0.0, -1.0].into());Source§impl RelativeEq for Angle
impl RelativeEq for Angle
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 Rotate<Cartesian<2>> for Angle
impl Rotate<Cartesian<2>> for Angle
Source§fn rotate(&self, vector: &Cartesian<2>) -> Cartesian<2>
fn rotate(&self, vector: &Cartesian<2>) -> Cartesian<2>
Rotate a Cartesian<2> in the plane by an Angle
§Example
use approxim::assert_relative_eq;
use hoomd_vector::{Angle, Cartesian, Rotate, Rotation};
use std::f64::consts::PI;
let v = Cartesian::from([-1.0, 0.0]);
let a = Angle::from(PI / 2.0);
let rotated = a.rotate(&v);
assert_relative_eq!(rotated, [0.0, -1.0].into());