[−]Struct lumol::Matrix3
A 3x3 square matrix type.
Matrix3
implements all the usual arithmetic operations:
use lumol_core::types::{Matrix3, Vector3D}; let one = Matrix3::one(); let a = Matrix3::new([ [1.0, 0.0, 3.0], [0.0, 2.0, 5.6], [0.0, 0.0, 8.0] ]); let v = Vector3D::new(3.0, 2.0, 1.0); // Indexing assert_eq!(a[0][0], 1.0); assert_eq!(a[1][2], 5.6); // Addition let c = a + one; assert_eq!(c, Matrix3::new([ [2.0, 0.0, 3.0], [0.0, 3.0, 5.6], [0.0, 0.0, 9.0] ])); // Subtraction let c = a - one; assert_eq!(c, Matrix3::new([ [0.0, 0.0, 3.0], [0.0, 1.0, 5.6], [0.0, 0.0, 7.0] ])); // Multiplication let c = a * one; // matrix - matrix assert_eq!(c, a); let c = a * v; // matrix - vector assert_eq!(c, Vector3D::new(6.0, 9.6, 8.0)); let c = 42.0 * one; // matrix - scalar assert_eq!(c, Matrix3::new([ [42., 0.0, 0.0], [0.0, 42., 0.0], [0.0, 0.0, 42.] ])); // Division let c = a / 2.0; assert_eq!(c, Matrix3::new([ [0.5, 0.0, 1.5], [0.0, 1.0, 2.8], [0.0, 0.0, 4.0] ]));
Implementations
impl Matrix3
pub fn new(data: [[f64; 3]; 3]) -> Matrix3
Create a new Matrix3
specifying all its components
Examples
let matrix = Matrix3::new([ [0.0, 0.0, 3.0], [0.0, 1.0, 5.6], [0.0, 0.0, 7.0], ]); assert_eq!(matrix[0][2], 3.0);
pub fn zero() -> Matrix3
Create a new Matrix3
with components set to 0
Examples
let matrix = Matrix3::zero(); for i in 0..3 { for j in 0..3 { assert_eq!(matrix[i][j], 0.0); } }
pub fn one() -> Matrix3
Create a new Vector3D
with components all components set to 0
,
except the diagonal components set to 1.
Examples
let matrix = Matrix3::one(); for i in 0..3 { for j in 0..3 { if i == j { assert_eq!(matrix[i][j], 1.0); } else { assert_eq!(matrix[i][j], 0.0); } } }
pub fn rotation(axis: &Vector3D, angle: f64) -> Matrix3
Returns rotation matrix given a rotation angle and an axis.
Examples
let e1 = Vector3D::new(1.0f64, 0.0, 0.0); let e3 = Vector3D::new(0.0f64, 0.0, 1.0); let angle = 90f64.to_radians(); let rotation = Matrix3::rotation(&(e1 * 2.0), angle); let mut rot_vec = rotation * e3; for i in 0..3 { rot_vec[i] = (rot_vec[i] * 1.0e8).round() / 1.0e8 }; assert_eq!(rot_vec, Vector3D::new(0.0, 1.0, 0.0));
pub fn trace(&self) -> f64
Compute the trace of the matrix
Examples
let matrix = Matrix3::new([ [0.0, 0.0, 3.0], [0.0, 1.0, 5.6], [0.0, 0.0, 7.0] ]); assert_eq!(matrix.trace(), 8.0);
pub fn inverse(&self) -> Matrix3
Computes the inverse of a matrix
Examples
// A diagonal matrix is trivially invertible let matrix = Matrix3::new([ [4.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 7.0] ]); let inverted = Matrix3::new([ [1.0/4.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0/7.0] ]); assert_eq!(matrix.inverse(), inverted); assert_eq!(matrix * matrix.inverse(), Matrix3::one());
Panics
If the matrix is not invertible, i.e. if the matrix determinant equals zero.
pub fn determinant(&self) -> f64
Computes the determinant of a matrix
Examples
let matrix = Matrix3::new([ [4.0, 0.0, 0.0], [0.0, 1.5, 0.0], [0.0, 0.0, 7.0] ]); assert_eq!(matrix.determinant(), 4.0 * 1.5 * 7.0);
pub fn transposed(&self) -> Matrix3
Transpose this matrix into a new matrix
Examples
let matrix = Matrix3::new([ [1.0, 2.0, 4.0], [0.0, 1.0, 3.0], [0.0, 0.0, 1.0] ]); let transposed = Matrix3::new([ [1.0, 0.0, 0.0], [2.0, 1.0, 0.0], [4.0, 3.0, 1.0] ]); assert_eq!(matrix.transposed(), transposed);
pub fn norm(&self) -> f64
Compute the (Frobenius) norm of the matrix
Examples
let matrix = Matrix3::new([ [1.0, 2.0, 4.0], [0.0, 1.0, 3.0], [0.0, 0.0, 1.0] ]); assert_eq!(matrix.norm(), 5.656854249492381);
Methods from Deref<Target = [[f64; 3]; 3]>
pub fn as_slice(&self) -> &[T]
[src]
array_methods
)Returns a slice containing the entire array. Equivalent to &s[..]
.
pub fn as_mut_slice(&mut self) -> &mut [T]
[src]
array_methods
)Returns a mutable slice containing the entire array. Equivalent to
&mut s[..]
.
Trait Implementations
impl<'a, 'b> Add<&'a Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Add<&'a Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a Matrix3) -> Matrix3
impl<'a> Add<&'a Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Add<&'a mut Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a mut Matrix3) -> Matrix3
impl<'a> Add<&'a mut Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a mut Matrix3) -> Matrix3
impl<'a, 'b> Add<&'a mut Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: &'a mut Matrix3) -> Matrix3
impl Add<Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: Matrix3) -> Matrix3
impl<'a> Add<Matrix3> for &'a mut Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: Matrix3) -> Matrix3
impl<'a> Add<Matrix3> for &'a Matrix3
type Output = Matrix3
The resulting type after applying the +
operator.
pub fn add(self, other: Matrix3) -> Matrix3
impl<'a> AddAssign<&'a Matrix3> for Matrix3
pub fn add_assign(&mut self, other: &'a Matrix3)
impl<'a> AddAssign<&'a mut Matrix3> for Matrix3
pub fn add_assign(&mut self, other: &'a mut Matrix3)
impl<'a> AddAssign<Matrix3> for Matrix3
pub fn add_assign(&mut self, other: Matrix3)
impl Clone for Matrix3
pub fn clone(&self) -> Matrix3
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Matrix3
impl Debug for Matrix3
impl Deref for Matrix3
type Target = [[f64; 3]; 3]
The resulting type after dereferencing.
pub fn deref(&self) -> &<Matrix3 as Deref>::Target
impl DerefMut for Matrix3
impl<'a> Div<f64> for &'a Matrix3
type Output = Matrix3
The resulting type after applying the /
operator.
pub fn div(self, other: f64) -> Matrix3
impl Div<f64> for Matrix3
type Output = Matrix3
The resulting type after applying the /
operator.
pub fn div(self, other: f64) -> Matrix3
impl<'a> Div<f64> for &'a mut Matrix3
type Output = Matrix3
The resulting type after applying the /
operator.
pub fn div(self, other: f64) -> Matrix3
impl<'a> DivAssign<&'a f64> for Matrix3
pub fn div_assign(&mut self, other: &'a f64)
impl<'a> DivAssign<&'a mut f64> for Matrix3
pub fn div_assign(&mut self, other: &'a mut f64)
impl<'a> DivAssign<f64> for Matrix3
pub fn div_assign(&mut self, other: f64)
impl From<[[f64; 3]; 3]> for Matrix3
impl<'a, 'b> Mul<&'a Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Mul<&'a Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Matrix3) -> Matrix3
impl<'a> Mul<&'a Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Mul<&'a Vector3D> for &'b mut Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Vector3D) -> Vector3D
impl<'a> Mul<&'a Vector3D> for Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Vector3D) -> Vector3D
impl<'a, 'b> Mul<&'a Vector3D> for &'b Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a Vector3D) -> Vector3D
impl<'a> Mul<&'a mut Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Matrix3) -> Matrix3
impl<'a, 'b> Mul<&'a mut Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Matrix3) -> Matrix3
impl<'a, 'b> Mul<&'a mut Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Matrix3) -> Matrix3
impl<'a> Mul<&'a mut Vector3D> for Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Vector3D) -> Vector3D
impl<'a, 'b> Mul<&'a mut Vector3D> for &'b mut Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Vector3D) -> Vector3D
impl<'a, 'b> Mul<&'a mut Vector3D> for &'b Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: &'a mut Vector3D) -> Vector3D
impl<'a> Mul<Matrix3> for &'a Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: Matrix3) -> Matrix3
impl<'a> Mul<Matrix3> for &'a mut Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: Matrix3) -> Matrix3
impl Mul<Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: Matrix3) -> Matrix3
impl<'a> Mul<Vector3D> for &'a mut Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: Vector3D) -> Vector3D
impl Mul<Vector3D> for Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: Vector3D) -> Vector3D
impl<'a> Mul<Vector3D> for &'a Matrix3
type Output = Vector3D
The resulting type after applying the *
operator.
pub fn mul(self, other: Vector3D) -> Vector3D
impl<'a> Mul<f64> for &'a Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: f64) -> Matrix3
impl Mul<f64> for Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: f64) -> Matrix3
impl<'a> Mul<f64> for &'a mut Matrix3
type Output = Matrix3
The resulting type after applying the *
operator.
pub fn mul(self, other: f64) -> Matrix3
impl<'a> MulAssign<&'a Matrix3> for Matrix3
pub fn mul_assign(&mut self, other: &'a Matrix3)
impl<'a> MulAssign<&'a f64> for Matrix3
pub fn mul_assign(&mut self, other: &'a f64)
impl<'a> MulAssign<&'a mut Matrix3> for Matrix3
pub fn mul_assign(&mut self, other: &'a mut Matrix3)
impl<'a> MulAssign<&'a mut f64> for Matrix3
pub fn mul_assign(&mut self, other: &'a mut f64)
impl<'a> MulAssign<Matrix3> for Matrix3
pub fn mul_assign(&mut self, other: Matrix3)
impl<'a> MulAssign<f64> for Matrix3
pub fn mul_assign(&mut self, other: f64)
impl One for Matrix3
pub fn one() -> Matrix3
Create an identity matrix
fn set_one(&mut self)
[src]
fn is_one(&self) -> bool where
Self: PartialEq<Self>,
[src]
Self: PartialEq<Self>,
impl PartialEq<Matrix3> for Matrix3
impl StructuralPartialEq for Matrix3
impl<'a> Sub<&'a Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Sub<&'a Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Sub<&'a Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a Matrix3) -> Matrix3
impl<'a, 'b> Sub<&'a mut Matrix3> for &'b mut Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a mut Matrix3) -> Matrix3
impl<'a> Sub<&'a mut Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a mut Matrix3) -> Matrix3
impl<'a, 'b> Sub<&'a mut Matrix3> for &'b Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: &'a mut Matrix3) -> Matrix3
impl Sub<Matrix3> for Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: Matrix3) -> Matrix3
impl<'a> Sub<Matrix3> for &'a Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: Matrix3) -> Matrix3
impl<'a> Sub<Matrix3> for &'a mut Matrix3
type Output = Matrix3
The resulting type after applying the -
operator.
pub fn sub(self, other: Matrix3) -> Matrix3
impl<'a> SubAssign<&'a Matrix3> for Matrix3
pub fn sub_assign(&mut self, other: &'a Matrix3)
impl<'a> SubAssign<&'a mut Matrix3> for Matrix3
pub fn sub_assign(&mut self, other: &'a mut Matrix3)
impl<'a> SubAssign<Matrix3> for Matrix3
pub fn sub_assign(&mut self, other: Matrix3)
impl Sum<Matrix3> for Matrix3
impl Zero for Matrix3
Auto Trait Implementations
impl RefUnwindSafe for Matrix3
impl Send for Matrix3
impl Sync for Matrix3
impl Unpin for Matrix3
impl UnwindSafe for Matrix3
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,