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>
impl<const N: usize> RotationMatrix<N>
Sourcepub fn rows(&self) -> [Cartesian<N>; N]
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);Sourcepub fn inverted(self) -> Self
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>
impl<const N: usize> Clone for RotationMatrix<N>
Source§fn clone(&self) -> RotationMatrix<N>
fn clone(&self) -> RotationMatrix<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<const N: usize> Debug for RotationMatrix<N>
impl<const N: usize> Debug for RotationMatrix<N>
Source§impl<const N: usize> Default for RotationMatrix<N>
impl<const N: usize> Default for RotationMatrix<N>
Source§fn default() -> RotationMatrix<N>
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>
impl<'de, const N: usize> Deserialize<'de> for RotationMatrix<N>
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<const N: usize> Display for RotationMatrix<N>
impl<const N: usize> Display for RotationMatrix<N>
Source§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<const N: usize> From<RotationMatrix<N>> for Matrix<N, N>
impl<const N: usize> From<RotationMatrix<N>> for Matrix<N, N>
Source§fn from(value: RotationMatrix<N>) -> Self
fn from(value: RotationMatrix<N>) -> Self
Source§impl From<Versor> for RotationMatrix<3>
impl From<Versor> for RotationMatrix<3>
Source§fn from(versor: Versor) -> RotationMatrix<3>
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> PartialEq for RotationMatrix<N>
impl<const N: usize> PartialEq for RotationMatrix<N>
Source§impl<const N: usize> Rotate<Cartesian<N>> for RotationMatrix<N>
impl<const N: usize> Rotate<Cartesian<N>> for RotationMatrix<N>
Source§fn rotate(&self, vector: &Cartesian<N>) -> Cartesian<N>
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());