# [−]Struct lumol::Matrix3

pub struct 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);

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]

🔬 This is a nightly-only experimental API. (array_methods)

Returns a slice containing the entire array. Equivalent to &s[..].

#### pub fn as_mut_slice(&mut self) -> &mut [T][src]

🔬 This is a nightly-only experimental API. (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.

### impl<'a, 'b> Add<&'a Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a> Add<&'a Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a, 'b> Add<&'a mut Matrix3> for &'b Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a> Add<&'a mut Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a, 'b> Add<&'a mut Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl Add<Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a> Add<Matrix3> for &'a mut Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl<'a> Add<Matrix3> for &'a Matrix3

#### type Output = Matrix3

The resulting type after applying the + operator.

### impl Deref for Matrix3

#### type Target = [[f64; 3]; 3]

The resulting type after dereferencing.

### impl<'a> Div<f64> for &'a Matrix3

#### type Output = Matrix3

The resulting type after applying the / operator.

### impl Div<f64> for Matrix3

#### type Output = Matrix3

The resulting type after applying the / operator.

### impl<'a> Div<f64> for &'a mut Matrix3

#### type Output = Matrix3

The resulting type after applying the / operator.

### impl<'a, 'b> Mul<&'a Matrix3> for &'b Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a> Mul<&'a Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a Vector3D> for &'b mut Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a> Mul<&'a Vector3D> for Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a Vector3D> for &'b Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a> Mul<&'a mut Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a mut Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a mut Matrix3> for &'b Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a> Mul<&'a mut Vector3D> for Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a mut Vector3D> for &'b mut Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a, 'b> Mul<&'a mut Vector3D> for &'b Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a> Mul<Matrix3> for &'a Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a> Mul<Matrix3> for &'a mut Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl Mul<Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a> Mul<Vector3D> for &'a mut Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl Mul<Vector3D> for Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a> Mul<Vector3D> for &'a Matrix3

#### type Output = Vector3D

The resulting type after applying the * operator.

### impl<'a> Mul<f64> for &'a Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl Mul<f64> for Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl<'a> Mul<f64> for &'a mut Matrix3

#### type Output = Matrix3

The resulting type after applying the * operator.

### impl One for Matrix3

#### pub fn one() -> Matrix3

Create an identity matrix

### impl<'a> Sub<&'a Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a, 'b> Sub<&'a Matrix3> for &'b Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a, 'b> Sub<&'a Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a, 'b> Sub<&'a mut Matrix3> for &'b mut Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a> Sub<&'a mut Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a, 'b> Sub<&'a mut Matrix3> for &'b Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl Sub<Matrix3> for Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a> Sub<Matrix3> for &'a Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

### impl<'a> Sub<Matrix3> for &'a mut Matrix3

#### type Output = Matrix3

The resulting type after applying the - operator.

## Blanket Implementations

### impl<T> Pointable for T

#### type Init = T

The type for initializers.

### impl<T> ToOwned for T where    T: Clone, [src]

#### type Owned = T

The resulting type after obtaining ownership.

### impl<T, U> TryFrom<U> for T where    U: Into<T>, [src]

#### type Error = Infallible

The type returned in the event of a conversion error.

### impl<T, U> TryInto<U> for T where    U: TryFrom<T>, [src]

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

The type returned in the event of a conversion error.