Skip to main content

RotationMatrix

Struct RotationMatrix 

Source
pub struct RotationMatrix<const N: usize> { /* private fields */ }
Expand description

Rotate vectors efficiently.

Construct a RotationMatrix to efficiently rotate many vectors by the same rotation.

See:

RotationMatrix intentionally does not implement Rotation. Angle and Versor are representations of rotations that are often the most effective and numerically stable to manipulate.

Implementations§

Source§

impl<const N: usize> RotationMatrix<N>

Source

pub fn rows(&self) -> [Cartesian<N>; N]

Get the rows of the rotation matrix.

§Example
use hoomd_vector::{Angle, InnerProduct, RotationMatrix, Vector};
use std::f64::consts::PI;

let a = Angle::from(PI / 2.0);

let matrix = RotationMatrix::from(a);
assert!(matrix.rows()[0].dot(&[0.0, -1.0].into()) > 0.99);
assert!(matrix.rows()[1].dot(&[1.0, 0.0].into()) > 0.99);
Source

pub fn inverted(self) -> Self

Create a matrix that performs the inverse rotation.

Matrix inversion is cheaper than Angle -> RotationMatrix and Versor -> RotationMatrix conversions. When you need both rotations, convert once and then invert.

§Example
use hoomd_vector::{Angle, InnerProduct, RotationMatrix, Vector};
use std::f64::consts::PI;

let a = Angle::from(PI / 2.0);

let matrix = RotationMatrix::from(a);
let inverted_matrix = matrix.inverted();
assert!(inverted_matrix.rows()[0].dot(&[0.0, 1.0].into()) > 0.99);
assert!(inverted_matrix.rows()[1].dot(&[-1.0, 0.0].into()) > 0.99);

Trait Implementations§

Source§

impl<const N: usize> Clone for RotationMatrix<N>

Source§

fn clone(&self) -> RotationMatrix<N>

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<const N: usize> Debug for RotationMatrix<N>

Source§

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

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

impl<const N: usize> Default for RotationMatrix<N>

Source§

fn default() -> RotationMatrix<N>

Create an identity matrix.

\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}

,

\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

, and so on.

§Example
use hoomd_vector::RotationMatrix;

let identity = RotationMatrix::<3>::default();
Source§

impl<'de, const N: usize> Deserialize<'de> for RotationMatrix<N>

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<const N: usize> Display for RotationMatrix<N>

Source§

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

Formats the value using the given formatter. 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<const N: usize> From<RotationMatrix<N>> for Matrix<N, N>

Source§

fn from(value: RotationMatrix<N>) -> Self

Converts to this type from the input type.
Source§

impl From<Versor> for RotationMatrix<3>

Source§

fn from(versor: Versor) -> RotationMatrix<3>

Construct a rotation matrix equivalent to this versor’s rotation.

When rotating many vectors by the same Versor, improve performance by converting to a matrix first and applying that matrix to the vectors.

§Example
use approxim::assert_relative_eq;
use hoomd_vector::{Cartesian, Rotate, RotationMatrix, Versor};
use std::f64::consts::PI;

let a = Cartesian::from([-1.0, 0.0, 0.0]);
let v = Versor::from_axis_angle([0.0, 0.0, 1.0].try_into()?, PI / 2.0);

let matrix = RotationMatrix::from(v);
let b = matrix.rotate(&a);
assert_relative_eq!(b, [0.0, -1.0, 0.0].into());
Source§

impl<const N: usize, const K: usize> MatMul<Matrix<N, K>> for RotationMatrix<N>

Source§

type Output = Matrix<N, K>

The type of the output matrix.
Source§

fn matmul(&self, rhs: &Matrix<N, K>) -> Self::Output

Multiply two matrices. Read more
Source§

impl<const N: usize> PartialEq for RotationMatrix<N>

Source§

fn eq(&self, other: &RotationMatrix<N>) -> 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<const N: usize> Rotate<Cartesian<N>> for RotationMatrix<N>

Source§

fn rotate(&self, vector: &Cartesian<N>) -> Cartesian<N>

Rotate a Cartesian<N> by a RotationMatrix

§Examples
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());
use approxim::assert_relative_eq;
use hoomd_vector::{Cartesian, Rotate, RotationMatrix, Versor};
use std::f64::consts::PI;

let a = Cartesian::from([-1.0, 0.0, 0.0]);
let v = Versor::from_axis_angle([0.0, 0.0, 1.0].try_into()?, PI / 2.0);

let matrix = RotationMatrix::from(v);
let b = matrix.rotate(&a);
assert_relative_eq!(b, [0.0, -1.0, 0.0].into());
Source§

type Matrix = RotationMatrix<N>

Type of the related rotation matrix
Source§

impl<const N: usize> Serialize for RotationMatrix<N>

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<const N: usize> Copy for RotationMatrix<N>

Source§

impl<const N: usize> StructuralPartialEq for RotationMatrix<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for RotationMatrix<N>

§

impl<const N: usize> RefUnwindSafe for RotationMatrix<N>

§

impl<const N: usize> Send for RotationMatrix<N>

§

impl<const N: usize> Sync for RotationMatrix<N>

§

impl<const N: usize> Unpin for RotationMatrix<N>

§

impl<const N: usize> UnsafeUnpin for RotationMatrix<N>

§

impl<const N: usize> UnwindSafe for RotationMatrix<N>

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>,