Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
Phyth::Matrix< 3, 3, T > Struct Template Reference

3x3 matrix with Quantity components More...

#include <Matrix3x3.hpp>

Public Member Functions

constexpr Matrix ()
 Construct a zero matrix.
 
constexpr Matrix (const Vector3< T > &col0, const Vector3< T > &col1, const Vector3< T > &col2)
 Construct from three column vectors.
 
constexpr Matrix (T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22)
 Construct from individual components (row-major ordering)
 
constexpr Matrix Transpose () const
 Compute the transpose of the matrix.
 
constexpr T Trace () const
 Compute the trace of the matrix.
 
constexpr auto Symmetric () const
 Compute the symmetric part of the matrix.
 
constexpr auto Antisymmetric () const
 Compute the antisymmetric part of the matrix.
 
const T & At (const int i, const int j) const
 Access element at row i, column j with bounds checking (0-based indexing)
 
T & At (const int i, const int j)
 Access element at row i, column j with bounds checking (0-based indexing) - mutable version.
 
constexpr const T & operator() (const int i, const int j) const
 Access element at row i, column j (0-based indexing) - no bounds checking.
 
constexpr T & operator() (const int i, const int j)
 Access element at row i, column j (0-based indexing) - mutable version.
 
template<typename U >
constexpr auto operator+ (const Matrix3x3< U > &other) const
 Matrix addition.
 
template<typename U >
constexpr auto operator- (const Matrix3x3< U > &other) const
 Matrix subtraction.
 
constexpr auto operator- () const
 Unary negation.
 
template<typename U >
constexpr auto operator* (U scalar) const
 Scalar multiplication (matrix * scalar)
 
template<typename U >
constexpr auto operator* (const Vector3< U > &v) const
 Matrix-vector multiplication: M * v.
 
template<typename U >
constexpr auto operator* (const Matrix3x3< U > &other) const
 Matrix-matrix multiplication: A * B.
 
template<typename U >
constexpr Matrix & operator+= (const Matrix3x3< U > &other)
 Addition assignment.
 
template<typename U >
constexpr Matrix & operator-= (const Matrix3x3< U > &other)
 Subtraction assignment.
 
template<typename U >
constexpr Matrix & operator*= (U scalar)
 Scalar multiplication assignment.
 
template<typename U >
constexpr bool operator== (const Matrix3x3< U > &other) const
 Equality comparison.
 
template<typename U >
constexpr bool operator!= (const Matrix3x3< U > &other) const
 Inequality comparison.
 
template<typename UnitT >
Matrix3x3< Quantity< UnitT > > As () const
 Convert all components to a different unit of the same dimension.
 

Static Public Member Functions

static constexpr Matrix Identity ()
 Create an identity matrix.
 

Public Attributes

Vector3< T > x_basis
 
Vector3< T > y_basis
 
Vector3< T > z_basis
 

Friends

std::ostream & operator<< (std::ostream &os, const Matrix &m)
 Stream insertion operator.
 

Detailed Description

template<typename T>
struct Phyth::Matrix< 3, 3, T >

3x3 matrix with Quantity components

Matrix3x3 stores three column vectors, enabling matrix-vector operations while preserving physical dimensions.

Template Parameters
TComponent type (must be a Quantity instantiation)

Example: Matrix3x3<Quantity<Meter>> m; // 3x3 matrix with meter components auto result = m * Vector3<Quantity<Meter>>(1.0_m, 0_m, 0_m);

Definition at line 27 of file Matrix3x3.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

template<typename T >
constexpr Phyth::Matrix< 3, 3, T >::Matrix ( )
inlineconstexpr

Construct a zero matrix.

Initializes all elements to zero using Quantity's default constructor.

Definition at line 39 of file Matrix3x3.hpp.

◆ Matrix() [2/3]

template<typename T >
constexpr Phyth::Matrix< 3, 3, T >::Matrix ( const Vector3< T > &  col0,
const Vector3< T > &  col1,
const Vector3< T > &  col2 
)
inlineconstexpr

Construct from three column vectors.

Parameters
col0First column vector
col1Second column vector
col2Third column vector

Definition at line 49 of file Matrix3x3.hpp.

◆ Matrix() [3/3]

template<typename T >
constexpr Phyth::Matrix< 3, 3, T >::Matrix ( T  m00,
T  m01,
T  m02,
T  m10,
T  m11,
T  m12,
T  m20,
T  m21,
T  m22 
)
inlineconstexpr

Construct from individual components (row-major ordering)

This constructor takes components in row-major order but stores them internally in column-major order.

Parameters
m00Row 0, Col 0
m01Row 0, Col 1
m02Row 0, Col 2
m10Row 1, Col 0
m11Row 1, Col 1
m12Row 1, Col 2
m20Row 2, Col 0
m21Row 2, Col 1
m22Row 2, Col 2

Example: Matrix3x3 m(1, 2, 3, 4, 5, 6, 7, 8, 9); // m(1, 0) == 4, m(0, 1) == 2

Definition at line 75 of file Matrix3x3.hpp.

Member Function Documentation

◆ Antisymmetric()

