Skip to main content

Angle

Struct Angle 

Source
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: f64

Rotation angle (radians).

Implementations§

Source§

impl Angle

Source

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

Source§

type Epsilon = <f64 as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximimate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl Clone for Angle

Source§

fn clone(&self) -> Angle

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Angle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Angle

Source§

fn default() -> Angle

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Angle

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Angle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format an Angle as <{theta}>.

Source§

impl Distribution<Angle> for StandardUniform

Source§

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>
where R: Rng, Self: Sized,

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

fn map<F, S>(self, func: F) -> Map<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Map sampled values to type S Read more
Source§

impl From<Angle> for RotationMatrix<2>

Source§

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 From<f64> for Angle

Source§

fn from(theta: f64) -> Self

Create a rotation by theta radians.

§Example
use hoomd_vector::Angle;

let a = Angle::from(1.5);
assert_eq!(a.theta, 1.5);
Source§

impl PartialEq for Angle

Source§

fn eq(&self, other: &Angle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl RelativeEq for Angle

Source§

fn default_max_relative() -> Self::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

fn relative_ne( &self, other: &Rhs, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of RelativeEq::relative_eq.
Source§

impl Rotate<Cartesian<2>> for Angle

Source§

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());
Source§

type Matrix = RotationMatrix<2>

Type of the related rotation matrix
Source§

impl Rotation for Angle

Source§

fn identity() -> Self

Create an Angle that rotates by 0 radians.

§Example
use hoomd_vector::{Angle, Rotation};

let a = Angle::default();
assert_eq!(a.theta, 0.0);
Source§

fn inverted(self) -> Self

Create an Angle that rotates by the same amount in the opposite direction.

§Example
use hoomd_vector::{Angle, Rotation};
use std::f64::consts::PI;

let a = Angle::from(PI / 3.0);
let b = a.inverted();
assert_eq!(b.theta, -PI / 3.0);
Source§

fn combine(&self, other: &Self) -> Self

Create an Angle that rotates by the sum of the two angles.

§Example
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);
Source§

impl Serialize for Angle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for Angle

Source§

impl StructuralPartialEq for Angle

Auto Trait Implementations§

§

impl Freeze for Angle

§

impl RefUnwindSafe for Angle

§

impl Send for Angle

§

impl Sync for Angle

§

impl Unpin for Angle

§

impl UnsafeUnpin for Angle

§

impl UnwindSafe for Angle

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,