17 #ifndef GZ_MATH_MATRIX6_HH_
18 #define GZ_MATH_MATRIX6_HH_
21 #include <gz/math/config.hh>
30 inline namespace IGNITION_MATH_VERSION_NAMESPACE {
69 memset(this->data, 0,
sizeof(this->data[0][0])*MatrixSize*MatrixSize);
113 public: constexpr
Matrix6(T _v00, T _v01, T _v02, T _v03, T _v04, T _v05,
114 T _v10, T _v11, T _v12, T _v13, T _v14, T _v15,
115 T _v20, T _v21, T _v22, T _v23, T _v24, T _v25,
116 T _v30, T _v31, T _v32, T _v33, T _v34, T _v35,
117 T _v40, T _v41, T _v42, T _v43, T _v44, T _v45,
118 T _v50, T _v51, T _v52, T _v53, T _v54, T _v55)
119 : data{{_v00, _v01, _v02, _v03, _v04, _v05},
120 {_v10, _v11, _v12, _v13, _v14, _v15},
121 {_v20, _v21, _v22, _v23, _v24, _v25},
122 {_v30, _v31, _v32, _v33, _v34, _v35},
123 {_v40, _v41, _v42, _v43, _v44, _v45},
124 {_v50, _v51, _v52, _v53, _v54, _v55}}
133 public:
bool SetValue(
size_t _row,
size_t _col, T _v)
135 if (_row < MatrixSize && _col < MatrixSize)
137 this->data[_row][_col] = _v;
181 T _v00, T _v01, T _v02, T _v03, T _v04, T _v05,
182 T _v10, T _v11, T _v12, T _v13, T _v14, T _v15,
183 T _v20, T _v21, T _v22, T _v23, T _v24, T _v25,
184 T _v30, T _v31, T _v32, T _v33, T _v34, T _v35,
185 T _v40, T _v41, T _v42, T _v43, T _v44, T _v45,
186 T _v50, T _v51, T _v52, T _v53, T _v54, T _v55)
188 this->data[0][0] = _v00;
189 this->data[0][1] = _v01;
190 this->data[0][2] = _v02;
191 this->data[0][3] = _v03;
192 this->data[0][4] = _v04;
193 this->data[0][5] = _v05;
195 this->data[1][0] = _v10;
196 this->data[1][1] = _v11;
197 this->data[1][2] = _v12;
198 this->data[1][3] = _v13;
199 this->data[1][4] = _v14;
200 this->data[1][5] = _v15;
202 this->data[2][0] = _v20;
203 this->data[2][1] = _v21;
204 this->data[2][2] = _v22;
205 this->data[2][3] = _v23;
206 this->data[2][4] = _v24;
207 this->data[2][5] = _v25;
209 this->data[3][0] = _v30;
210 this->data[3][1] = _v31;
211 this->data[3][2] = _v32;
212 this->data[3][3] = _v33;
213 this->data[3][4] = _v34;
214 this->data[3][5] = _v35;
216 this->data[4][0] = _v40;
217 this->data[4][1] = _v41;
218 this->data[4][2] = _v42;
219 this->data[4][3] = _v43;
220 this->data[4][4] = _v44;
221 this->data[4][5] = _v45;
223 this->data[5][0] = _v50;
224 this->data[5][1] = _v51;
225 this->data[5][2] = _v52;
226 this->data[5][3] = _v53;
227 this->data[5][4] = _v54;
228 this->data[5][5] = _v55;
234 std::swap(this->data[0][1], this->data[1][0]);
235 std::swap(this->data[0][2], this->data[2][0]);
236 std::swap(this->data[0][3], this->data[3][0]);
237 std::swap(this->data[0][4], this->data[4][0]);
238 std::swap(this->data[0][5], this->data[5][0]);
239 std::swap(this->data[1][2], this->data[2][1]);
240 std::swap(this->data[1][3], this->data[3][1]);
241 std::swap(this->data[1][4], this->data[4][1]);
242 std::swap(this->data[1][5], this->data[5][1]);
243 std::swap(this->data[2][3], this->data[3][2]);
244 std::swap(this->data[2][4], this->data[4][2]);
245 std::swap(this->data[2][5], this->data[5][2]);
246 std::swap(this->data[3][4], this->data[4][3]);
247 std::swap(this->data[3][5], this->data[5][3]);
248 std::swap(this->data[4][5], this->data[5][4]);
310 (*this) = (*this) * _m2;
319 auto el = [&](
size_t _row,
size_t _col) -> T
321 T result =
static_cast<T
>(0);
322 for (
size_t i = 0; i < MatrixSize; ++i)
323 result += this->data[_row][i] * _m2(i, _col);
327 el(0, 0), el(0, 1), el(0, 2), el(0, 3), el(0, 4), el(0, 5),
328 el(1, 0), el(1, 1), el(1, 2), el(1, 3), el(1, 4), el(1, 5),
329 el(2, 0), el(2, 1), el(2, 2), el(2, 3), el(2, 4), el(2, 5),
330 el(3, 0), el(3, 1), el(3, 2), el(3, 3), el(3, 4), el(3, 5),
331 el(4, 0), el(4, 1), el(4, 2), el(4, 3), el(4, 4), el(4, 5),
332 el(5, 0), el(5, 1), el(5, 2), el(5, 3), el(5, 4), el(5, 5));
341 (*this) = (*this) + _m2;
350 auto el = [&](
size_t _row,
size_t _col) -> T
352 return this->data[_row][_col] + _m2(_row, _col);
355 el(0, 0), el(0, 1), el(0, 2), el(0, 3), el(0, 4), el(0, 5),
356 el(1, 0), el(1, 1), el(1, 2), el(1, 3), el(1, 4), el(1, 5),
357 el(2, 0), el(2, 1), el(2, 2), el(2, 3), el(2, 4), el(2, 5),
358 el(3, 0), el(3, 1), el(3, 2), el(3, 3), el(3, 4), el(3, 5),
359 el(4, 0), el(4, 1), el(4, 2), el(4, 3), el(4, 4), el(4, 5),
360 el(5, 0), el(5, 1), el(5, 2), el(5, 3), el(5, 4), el(5, 5));
370 const size_t _col)
const
383 public:
inline T &
operator()(
const size_t _row,
const size_t _col)
398 if (_corner == BOTTOM_LEFT || _corner == BOTTOM_RIGHT)
402 if (_corner == TOP_RIGHT || _corner == BOTTOM_RIGHT)
406 return {this->data[row + 0][col + 0],
407 this->data[row + 0][col + 1],
408 this->data[row + 0][col + 2],
409 this->data[row + 1][col + 0],
410 this->data[row + 1][col + 1],
411 this->data[row + 1][col + 2],
412 this->data[row + 2][col + 0],
413 this->data[row + 2][col + 1],
414 this->data[row + 2][col + 2]};
426 if (_corner == BOTTOM_LEFT || _corner == BOTTOM_RIGHT)
430 if (_corner == TOP_RIGHT || _corner == BOTTOM_RIGHT)
434 for (
size_t r = 0; r < 3; ++r)
436 for (
size_t c = 0; c < 3; ++c)
438 this->data[row + r][col + c] = _mat(r, c);
450 return equal<T>(this->data[0][0], _m(0, 0), _tol)
451 && equal<T>(this->data[0][1], _m(0, 1), _tol)
452 && equal<T>(this->data[0][2], _m(0, 2), _tol)
453 && equal<T>(this->data[0][3], _m(0, 3), _tol)
454 && equal<T>(this->data[0][4], _m(0, 4), _tol)
455 && equal<T>(this->data[0][5], _m(0, 5), _tol)
456 && equal<T>(this->data[1][0], _m(1, 0), _tol)
457 && equal<T>(this->data[1][1], _m(1, 1), _tol)
458 && equal<T>(this->data[1][2], _m(1, 2), _tol)
459 && equal<T>(this->data[1][3], _m(1, 3), _tol)
460 && equal<T>(this->data[1][4], _m(1, 4), _tol)
461 && equal<T>(this->data[1][5], _m(1, 5), _tol)
462 && equal<T>(this->data[2][0], _m(2, 0), _tol)
463 && equal<T>(this->data[2][1], _m(2, 1), _tol)
464 && equal<T>(this->data[2][2], _m(2, 2), _tol)
465 && equal<T>(this->data[2][3], _m(2, 3), _tol)
466 && equal<T>(this->data[2][4], _m(2, 4), _tol)
467 && equal<T>(this->data[2][5], _m(2, 5), _tol)
468 && equal<T>(this->data[3][0], _m(3, 0), _tol)
469 && equal<T>(this->data[3][1], _m(3, 1), _tol)
470 && equal<T>(this->data[3][2], _m(3, 2), _tol)
471 && equal<T>(this->data[3][3], _m(3, 3), _tol)
472 && equal<T>(this->data[3][4], _m(3, 4), _tol)
473 && equal<T>(this->data[3][5], _m(3, 5), _tol)
474 && equal<T>(this->data[4][0], _m(4, 0), _tol)
475 && equal<T>(this->data[4][1], _m(4, 1), _tol)
476 && equal<T>(this->data[4][2], _m(4, 2), _tol)
477 && equal<T>(this->data[4][3], _m(4, 3), _tol)
478 && equal<T>(this->data[4][4], _m(4, 4), _tol)
479 && equal<T>(this->data[4][5], _m(4, 5), _tol)
480 && equal<T>(this->data[5][0], _m(5, 0), _tol)
481 && equal<T>(this->data[5][1], _m(5, 1), _tol)
482 && equal<T>(this->data[5][2], _m(5, 2), _tol)
483 && equal<T>(this->data[5][3], _m(5, 3), _tol)
484 && equal<T>(this->data[5][4], _m(5, 4), _tol)
485 && equal<T>(this->data[5][5], _m(5, 5), _tol);
494 return this->Equal(_m,
static_cast<T
>(1e-6));
502 return !(*
this == _m);
512 for (
auto i : {0, 1, 2, 3, 4, 5})
514 for (
auto j : {0, 1, 2, 3, 4, 5})
516 if (!(i == 0 && j == 0))
534 _in.
setf(std::ios_base::skipws);
536 _in >> d[0] >> d[1] >> d[2] >> d[3] >> d[4] >> d[5]
537 >> d[6] >> d[7] >> d[8] >> d[9] >> d[10] >> d[11]
538 >> d[12] >> d[13] >> d[14] >> d[15] >> d[16] >> d[17]
539 >> d[18] >> d[19] >> d[20] >> d[21] >> d[22] >> d[23]
540 >> d[24] >> d[25] >> d[26] >> d[27] >> d[28] >> d[29]
541 >> d[30] >> d[31] >> d[32] >> d[33] >> d[34] >> d[35];
545 _m.Set(d[0], d[1], d[2], d[3], d[4], d[5],
546 d[6], d[7], d[8], d[9], d[10], d[11],
547 d[12], d[13], d[14], d[15], d[16], d[17],
548 d[18], d[19], d[20], d[21], d[22], d[23],
549 d[24], d[25], d[26], d[27], d[28], d[29],
550 d[30], d[31], d[32], d[33], d[34], d[35]);
556 private: T data[MatrixSize][MatrixSize];
562 constexpr Matrix6<T> gMatrix6Identity(
571 constexpr Matrix6<T> gMatrix6Zero(
A 3x3 matrix class.
Definition: gz/math/Matrix3.hh:41
A 6x6 matrix class.
Definition: gz/math/Matrix6.hh:36
Matrix6< T > operator+(const Matrix6< T > &_m2) const
Addition operator.
Definition: gz/math/Matrix6.hh:348
bool operator==(const Matrix6< T > &_m) const
Equality operator.
Definition: gz/math/Matrix6.hh:492
void Transpose()
Transpose this matrix.
Definition: gz/math/Matrix6.hh:232
static const Matrix6< T > & Identity
Identity matrix.
Definition: gz/math/Matrix6.hh:61
bool Equal(const Matrix6 &_m, const T &_tol) const
Equality test with tolerance.
Definition: gz/math/Matrix6.hh:448
bool SetValue(size_t _row, size_t _col, T _v)
Set a value in a specific row and col param[in] _row Row of the matrix param[in] _col Col of the matr...
Definition: gz/math/Matrix6.hh:133
Matrix6< T > & operator=(const Matrix6< T > &_mat)=default
Assignment operator. this = _mat.
Matrix3< T > Submatrix(Matrix6Corner _corner) const
Get one of the four 3x3 submatrices that compose this matrix. These submatrices are formed by dividin...
Definition: gz/math/Matrix6.hh:394
Matrix6< T > Transposed() const
Return the transpose of this matrix.
Definition: gz/math/Matrix6.hh:253
friend std::ostream & operator<<(std::ostream &_out, const Matrix6< T > &_m)
Stream insertion operator.
Definition: gz/math/Matrix6.hh:509
Matrix6()
Constructor.
Definition: gz/math/Matrix6.hh:67
constexpr Matrix6(T _v00, T _v01, T _v02, T _v03, T _v04, T _v05, T _v10, T _v11, T _v12, T _v13, T _v14, T _v15, T _v20, T _v21, T _v22, T _v23, T _v24, T _v25, T _v30, T _v31, T _v32, T _v33, T _v34, T _v35, T _v40, T _v41, T _v42, T _v43, T _v44, T _v45, T _v50, T _v51, T _v52, T _v53, T _v54, T _v55)
Constructor.
Definition: gz/math/Matrix6.hh:113
bool operator!=(const Matrix6< T > &_m) const
Inequality test operator.
Definition: gz/math/Matrix6.hh:500
Matrix6< T > operator*(const Matrix6< T > &_m2) const
Multiplication operator.
Definition: gz/math/Matrix6.hh:317
void SetSubmatrix(Matrix6Corner _corner, const Matrix3< T > &_mat)
Set one of the four 3x3 submatrices that compose this matrix. These submatrices are formed by dividin...
Definition: gz/math/Matrix6.hh:422
friend std::istream & operator>>(std::istream &_in, Matrix6< T > &_m)
Stream extraction operator.
Definition: gz/math/Matrix6.hh:530
const T & operator()(const size_t _row, const size_t _col) const
Get the value at the specified row, column index.
Definition: gz/math/Matrix6.hh:369
Matrix6< T > operator+=(const Matrix6< T > &_m2)
Addition assignment operator. This matrix will become equal to this + _m2.
Definition: gz/math/Matrix6.hh:339
Matrix6(const Matrix6< T > &_m)=default
Copy constructor.
static const Matrix6< T > & Zero
Zero matrix.
Definition: gz/math/Matrix6.hh:64
Matrix6< T > operator*=(const Matrix6< T > &_m2)
Multiplication assignment operator. This matrix will become equal to this * _m2.
Definition: gz/math/Matrix6.hh:308
Matrix6Corner
Identifiers for each of the 4 3x3 corners of the matrix.
Definition: gz/math/Matrix6.hh:39
T & operator()(const size_t _row, const size_t _col)
Get a mutable version of the value at the specified row, column index.
Definition: gz/math/Matrix6.hh:383
void Set(T _v00, T _v01, T _v02, T _v03, T _v04, T _v05, T _v10, T _v11, T _v12, T _v13, T _v14, T _v15, T _v20, T _v21, T _v22, T _v23, T _v24, T _v25, T _v30, T _v31, T _v32, T _v33, T _v34, T _v35, T _v40, T _v41, T _v42, T _v43, T _v44, T _v45, T _v50, T _v51, T _v52, T _v53, T _v54, T _v55)
Change the values.
Definition: gz/math/Matrix6.hh:180
static const size_t IGN_FIVE_SIZE_T
size_t type with a value of 5
Definition: gz/math/Helpers.hh:242
static const size_t IGN_ZERO_SIZE_T
size_t type with a value of 0
Definition: gz/math/Helpers.hh:227
Matrix6< int > Matrix6i
Definition: gz/math/Matrix6.hh:587
Matrix6< float > Matrix6f
Definition: gz/math/Matrix6.hh:589
T clamp(T _v, T _min, T _max)
Simple clamping function.
Definition: gz/math/Helpers.hh:406
void appendToStream(std::ostream &_out, T _number)
Append a number to a stream. Makes sure "-0" is returned as "0".
Definition: gz/math/Helpers.hh:626
Matrix6< double > Matrix6d
Definition: gz/math/Matrix6.hh:588
Definition: gz/math/AdditivelySeparableScalarField3.hh:28