1#ifndef PHYTH_MATRIX3X3_HPP
2#define PHYTH_MATRIX3X3_HPP
39 constexpr Matrix() : x_basis(0, 0, 0), y_basis(0, 0, 0), z_basis(0, 0, 0) {
113 x_basis.
x, y_basis.
x, z_basis.
x,
114 x_basis.
y, y_basis.
y, z_basis.
y,
115 x_basis.
z, y_basis.
z, z_basis.
z
130 return x_basis.
x + y_basis.
y + z_basis.
z;
174 throw std::out_of_range(
"Matrix3x3::at: index out of range");
177 case 0:
return x_basis[
i];
178 case 1:
return y_basis[
i];
179 case 2:
return z_basis[
i];
180 default:
throw std::out_of_range(
"Matrix3x3::at: invalid column");
197 throw std::out_of_range(
"Matrix3x3::at: index out of range");
200 case 0:
return x_basis[
i];
201 case 1:
return y_basis[
i];
202 case 2:
return z_basis[
i];
203 default:
throw std::out_of_range(
"Matrix3x3::at: invalid column");
221 if (
j == 0)
return x_basis[
i];
222 if (
j == 1)
return y_basis[
i];
240 if (
j == 0)
return x_basis[
i];
241 if (
j == 1)
return y_basis[
i];
258 x_basis +
other.x_basis,
259 y_basis +
other.y_basis,
260 z_basis +
other.z_basis
277 x_basis -
other.x_basis,
278 y_basis -
other.y_basis,
279 z_basis -
other.z_basis
292 return Matrix(-x_basis, -y_basis, -z_basis);
327 return x_basis *
v.
x + y_basis *
v.
y + z_basis *
v.
z;
344 *
this *
other.x_basis,
345 *
this *
other.y_basis,
346 *
this *
other.z_basis
362 x_basis +=
other.x_basis;
363 y_basis +=
other.y_basis;
364 z_basis +=
other.z_basis;
380 x_basis -=
other.x_basis;
381 y_basis -=
other.y_basis;
382 z_basis -=
other.z_basis;
416 return x_basis ==
other.x_basis && y_basis ==
other.y_basis && z_basis ==
other.z_basis;
431 return !(*
this ==
other);
443 template<
typename UnitT>
463 os <<
"[" <<
m.x_basis.x <<
" " <<
m.y_basis.x <<
" " <<
m.z_basis.x <<
"\n"
464 <<
" " <<
m.x_basis.y <<
" " <<
m.y_basis.y <<
" " <<
m.z_basis.y <<
"\n"
465 <<
" " <<
m.x_basis.z <<
" " <<
m.y_basis.z <<
" " <<
m.z_basis.z <<
"]";
482 template<
typename T,
typename U>
constexpr auto operator*(Quantity< U1 > a, Quantity< U2 > b)
Multiply two quantities.
3x3 matrix with Quantity components
constexpr auto operator*(const Matrix3x3< U > &other) const
Matrix-matrix multiplication: A * B.
constexpr bool operator==(const Matrix3x3< U > &other) const
Equality comparison.
constexpr auto operator-(const Matrix3x3< U > &other) const
Matrix subtraction.
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 auto operator+(const Matrix3x3< U > &other) const
Matrix addition.
T & At(const int i, const int j)
Access element at row i, column j with bounds checking (0-based indexing) - mutable version.
static constexpr Matrix Identity()
Create an identity matrix.
const T & At(const int i, const int j) const
Access element at row i, column j with bounds checking (0-based indexing)
constexpr Matrix(const Vector3< T > &col0, const Vector3< T > &col1, const Vector3< T > &col2)
Construct from three column vectors.
friend std::ostream & operator<<(std::ostream &os, const Matrix &m)
Stream insertion operator.
constexpr Matrix & operator*=(U scalar)
Scalar multiplication assignment.
constexpr Matrix()
Construct a zero matrix.
constexpr auto operator-() const
Unary negation.
constexpr Matrix Transpose() const
Compute the transpose of the matrix.
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 bool operator!=(const Matrix3x3< U > &other) const
Inequality comparison.
constexpr auto Symmetric() const
Compute the symmetric part of the matrix.
constexpr auto operator*(U scalar) const
Scalar multiplication (matrix * scalar)
constexpr T & operator()(const int i, const int j)
Access element at row i, column j (0-based indexing) - mutable version.
constexpr auto operator*(const Vector3< U > &v) const
Matrix-vector multiplication: M * v.
Matrix3x3< Quantity< UnitT > > As() const
Convert all components to a different unit of the same dimension.
constexpr auto Antisymmetric() const
Compute the antisymmetric part of the matrix.
constexpr T Trace() const
Compute the trace of the matrix.
constexpr Matrix & operator+=(const Matrix3x3< U > &other)
Addition assignment.
constexpr Matrix & operator-=(const Matrix3x3< U > &other)
Subtraction assignment.
constexpr auto Transpose() const
3D vector with Quantity components