9 #ifndef CUBBYFLOW_MATRIX3X3_IMPL_H 10 #define CUBBYFLOW_MATRIX3X3_IMPL_H 93 size_t height = list.size();
94 size_t width = (height > 0) ? list.begin()->size() : 0;
99 auto rowIter = list.begin();
100 for (
size_t i = 0; i < height; ++i)
102 assert(width == rowIter->size());
104 auto colIter = rowIter->begin();
105 for (
size_t j = 0; j < width; ++j)
107 (*this)(i, j) = static_cast<T>(*colIter);
115 template <
typename T>
118 for (
size_t i = 0; i < 9; ++i)
120 m_elements[i] = m.m_elements[i];
124 template <
typename T>
127 for (
size_t i = 0; i < 9; ++i)
129 m_elements[i] = arr[i];
133 template <
typename T>
141 template <
typename T>
152 template <
typename T>
155 m_elements[i * 3] = row.
x;
156 m_elements[i * 3 + 1] = row.
y;
157 m_elements[i * 3 + 2] = row.
z;
160 template <
typename T>
163 m_elements[i] = col.
x;
164 m_elements[i + 3] = col.
y;
165 m_elements[i + 6] = col.
z;
168 template <
typename T>
172 std::fabs(m_elements[0] - m.m_elements[0]) < tol &&
173 std::fabs(m_elements[1] - m.m_elements[1]) < tol &&
174 std::fabs(m_elements[2] - m.m_elements[2]) < tol &&
175 std::fabs(m_elements[3] - m.m_elements[3]) < tol &&
176 std::fabs(m_elements[4] - m.m_elements[4]) < tol &&
177 std::fabs(m_elements[5] - m.m_elements[5]) < tol &&
178 std::fabs(m_elements[6] - m.m_elements[6]) < tol &&
179 std::fabs(m_elements[7] - m.m_elements[7]) < tol &&
180 std::fabs(m_elements[8] - m.m_elements[8]) < tol;
183 template <
typename T>
189 template <
typename T>
195 template <
typename T>
201 template <
typename T>
204 return m_elements.data();
207 template <
typename T>
210 return m_elements.data();
213 template <
typename T>
217 m_elements[0] + s, m_elements[1] + s, m_elements[2] + s,
218 m_elements[3] + s, m_elements[4] + s, m_elements[5] + s,
219 m_elements[6] + s, m_elements[7] + s, m_elements[8] + s);
222 template <
typename T>
226 m_elements[0] + m.m_elements[0], m_elements[1] + m.m_elements[1], m_elements[2] + m.m_elements[2],
227 m_elements[3] + m.m_elements[3], m_elements[4] + m.m_elements[4], m_elements[5] + m.m_elements[5],
228 m_elements[6] + m.m_elements[6], m_elements[7] + m.m_elements[7], m_elements[8] + m.m_elements[8]);
231 template <
typename T>
235 m_elements[0] - s, m_elements[1] - s, m_elements[2] - s,
236 m_elements[3] - s, m_elements[4] - s, m_elements[5] - s,
237 m_elements[6] - s, m_elements[7] - s, m_elements[8] - s);
240 template <
typename T>
244 m_elements[0] - m.m_elements[0], m_elements[1] - m.m_elements[1], m_elements[2] - m.m_elements[2],
245 m_elements[3] - m.m_elements[3], m_elements[4] - m.m_elements[4], m_elements[5] - m.m_elements[5],
246 m_elements[6] - m.m_elements[6], m_elements[7] - m.m_elements[7], m_elements[8] - m.m_elements[8]);
249 template <
typename T>
253 m_elements[0] * s, m_elements[1] * s, m_elements[2] * s,
254 m_elements[3] * s, m_elements[4] * s, m_elements[5] * s,
255 m_elements[6] * s, m_elements[7] * s, m_elements[8] * s);
258 template <
typename T>
262 v.
x * m_elements[0] + v.
y * m_elements[1] + v.
z * m_elements[2],
263 v.
x * m_elements[3] + v.
y * m_elements[4] + v.
z * m_elements[5],
264 v.
x * m_elements[6] + v.
y * m_elements[7] + v.
z * m_elements[8]);
267 template <
typename T>
271 m_elements[0] * m.m_elements[0] + m_elements[1] * m.m_elements[3] + m_elements[2] * m.m_elements[6],
272 m_elements[0] * m.m_elements[1] + m_elements[1] * m.m_elements[4] + m_elements[2] * m.m_elements[7],
273 m_elements[0] * m.m_elements[2] + m_elements[1] * m.m_elements[5] + m_elements[2] * m.m_elements[8],
275 m_elements[3] * m.m_elements[0] + m_elements[4] * m.m_elements[3] + m_elements[5] * m.m_elements[6],
276 m_elements[3] * m.m_elements[1] + m_elements[4] * m.m_elements[4] + m_elements[5] * m.m_elements[7],
277 m_elements[3] * m.m_elements[2] + m_elements[4] * m.m_elements[5] + m_elements[5] * m.m_elements[8],
279 m_elements[6] * m.m_elements[0] + m_elements[7] * m.m_elements[3] + m_elements[8] * m.m_elements[6],
280 m_elements[6] * m.m_elements[1] + m_elements[7] * m.m_elements[4] + m_elements[8] * m.m_elements[7],
281 m_elements[6] * m.m_elements[2] + m_elements[7] * m.m_elements[5] + m_elements[8] * m.m_elements[8]);
284 template <
typename T>
288 m_elements[0] / s, m_elements[1] / s, m_elements[2] / s,
289 m_elements[3] / s, m_elements[4] / s, m_elements[5] / s,
290 m_elements[6] / s, m_elements[7] / s, m_elements[8] / s);
293 template <
typename T>
297 s + m_elements[0], s + m_elements[1], s + m_elements[2],
298 s + m_elements[3], s + m_elements[4], s + m_elements[5],
299 s + m_elements[6], s + m_elements[7], s + m_elements[8]);
302 template <
typename T>
306 m.m_elements[0] + m_elements[0], m.m_elements[1] + m_elements[1], m.m_elements[2] + m_elements[2],
307 m.m_elements[3] + m_elements[3], m.m_elements[4] + m_elements[4], m.m_elements[5] + m_elements[5],
308 m.m_elements[6] + m_elements[6], m.m_elements[7] + m_elements[7], m.m_elements[8] + m_elements[8]);
311 template <
typename T>
315 s - m_elements[0], s - m_elements[1], s - m_elements[2],
316 s - m_elements[3], s - m_elements[4], s - m_elements[5],
317 s - m_elements[6], s - m_elements[7], s - m_elements[8]);
320 template <
typename T>
324 m.m_elements[0] - m_elements[0], m.m_elements[1] - m_elements[1], m.m_elements[2] - m_elements[2],
325 m.m_elements[3] - m_elements[3], m.m_elements[4] - m_elements[4], m.m_elements[5] - m_elements[5],
326 m.m_elements[6] - m_elements[6], m.m_elements[7] - m_elements[7], m.m_elements[8] - m_elements[8]);
329 template <
typename T>
333 s * m_elements[0], s * m_elements[1], s * m_elements[2],
334 s * m_elements[3], s * m_elements[4], s * m_elements[5],
335 s * m_elements[6], s * m_elements[7], s * m_elements[8]);
338 template <
typename T>
344 template <
typename T>
348 s / m_elements[0], s / m_elements[1], s / m_elements[2],
349 s / m_elements[3], s / m_elements[4], s / m_elements[5],
350 s / m_elements[6], s / m_elements[7], s / m_elements[8]);
353 template <
typename T>
367 template <
typename T>
370 m_elements[0] += m.m_elements[0];
371 m_elements[1] += m.m_elements[1];
372 m_elements[2] += m.m_elements[2];
373 m_elements[3] += m.m_elements[3];
374 m_elements[4] += m.m_elements[4];
375 m_elements[5] += m.m_elements[5];
376 m_elements[6] += m.m_elements[6];
377 m_elements[7] += m.m_elements[7];
378 m_elements[8] += m.m_elements[8];
381 template <
typename T>
395 template <
typename T>
398 m_elements[0] -= m.m_elements[0];
399 m_elements[1] -= m.m_elements[1];
400 m_elements[2] -= m.m_elements[2];
401 m_elements[3] -= m.m_elements[3];
402 m_elements[4] -= m.m_elements[4];
403 m_elements[5] -= m.m_elements[5];
404 m_elements[6] -= m.m_elements[6];
405 m_elements[7] -= m.m_elements[7];
406 m_elements[8] -= m.m_elements[8];
409 template <
typename T>
423 template <
typename T>
429 template <
typename T>
443 template <
typename T>
446 std::swap(m_elements[1], m_elements[3]);
447 std::swap(m_elements[2], m_elements[6]);
448 std::swap(m_elements[5], m_elements[7]);
451 template <
typename T>
457 m.m_elements[0] = m_elements[4] * m_elements[8] - m_elements[5] * m_elements[7];
458 m.m_elements[1] = m_elements[2] * m_elements[7] - m_elements[1] * m_elements[8];
459 m.m_elements[2] = m_elements[1] * m_elements[5] - m_elements[2] * m_elements[4];
460 m.m_elements[3] = m_elements[5] * m_elements[6] - m_elements[3] * m_elements[8];
461 m.m_elements[4] = m_elements[0] * m_elements[8] - m_elements[2] * m_elements[6];
462 m.m_elements[5] = m_elements[2] * m_elements[3] - m_elements[0] * m_elements[5];
463 m.m_elements[6] = m_elements[3] * m_elements[7] - m_elements[4] * m_elements[6];
464 m.m_elements[7] = m_elements[1] * m_elements[6] - m_elements[0] * m_elements[7];
465 m.m_elements[8] = m_elements[0] * m_elements[4] - m_elements[1] * m_elements[3];
471 template <
typename T>
476 for (
size_t i = 0; i < 9; ++i)
478 sum += m_elements[i];
484 template <
typename T>
490 template <
typename T>
493 return m_elements[std::distance(std::begin(m_elements), std::min_element(std::begin(m_elements), std::end(m_elements)))];
496 template <
typename T>
499 return m_elements[std::distance(std::begin(m_elements), std::max_element(std::begin(m_elements), std::end(m_elements)))];
502 template <
typename T>
508 template <
typename T>
514 template <
typename T>
517 return m_elements[0] + m_elements[4] + m_elements[8];
520 template <
typename T>
524 m_elements[0] * m_elements[4] * m_elements[8] -
525 m_elements[0] * m_elements[5] * m_elements[7] +
526 m_elements[1] * m_elements[5] * m_elements[6] -
527 m_elements[1] * m_elements[3] * m_elements[8] +
528 m_elements[2] * m_elements[3] * m_elements[7] -
529 m_elements[2] * m_elements[4] * m_elements[6];
532 template <
typename T>
538 0, 0, m_elements[8]);
541 template <
typename T>
545 0, m_elements[1], m_elements[2],
546 m_elements[3], 0, m_elements[5],
547 m_elements[6], m_elements[7], 0);
550 template <
typename T>
556 m_elements[6], m_elements[7], 0);
559 template <
typename T>
563 0, m_elements[1], m_elements[2],
568 template <
typename T>
573 m_elements[3], m_elements[4], 0,
574 m_elements[6], m_elements[7], m_elements[8]);
577 template <
typename T>
581 m_elements[0], m_elements[1], m_elements[2],
582 0, m_elements[4], m_elements[5],
583 0, 0, m_elements[8]);
586 template <
typename T>
590 m_elements[0], m_elements[3], m_elements[6],
591 m_elements[1], m_elements[4], m_elements[7],
592 m_elements[2], m_elements[5], m_elements[8]);
595 template <
typename T>
603 template <
typename T>
604 template <
typename U>
608 static_cast<U
>(m_elements[0]),
609 static_cast<U>(m_elements[1]),
610 static_cast<U
>(m_elements[2]),
611 static_cast<U>(m_elements[3]),
612 static_cast<U
>(m_elements[4]),
613 static_cast<U>(m_elements[5]),
614 static_cast<U
>(m_elements[6]),
615 static_cast<U>(m_elements[7]),
616 static_cast<U
>(m_elements[8]));
619 template <
typename T>
626 template <
typename T>
633 template <
typename T>
640 template <
typename T>
647 template <
typename T>
654 template <
typename T>
661 template <
typename T>
668 template <
typename T>
675 template <
typename T>
678 return m_elements[i];
681 template <
typename T>
684 return m_elements[i];
687 template <
typename T>
690 return m_elements[i * 3 + j];
693 template <
typename T>
696 return m_elements[i * 3 + j];
699 template <
typename T>
703 m_elements[0] == m.m_elements[0] &&
704 m_elements[1] == m.m_elements[1] &&
705 m_elements[2] == m.m_elements[2] &&
706 m_elements[3] == m.m_elements[3] &&
707 m_elements[4] == m.m_elements[4] &&
708 m_elements[5] == m.m_elements[5] &&
709 m_elements[6] == m.m_elements[6] &&
710 m_elements[7] == m.m_elements[7] &&
711 m_elements[8] == m.m_elements[8];
714 template <
typename T>
718 m_elements[0] != m.m_elements[0] ||
719 m_elements[1] != m.m_elements[1] ||
720 m_elements[2] != m.m_elements[2] ||
721 m_elements[3] != m.m_elements[3] ||
722 m_elements[4] != m.m_elements[4] ||
723 m_elements[5] != m.m_elements[5] ||
724 m_elements[6] != m.m_elements[6] ||
725 m_elements[7] != m.m_elements[7] ||
726 m_elements[8] != m.m_elements[8];
729 template <
typename T>
738 template <
typename T>
747 template <
typename T>
756 template <
typename T>
759 return MakeScaleMatrix(s.
x, s.
y, s.
z);
762 template <
typename T>
766 1 + (1 - std::cos(rad)) * (axis.
x * axis.
x - 1),
767 -axis.
z * std::sin(rad) + (1 - std::cos(rad)) * axis.
x * axis.
y,
768 axis.
y * std::sin(rad) + (1 - std::cos(rad)) * axis.
x * axis.
z,
770 axis.
z * std::sin(rad) + (1 - std::cos(rad)) * axis.
x * axis.
y,
771 1 + (1 - std::cos(rad)) * (axis.
y * axis.
y - 1),
772 -axis.
x * std::sin(rad) + (1 - std::cos(rad)) * axis.
y * axis.
z,
774 -axis.
y * std::sin(rad) + (1 - std::cos(rad)) * axis.
x * axis.
z,
775 axis.
x * std::sin(rad) + (1 - std::cos(rad)) * axis.
y * axis.
z,
776 1 + (1 - std::cos(rad)) * (axis.
z * axis.
z - 1));
779 template <
typename T>
785 template <
typename T>
791 template <
typename T>
797 template <
typename T>
803 template <
typename T>
809 template <
typename T>
815 template <
typename T>
821 template <
typename T>
827 template <
typename T>
833 template <
typename T>
839 template <
typename T>
845 template <
typename T>
851 template <
typename T>
3-D vector class.
Definition: Vector3.h:26
bool IsSimilar(const MatrixExpression< T, E > &other, double tol=std::numeric_limits< double >::epsilon()) const
Definition: Matrix-Impl.h:169
static MatrixConstant< T > MakeZero()
Makes a M x N matrix with zeros.
Definition: Matrix-Impl.h:823
MatrixDiagonal< T, Matrix > Diagonal() const
Returns diagonal part of this matrix.
Definition: Matrix-Impl.h:633
MatrixDiagonal< T, Matrix > OffDiagonal() const
Returns off-diagonal part of this matrix.
Definition: Matrix-Impl.h:639
Matrix RAdd(T s) const
Returns input scalar + this matrix.
Definition: Matrix3x3-Impl.h:294
T Sum() const
Returns sum of all elements.
Definition: Matrix-Impl.h:483
Matrix & operator*=(const T &s)
Multiplication assignment with input scalar.
Definition: Matrix-Impl.h:737
T z
Z (or the third) component of the vector.
Definition: Vector3.h:38
Matrix & operator/=(const T &s)
Division assignment with input scalar.
Definition: Matrix-Impl.h:752
Matrix Div(T s) const
Returns this matrix / input scalar.
Definition: Matrix3x3-Impl.h:285
T * data()
Returns data pointer of this matrix.
Definition: Matrix-Impl.h:217
void SetDiagonal(const T &s)
Sets diagonal elements with input scalar.
Definition: Matrix-Impl.h:92
Matrix< T, 2, 2 > operator+(const Matrix< T, 2, 2 > &a, const Matrix< T, 2, 2 > &b)
Returns a + b (element-size).
Definition: Matrix2x2-Impl.h:660
void IMul(const T &s)
Multiplies input scalar to this matrix.
Definition: Matrix-Impl.h:376
MatrixScalarRSub< T, Matrix > RSub(const T &s) const
Returns input scalar - this matrix.
Definition: Matrix-Impl.h:318
T AbsMaxN(const T *x, size_t n)
Returns absolute maximum among n-elements.
Definition: MathUtils-Impl.h:64
void IAdd(const T &s)
Adds input scalar to this matrix.
Definition: Matrix-Impl.h:350
void Set(const T &s)
Sets whole matrix with input scalar.
Definition: Matrix-Impl.h:52
MatrixScalarAdd< T, Matrix > Add(const T &s) const
Returns this matrix + input scalar.
Definition: Matrix-Impl.h:253
void SetRow(size_t i, const VectorExpression< T, E > &row)
Sets i-th row with input vector.
Definition: Matrix-Impl.h:116
void IDiv(const T &s)
Divides this matrix with input scalar.
Definition: Matrix-Impl.h:390
Matrix RSub(T s) const
Returns input scalar - this matrix.
Definition: Matrix3x3-Impl.h:312
bool operator!=(const MatrixExpression< T, E > &m) const
Returns true if is not equal to m.
Definition: Matrix-Impl.h:791
Matrix RDiv(T s) const
Returns input scalar / this matrix.
Definition: Matrix3x3-Impl.h:345
void ISub(const T &s)
Subtracts input scalar from this matrix.
Definition: Matrix-Impl.h:363
constexpr size_t Cols() const
Returns number of columns of this matrix.
Definition: Matrix-Impl.h:211
T Max() const
Returns maximum among all elements.
Definition: Matrix-Impl.h:515
Matrix & operator+=(const T &s)
Addition assignment with input scalar.
Definition: Matrix-Impl.h:707
MatrixScalarDiv< T, Matrix > Div(const T &s) const
Returns this matrix / input scalar.
Definition: Matrix-Impl.h:299
MatrixScalarSub< T, Matrix > Sub(const T &s) const
Returns this matrix - input scalar.
Definition: Matrix-Impl.h:266
Matrix Inverse() const
Returns inverse matrix.
Definition: Matrix-Impl.h:677
MatrixScalarMul< T, Matrix > RMul(const T &s) const
Returns input scalar * this matrix.
Definition: Matrix-Impl.h:331
MatrixScalarAdd< T, Matrix > RAdd(const T &s) const
Returns input scalar + this matrix.
Definition: Matrix-Impl.h:305
T AbsMinN(const T *x, size_t n)
Returns absolute minimum among n-elements.
Definition: MathUtils-Impl.h:51
Matrix Mul(T s) const
Returns this matrix * input scalar.
Definition: Matrix3x3-Impl.h:250
Static-sized M x N matrix class.
Definition: Matrix.h:30
MatrixScalarMul< T, Matrix > Mul(const T &s) const
Returns this matrix * input scalar.
Definition: Matrix-Impl.h:279
void Invert()
Inverts this matrix.
Definition: Matrix-Impl.h:402
T x
X (or the first) component of the vector.
Definition: Vector3.h:29
Matrix< T, 2, 2 > operator/(const Matrix< T, 2, 2 > &a, T b)
Definition: Matrix2x2-Impl.h:720
Matrix Add(T s) const
Returns this matrix + input scalar.
Definition: Matrix3x3-Impl.h:214
Definition: pybind11Utils.h:24
3-D matrix class.
Definition: Matrix3x3.h:30
T & operator[](size_t i)
Returns reference of i-th element.
Definition: Matrix-Impl.h:759
bool operator==(const MatrixExpression< T, E > &m) const
Returns true if is equal to m.
Definition: Matrix-Impl.h:784
constexpr bool IsSquare() const
Returns true if this matrix is a square matrix.
Definition: Matrix-Impl.h:193
Matrix< T, 2, 2 > operator-(const Matrix< T, 2, 2 > &a)
Returns a matrix with opposite sign.
Definition: Matrix2x2-Impl.h:654
Matrix & operator-=(const T &s)
Subtraction assignment with input scalar.
Definition: Matrix-Impl.h:722
Matrix & operator=(const E &m)
Assigns input matrix.
const Matrix< T, M, N > & operator()() const
Returns actual implementation (the subclass).
Definition: MatrixExpression-Impl.h:34
T Trace() const
Definition: Matrix-Impl.h:554
T Avg() const
Returns average of all elements.
Definition: Matrix-Impl.h:496
Matrix RMul(T s) const
Returns input scalar * this matrix.
Definition: Matrix3x3-Impl.h:330
Matrix Sub(T s) const
Returns this matrix - input scalar.
Definition: Matrix3x3-Impl.h:232
T Determinant() const
Returns determinant of this matrix.
Definition: Matrix-Impl.h:569
void Transpose()
Transposes this matrix.
Definition: Matrix-Impl.h:396
static MatrixIdentity< T > MakeIdentity()
Makes a M x N matrix with all diagonal elements to 1, and other elements to 0.
Definition: Matrix-Impl.h:829
T Min() const
Returns minimum among all elements.
Definition: Matrix-Impl.h:502
T AbsMin() const
Returns absolute minimum among all elements.
Definition: Matrix-Impl.h:528
Vector< T, 3 > operator*(const Quaternion< T > &q, const Vector< T, 3 > &v)
Returns quaternion q * vector v.
Definition: Quaternion-Impl.h:481
void SetOffDiagonal(const T &s)
Sets off-diagonal elements with input scalar.
Definition: Matrix-Impl.h:103
MatrixTypeCast< U, Matrix, T > CastTo() const
MatrixScalarRDiv< T, Matrix > RDiv(const T &s) const
Returns input matrix / this scalar.
Definition: Matrix-Impl.h:344
constexpr size_t Rows() const
Returns number of rows of this matrix.
Definition: Matrix-Impl.h:205
Matrix< T, N, M > Transposed() const
Returns transposed matrix.
Definition: Matrix-Impl.h:669
T AbsMax() const
Returns absolute maximum among all elements.
Definition: Matrix-Impl.h:541
Matrix()
Definition: Matrix-Impl.h:15
T y
Y (or the second) component of the vector.
Definition: Vector3.h:35
void SetColumn(size_t j, const VectorExpression< T, E > &col)
Sets j-th column with input vector.
Definition: Matrix-Impl.h:130