1#include "math/Vector3.hpp"
10#define n12 elements[1]
11#define n13 elements[2]
12#define n21 elements[3]
13#define n22 elements[4]
14#define n23 elements[5]
15#define n31 elements[6]
16#define n32 elements[7]
17#define n33 elements[8]
56 Matrix3x3(
double _n11,
double _n12,
double _n13,
double _n21,
double _n22,
57 double _n23,
double _n31,
double _n32,
double _n33)
58 :
elements({_n11, _n12, _n13, _n21, _n22, _n23, _n31, _n32, _n33}) {}
66 return Matrix3x3(n11, n12, n13, n21, n22, n23, n31, n32, n33);
76 for (
auto i = 0; i < 9; ++i) {
98 double _n22,
double _n23,
double _n31,
double _n32,
124 double get(
int row,
int column)
const {
125 return elements.at(row * 3 + column);
138 elements.at(row * 3 + column) = value;
156 return n11 * n22 * n33 + n12 * n23 * n31 + n13 * n21 * n32 -
157 n11 * n23 * n32 - n12 * n21 * n33 - n13 * n22 * n31;
169 return Matrix3x3(n11, n21, n31, n12, n22, n32, n13, n23, n33);
188 return Matrix3x3(0, 0, 0, 0, 0, 0, 0, 0, 0);
192 (n22 * n33 - n23 * n32) / det, (n13 * n32 - n12 * n33) / det,
193 (n12 * n23 - n13 * n22) / det, (n23 * n31 - n21 * n33) / det,
194 (n11 * n33 - n13 * n31) / det, (n13 * n21 - n11 * n23) / det,
195 (n21 * n32 - n22 * n31) / det, (n12 * n31 - n11 * n32) / det,
196 (n11 * n22 - n12 * n21) / det);
220 for (
int i = 0; i < 9; ++i) {
248 for (
int i = 0; i < 9; ++i) {
303 for (
int i = 0; i < 9; ++i) {
341 return Matrix3x3(a.n11 + b.n11, a.n12 + b.n12, a.n13 + b.n13, a.n21 + b.n21,
342 a.n22 + b.n22, a.n23 + b.n23, a.n31 + b.n31, a.n32 + b.n32,
354 return Matrix3x3(a.n11 + s, a.n12 + s, a.n13 + s, a.n21 + s, a.n22 + s,
355 a.n23 + s, a.n31 + s, a.n32 + s, a.n33 + s);
375 return Matrix3x3(a.n11 - b.n11, a.n12 - b.n12, a.n13 - b.n13, a.n21 - b.n21,
376 a.n22 - b.n22, a.n23 - b.n23, a.n31 - b.n31, a.n32 - b.n32,
389 return Matrix3x3(a.n11 - s, a.n12 - s, a.n13 - s, a.n21 - s, a.n22 - s,
390 a.n23 - s, a.n31 - s, a.n32 - s, a.n33 - s);
403 return Matrix3x3(s - a.n11, s - a.n12, s - a.n13, s - a.n21, s - a.n22,
404 s - a.n23, s - a.n31, s - a.n32, s - a.n33);
418 return Matrix3x3(a.n11 * b.n11 + a.n12 * b.n21 + a.n13 * b.n31,
419 a.n11 * b.n12 + a.n12 * b.n22 + a.n13 * b.n32,
420 a.n11 * b.n13 + a.n12 * b.n23 + a.n13 * b.n33,
421 a.n21 * b.n11 + a.n22 * b.n21 + a.n23 * b.n31,
422 a.n21 * b.n12 + a.n22 * b.n22 + a.n23 * b.n32,
423 a.n21 * b.n13 + a.n22 * b.n23 + a.n23 * b.n33,
424 a.n31 * b.n11 + a.n32 * b.n21 + a.n33 * b.n31,
425 a.n31 * b.n12 + a.n32 * b.n22 + a.n33 * b.n32,
426 a.n31 * b.n13 + a.n32 * b.n23 + a.n33 * b.n33);
438 return Matrix3x3(a.n11 * s, a.n12 * s, a.n13 * s, a.n21 * s, a.n22 * s,
439 a.n23 * s, a.n31 * s, a.n32 * s, a.n33 * s);
460 return Vector3(a.n11 * v.x + a.n12 * v.y + a.n13 * v.z,
461 a.n21 * v.x + a.n22 * v.y + a.n23 * v.z,
462 a.n31 * v.x + a.n32 * v.y + a.n33 * v.z);
473 return Matrix3x3(a.n11 / b.n11, a.n12 / b.n12, a.n13 / b.n13, a.n21 / b.n21,
474 a.n22 / b.n22, a.n23 / b.n23, a.n31 / b.n31, a.n32 / b.n32,
486 return Matrix3x3(a.n11 / s, a.n12 / s, a.n13 / s, a.n21 / s, a.n22 / s,
487 a.n23 / s, a.n31 / s, a.n32 / s, a.n33 / s);
499 return Matrix3x3(s / a.n11, s / a.n12, s / a.n13, s / a.n21, s / a.n22,
500 s / a.n23, s / a.n31, s / a.n32, s / a.n33);
The matrix class.
Definition Matrix3x3.hpp:24
Matrix3x3 & operator-=(double s)
Substracts the specified constant from all elements in this matrix.
Definition Matrix3x3.hpp:261
Matrix3x3 & operator*=(double s)
Multiplies the elements of this matrix with the specified constant.
Definition Matrix3x3.hpp:287
double determinant() const
Returns the determinant of this matrix.
Definition Matrix3x3.hpp:155
Matrix3x3 & set(int row, int column, int value)
Sets the element at the specified row and column of this matrix to the specified value.
Definition Matrix3x3.hpp:137
Matrix3x3 & reset()
Resets this matrix to the identity matrix.
Definition Matrix3x3.hpp:147
Matrix3x3 & operator/=(double s)
Divides the elements of this matrix with the specified constant.
Definition Matrix3x3.hpp:316
Matrix3x3 & operator+=(const Matrix3x3 &m)
Adds the specified matrix to this matrix.
Definition Matrix3x3.hpp:219
Matrix3x3(double _n11, double _n12, double _n13, double _n21, double _n22, double _n23, double _n31, double _n32, double _n33)
Creates a new matrix with the specified elements.
Definition Matrix3x3.hpp:56
Matrix3x3 & operator*=(const Matrix3x3 &m)
Multiplies this matrix with another matrix and copies the result into this instance.
Definition Matrix3x3.hpp:279
friend Vector3 operator*(const Matrix3x3 &a, const Vector3 &v)
Multiplies a matrix with a 3D vector.
Definition Matrix3x3.hpp:459
friend Matrix3x3 operator*(double s, const Matrix3x3 &a)
Multiplies all elements of a matrix with a constant.
Definition Matrix3x3.hpp:450
Matrix3x3 & operator+=(double s)
Adds the specified constant to all elements in this matrix.
Definition Matrix3x3.hpp:233
friend Matrix3x3 operator/(const Matrix3x3 &a, const Matrix3x3 &b)
Returns the element-wise division of two matrices.
Definition Matrix3x3.hpp:472
Matrix3x3 & set(double _n11, double _n12, double _n13, double _n21, double _n22, double _n23, double _n31, double _n32, double _n33)
Sets the elements of this matrix.
Definition Matrix3x3.hpp:97
Matrix3x3 clone() const
Returns a copy of this matrix.
Definition Matrix3x3.hpp:65
double operator[](std::size_t index) const
Returns the element at the specified index of this matrix without bounds checking and assuming row-ma...
Definition Matrix3x3.hpp:211
friend Matrix3x3 operator-(double s, const Matrix3x3 &a)
Substracts a matrix from a constant matrix.
Definition Matrix3x3.hpp:402
friend Matrix3x3 operator+(const Matrix3x3 &a, const Matrix3x3 &b)
Adds two matrices.
Definition Matrix3x3.hpp:340
Matrix3x3 transpose() const
Returns the transpose of this matrix.
Definition Matrix3x3.hpp:168
friend Matrix3x3 operator+(double s, const Matrix3x3 &a)
Adds a constant to all elements of a matrix.
Definition Matrix3x3.hpp:365
friend Matrix3x3 operator/(const Matrix3x3 &a, double s)
Divides all elements of a matrix by a constant.
Definition Matrix3x3.hpp:485
friend Matrix3x3 operator-(const Matrix3x3 &a, double s)
Substracts a constant from all elements of a matrix.
Definition Matrix3x3.hpp:388
Matrix3x3 & operator/=(const Matrix3x3 &m)
Divides the elements of this matrix by the corresponding elements of the specified matrix.
Definition Matrix3x3.hpp:302
static Matrix3x3 identity()
Returns a identity matrix.
Definition Matrix3x3.hpp:34
friend Matrix3x3 operator/(double s, const Matrix3x3 &a)
Returns the element-wise division of a constant matrix and a matrix.
Definition Matrix3x3.hpp:498
friend Matrix3x3 operator+(const Matrix3x3 &a, double s)
Adds a constant to all elements of a matrix.
Definition Matrix3x3.hpp:353
std::array< double, 9 > elements
The array containing the elements of this matrix in row-major order.
Definition Matrix3x3.hpp:26
friend Matrix3x3 operator*(const Matrix3x3 &a, const Matrix3x3 &b)
Multiplies two matrices.
Definition Matrix3x3.hpp:417
double get(int row, int column) const
Gets the element at the specified row and column of this matrix with bounds checking.
Definition Matrix3x3.hpp:124
friend Matrix3x3 operator-(const Matrix3x3 &a, const Matrix3x3 &b)
Substracts 2 matrices.
Definition Matrix3x3.hpp:374
Matrix3x3 & operator-=(const Matrix3x3 &m)
Substracts the specified matrix from this matrix.
Definition Matrix3x3.hpp:247
Matrix3x3 & copy(const Matrix3x3 &source)
Copies the elements of another matrix into this matrix.
Definition Matrix3x3.hpp:75
friend Matrix3x3 operator*(const Matrix3x3 &a, double s)
Multiplies all elements of a matrix with a constant.
Definition Matrix3x3.hpp:437
friend bool operator==(const Matrix3x3 &a, const Matrix3x3 &b)=default
Returns whether two matrices are equal.
Matrix3x3 inverse() const
Returns the inverse of this matrix or the zero matrix if this matrix does not have an inverse.
Definition Matrix3x3.hpp:184
static Matrix3x3 zero()
Returns a zero matrix.
Definition Matrix3x3.hpp:41
The 3D vector class.
Definition Vector3.hpp:20
The t software 3D graphics library namespace.
Definition algorithms.hpp:12