template<typename T >
constexpr auto Phyth::Matrix< 3, 3, T >::Antisymmetric ( ) const
inlineconstexpr

Compute the antisymmetric part of the matrix.

Returns (M - M^T) / 2

Returns
Matrix3x3 Antisymmetric part

Example: auto anti = m.Antisymmetric(); // (m - m^T) / 2

Definition at line 157 of file Matrix3x3.hpp.

◆ As()

template<typename T >
template<typename UnitT >
Matrix3x3< Quantity< UnitT > > Phyth::Matrix< 3, 3, T >::As ( ) const
inline

Convert all components to a different unit of the same dimension.

Template Parameters
UnitTTarget unit type
Returns
Matrix3x3<Quantity<UnitT>> Matrix with components converted to the new unit

Example: auto m_mm = m.as<Millimeter>();

Definition at line 444 of file Matrix3x3.hpp.

◆ At() [1/2]

template<typename T >
T & Phyth::Matrix< 3, 3, T >::At ( const int  i,
const int  j 
)
inline

Access element at row i, column j with bounds checking (0-based indexing) - mutable version.

Parameters
iRow index (0, 1, 2)
jColumn index (0, 1, 2)
Returns
T& Element value
Exceptions
std::out_of_rangeif index is out of bounds

Example: m.at(0, 1) = 5; // Set element at row 0, column 1 to 5

Definition at line 195 of file Matrix3x3.hpp.

◆ At() [2/2]

template<typename T >
const T & Phyth::Matrix< 3, 3, T >::At ( const int  i,
const int  j 
) const
inline

Access element at row i, column j with bounds checking (0-based indexing)

Parameters
iRow index (0, 1, 2)
jColumn index (0, 1, 2)
Returns
const T& Element value
Exceptions
std::out_of_rangeif index is out of bounds

Example: auto val = m.at(1, 2); // Get element at row 1, column 2

Definition at line 172 of file Matrix3x3.hpp.

◆ Identity()

template<typename T >
static constexpr Matrix Phyth::Matrix< 3, 3, T >::Identity ( )
inlinestaticconstexpr

Create an identity matrix.

Returns a 3x3 identity matrix with ones on the diagonal and zeros elsewhere.

Returns
Matrix3x3 Identity matrix

Example: auto I = Matrix3x3<Quantity<Meter>>::Identity();

Definition at line 94 of file Matrix3x3.hpp.

◆ operator!=()

template<typename T >
template<typename U >
constexpr bool Phyth::Matrix< 3, 3, T >::operator!= ( const Matrix3x3< U > &  other) const
inlineconstexpr

Inequality comparison.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to compare against
Returns
true if any corresponding component differs

Example: if (m1 != m2) { ... }

Definition at line 430 of file Matrix3x3.hpp.

◆ operator()() [1/2]

template<typename T >
constexpr T & Phyth::Matrix< 3, 3, T >::operator() ( const int  i,
const int  j 
)
inlineconstexpr

Access element at row i, column j (0-based indexing) - mutable version.

Parameters
iRow index (0, 1, 2)
jColumn index (0, 1, 2)
Returns
T& Element value
Note
Matrix is stored in column-major order internally
Warning
No bounds checking is performed. Use at() for safe access.

Example: m(0, 1) = 5; // Set element at row 0, column 1 to 5

Definition at line 239 of file Matrix3x3.hpp.

◆ operator()() [2/2]

template<typename T >
constexpr const T & Phyth::Matrix< 3, 3, T >::operator() ( const int  i,
const int  j 
) const
inlineconstexpr

Access element at row i, column j (0-based indexing) - no bounds checking.

Parameters
iRow index (0, 1, 2)
jColumn index (0, 1, 2)
Returns
const T& Element value
Note
Matrix is stored in column-major order internally
Warning
No bounds checking is performed. Use at() for safe access.

Example: auto val = m(1, 2); // Get element at row 1, column 2

Definition at line 220 of file Matrix3x3.hpp.

◆ operator*() [1/3]

template<typename T >
template<typename U >
constexpr auto Phyth::Matrix< 3, 3, T >::operator* ( const Matrix3x3< U > &  other) const
inlineconstexpr

Matrix-matrix multiplication: A * B.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to multiply with
Returns
Matrix3x3<decltype(*this * other.x_basis)> Product of the two matrices

Example: auto product = m1 * m2;

Definition at line 341 of file Matrix3x3.hpp.

◆ operator*() [2/3]

template<typename T >
template<typename U >
constexpr auto Phyth::Matrix< 3, 3, T >::operator* ( const Vector3< U > &  v) const
inlineconstexpr

Matrix-vector multiplication: M * v.

Template Parameters
UQuantity type of the vector
Parameters
vVector to multiply with
Returns
auto Resulting vector

Example: auto v = m * Vector3<Quantity<Meter>>(1, 2, 3);

Definition at line 325 of file Matrix3x3.hpp.

◆ operator*() [3/3]

template<typename T >
template<typename U >
constexpr auto Phyth::Matrix< 3, 3, T >::operator* ( U  scalar) const
inlineconstexpr

Scalar multiplication (matrix * scalar)

