SymmetricMat3

Struct SymmetricMat3 

Source
pub struct SymmetricMat3(/* private fields */);
Expand description

A memory-efficient 3×3 symmetric matrix for spatial algebra operations.

This structure stores a symmetric 3×3 matrix using only 6 elements instead of 9, exploiting the mathematical property that a_ij = a_ji for symmetric matrices. This provides significant memory savings and computational efficiency for inertia tensors and other symmetric operations in spatial algebra.

§Storage Format

The matrix is stored in column-major order, containing the lower triangular elements of the symmetric matrix:

Stored array: [a₀₀, a₁₀, a₂₀, a₁₁, a₂₁, a₂₂]

Full matrix:
| a₀₀  a₀₁  a₀₂ |
| a₁₀  a₁₁  a₁₂ |  where a_ij = a_ji
| a₂₀  a₂₁  a₂₂ |

§Applications in Spatial Algebra

  • Rotational inertia tensors: Always symmetric, stored efficiently
  • Covariance matrices: Common in state estimation and filtering
  • Stiffness/damping matrices: Used in compliant dynamics
  • Quadratic forms: Energy calculations and optimization

§Performance Benefits

  • Memory: 33% reduction compared to full 3×3 matrix storage
  • Cache efficiency: Compact layout improves memory access patterns
  • Computation: Avoids redundant calculations on symmetric elements

Implementations§

Source§

impl SymmetricMat3

Source

pub const ONE: Self

Identity matrix (diagonal elements are 1, off-diagonal are 0).

Represents the 3×3 identity matrix in symmetric storage format.

Source

pub const ZERO: Self

Zero matrix (all elements are 0).

Useful for initialization and as the additive identity.

Source

pub fn from_array(array: [Real; 6]) -> Self

Create a symmetric matrix from a 6-element array in column-major order.

§Input Format

The array should contain the lower triangular elements in column-major order:

array = [a₀₀, a₁₀, a₂₀, a₁₁, a₂₁, a₂₂]
§Example
use spatial_math::SymmetricMat3;

// Create matrix |1 2 3|
//               |2 4 5|
//               |3 5 6|
let matrix = SymmetricMat3::from_array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);
Source

pub fn from_iterator(iter: impl IntoIterator<Item = Real>) -> Self

Source

pub fn mat3(&self) -> Mat3

Source

pub fn mul_vec(&self, v: Vec3) -> Vec3

Source

pub fn scale(&self, scalar: Real) -> Self

Source

pub fn add(&self, rhs: Self) -> Self

Source

pub fn sub(&self, rhs: Self) -> Self

Source

pub fn into_array(self) -> [Real; 6]

Trait Implementations§

Source§

impl Add for SymmetricMat3

Source§

type Output = SymmetricMat3

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl Clone for SymmetricMat3

Source§

fn clone(&self) -> SymmetricMat3

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 SymmetricMat3

Source§

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

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

impl Default for SymmetricMat3

Source§

fn default() -> SymmetricMat3

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

impl From<[f32; 6]> for SymmetricMat3

Source§

fn from(array: [Real; 6]) -> Self

Converts to this type from the input type.
Source§

impl From<Matrix<f32, Const<3>, Const<3>, ArrayStorage<f32, 3, 3>>> for SymmetricMat3

Source§

fn from(mat: Mat3) -> Self

Converts to this type from the input type.
Source§

impl<RStride, CStride> From<Matrix<f32, Const<3>, Const<3>, ViewStorage<'_, f32, Const<3>, Const<3>, RStride, CStride>>> for SymmetricMat3
where RStride: Dim, CStride: Dim,

Source§

fn from(mat: MatrixView3<'_, Real, RStride, CStride>) -> Self

Takes the lower triangle of the matrix and converts it into a SymmetricMat3.

Source§

impl Index<(usize, usize)> for SymmetricMat3

Source§

type Output = f32

The returned type after indexing.
Source§

fn index(&self, (row, col): (usize, usize)) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Mul<Matrix<f32, Const<3>, Const<1>, ArrayStorage<f32, 3, 1>>> for SymmetricMat3

Source§

type Output = Matrix<f32, Const<3>, Const<1>, ArrayStorage<f32, 3, 1>>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec3) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f32> for SymmetricMat3

Source§

type Output = SymmetricMat3

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Real) -> Self::Output

Performs the * operation. Read more
Source§

impl Sub for SymmetricMat3

Source§

type Output = SymmetricMat3

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
Source§

impl Copy for SymmetricMat3

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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, 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.