Template Parameters
UScalar type
Parameters
scalarScalar value to multiply with
Returns
Matrix3x3<decltype(x_basis * scalar)> Matrix scaled by scalar

Example: auto scaled = m * 2.0;

Definition at line 306 of file Matrix3x3.hpp.

◆ operator*=()

template<typename T >
template<typename U >
constexpr Matrix & Phyth::Matrix< 3, 3, T >::operator*= ( U  scalar)
inlineconstexpr

Scalar multiplication assignment.

Template Parameters
UScalar type
Parameters
scalarScalar value to multiply with
Returns
Matrix3x3& Reference to this matrix

Example: m *= 2.0;

Definition at line 397 of file Matrix3x3.hpp.

◆ operator+()

template<typename T >
template<typename U >
constexpr auto Phyth::Matrix< 3, 3, T >::operator+ ( const Matrix3x3< U > &  other) const
inlineconstexpr

Matrix addition.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to add
Returns
Matrix3x3<decltype(x_basis + other.x_basis)> Sum of the two matrices

Example: auto sum = m1 + m2;

Definition at line 256 of file Matrix3x3.hpp.

◆ operator+=()

template<typename T >
template<typename U >
constexpr Matrix & Phyth::Matrix< 3, 3, T >::operator+= ( const Matrix3x3< U > &  other)
inlineconstexpr

Addition assignment.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to add
Returns
Matrix3x3& Reference to this matrix

Example: m += other;

Definition at line 361 of file Matrix3x3.hpp.

◆ operator-() [1/2]

template<typename T >
constexpr auto Phyth::Matrix< 3, 3, T >::operator- ( ) const
inlineconstexpr

Unary negation.

Returns
Matrix3x3 Negated matrix

Example: auto neg = -m;

Definition at line 291 of file Matrix3x3.hpp.

◆ operator-() [2/2]

template<typename T >
template<typename U >
constexpr auto Phyth::Matrix< 3, 3, T >::operator- ( const Matrix3x3< U > &  other) const
inlineconstexpr

Matrix subtraction.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to subtract
Returns
Matrix3x3<decltype(x_basis - other.x_basis)> Difference of the two matrices

Example: auto diff = m1 - m2;

Definition at line 275 of file Matrix3x3.hpp.

◆ operator-=()

template<typename T >
template<typename U >
constexpr Matrix & Phyth::Matrix< 3, 3, T >::operator-= ( const Matrix3x3< U > &  other)
inlineconstexpr

Subtraction assignment.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to subtract
Returns
Matrix3x3& Reference to this matrix

Example: m -= other;

Definition at line 379 of file Matrix3x3.hpp.

◆ operator==()

template<typename T >
template<typename U >
constexpr bool Phyth::Matrix< 3, 3, T >::operator== ( const Matrix3x3< U > &  other) const
inlineconstexpr

Equality comparison.

Template Parameters
UQuantity type of the other matrix
Parameters
otherMatrix to compare against
Returns
true if all corresponding components are equal

Example: if (m1 == m2) { ... }

Definition at line 415 of file Matrix3x3.hpp.

◆ Symmetric()

template<typename T >
constexpr auto Phyth::Matrix< 3, 3, T >::Symmetric ( ) const
inlineconstexpr

Compute the symmetric part of the matrix.

Returns (M + M^T) / 2

Returns
Matrix3x3 Symmetric part

Example: auto sym = m.Symmetric(); // (m + m^T) / 2

Definition at line 143 of file Matrix3x3.hpp.

◆ Trace()

template<typename T >
constexpr T Phyth::Matrix< 3, 3, T >::Trace ( ) const
inlineconstexpr

Compute the trace of the matrix.

The trace is the sum of the diagonal elements: M[0][0] + M[1][1] + M[2][2]

Returns
T Sum of diagonal elements

Example: auto tr = m.Trace(); // m00 + m11 + m22

Definition at line 129 of file Matrix3x3.hpp.

◆ Transpose()

template<typename T >
constexpr Matrix Phyth::Matrix< 3, 3, T >::Transpose ( ) const
inlineconstexpr

Compute the transpose of the matrix.

Returns
Matrix3x3 Transposed matrix

Example: auto m = Matrix3x3(...); auto mT = m.Transpose();

Definition at line 111 of file Matrix3x3.hpp.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  os,
const Matrix< 3, 3, T > &  m 
)
friend

Stream insertion operator.

Parameters
osOutput stream
mMatrix to output
Returns
std::ostream& Reference to the output stream

Example: std::cout << m << std::endl;

Definition at line 462 of file Matrix3x3.hpp.

Member Data Documentation

◆ x_basis

template<typename T >
Vector3<T> Phyth::Matrix< 3, 3, T >::x_basis

Definition at line 30 of file Matrix3x3.hpp.

◆ y_basis

template<typename T >
Vector3<T> Phyth::Matrix< 3, 3, T >::y_basis

Definition at line 31 of file Matrix3x3.hpp.

◆ z_basis

template<typename T >
Vector3<T> Phyth::Matrix< 3, 3, T >::z_basis

Definition at line 32 of file Matrix3x3.hpp.


The documentation for this struct was generated from the following file: