Matrix3x3-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: Matrix3x3-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Dongmin Kim
5 > Purpose: 3-D matrix class.
6 > Created Time: 2017/03/07
7 > Copyright (c) 2018, Dongmin Kim
8 *************************************************************************/
9 #ifndef CUBBYFLOW_MATRIX3X3_IMPL_H
10 #define CUBBYFLOW_MATRIX3X3_IMPL_H
11 
12 #include <cassert>
13 
14 namespace CubbyFlow
15 {
16  template <typename T>
18  {
19  Set(1, 0, 0,
20  0, 1, 0,
21  0, 0, 1);
22  }
23 
24  template <typename T>
26  {
27  Set(s);
28  }
29 
30  template <typename T>
31  Matrix<T, 3, 3>::Matrix(T m00, T m01, T m02,
32  T m10, T m11, T m12,
33  T m20, T m21, T m22)
34  {
35  Set(m00, m01, m02,
36  m10, m11, m12,
37  m20, m21, m22);
38  }
39 
40  template <typename T>
41  template <typename U>
42  Matrix<T, 3, 3>::Matrix(const std::initializer_list<std::initializer_list<U>>& list)
43  {
44  Set(list);
45  }
46 
47  template <typename T>
49  {
50  Set(m);
51  }
52 
53  template <typename T>
55  {
56  Set(arr);
57  }
58 
59  template <typename T>
61  {
62  m_elements[0] = s;
63  m_elements[1] = s;
64  m_elements[2] = s;
65  m_elements[3] = s;
66  m_elements[4] = s;
67  m_elements[5] = s;
68  m_elements[6] = s;
69  m_elements[7] = s;
70  m_elements[8] = s;
71  }
72 
73  template <typename T>
74  void Matrix<T, 3, 3>::Set(T m00, T m01, T m02,
75  T m10, T m11, T m12,
76  T m20, T m21, T m22)
77  {
78  m_elements[0] = m00;
79  m_elements[1] = m01;
80  m_elements[2] = m02;
81  m_elements[3] = m10;
82  m_elements[4] = m11;
83  m_elements[5] = m12;
84  m_elements[6] = m20;
85  m_elements[7] = m21;
86  m_elements[8] = m22;
87  }
88 
89  template <typename T>
90  template <typename U>
91  void Matrix<T, 3, 3>::Set(const std::initializer_list<std::initializer_list<U>>& list)
92  {
93  size_t height = list.size();
94  size_t width = (height > 0) ? list.begin()->size() : 0;
95 
96  assert(width == 3);
97  assert(height == 3);
98 
99  auto rowIter = list.begin();
100  for (size_t i = 0; i < height; ++i)
101  {
102  assert(width == rowIter->size());
103 
104  auto colIter = rowIter->begin();
105  for (size_t j = 0; j < width; ++j)
106  {
107  (*this)(i, j) = static_cast<T>(*colIter);
108  ++colIter;
109  }
110 
111  ++rowIter;
112  }
113  }
114 
115  template <typename T>
117  {
118  for (size_t i = 0; i < 9; ++i)
119  {
120  m_elements[i] = m.m_elements[i];
121  }
122  }
123 
124  template <typename T>
125  void Matrix<T, 3, 3>::Set(const T* arr)
126  {
127  for (size_t i = 0; i < 9; ++i)
128  {
129  m_elements[i] = arr[i];
130  }
131  }
132 
133  template <typename T>
135  {
136  m_elements[0] = s;
137  m_elements[4] = s;
138  m_elements[8] = s;
139  }
140 
141  template <typename T>
143  {
144  m_elements[1] = s;
145  m_elements[2] = s;
146  m_elements[3] = s;
147  m_elements[5] = s;
148  m_elements[6] = s;
149  m_elements[7] = s;
150  }
151 
152  template <typename T>
153  void Matrix<T, 3, 3>::SetRow(size_t i, const Vector3<T>& row)
154  {
155  m_elements[i * 3] = row.x;
156  m_elements[i * 3 + 1] = row.y;
157  m_elements[i * 3 + 2] = row.z;
158  }
159 
160  template <typename T>
161  void Matrix<T, 3, 3>::SetColumn(size_t i, const Vector3<T>& col)
162  {
163  m_elements[i] = col.x;
164  m_elements[i + 3] = col.y;
165  m_elements[i + 6] = col.z;
166  }
167 
168  template <typename T>
169  bool Matrix<T, 3, 3>::IsSimilar(const Matrix& m, double tol) const
170  {
171  return
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;
181  }
182 
183  template <typename T>
185  {
186  return true;
187  }
188 
189  template <typename T>
190  size_t Matrix<T, 3, 3>::Rows() const
191  {
192  return 3;
193  }
194 
195  template <typename T>
196  size_t Matrix<T, 3, 3>::Cols() const
197  {
198  return 3;
199  }
200 
201  template <typename T>
203  {
204  return m_elements.data();
205  }
206 
207  template <typename T>
208  const T* Matrix<T, 3, 3>::data() const
209  {
210  return m_elements.data();
211  }
212 
213  template <typename T>
215  {
216  return Matrix<T, 3, 3>(
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);
220  }
221 
222  template <typename T>
224  {
225  return Matrix<T, 3, 3>(
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]);
229  }
230 
231  template <typename T>
233  {
234  return Matrix<T, 3, 3>(
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);
238  }
239 
240  template <typename T>
242  {
243  return Matrix<T, 3, 3>(
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]);
247  }
248 
249  template <typename T>
251  {
252  return Matrix<T, 3, 3>(
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);
256  }
257 
258  template <typename T>
260  {
261  return Vector<T, 3>(
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]);
265  }
266 
267  template <typename T>
269  {
270  return Matrix(
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],
274 
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],
278 
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]);
282  }
283 
284  template <typename T>
286  {
287  return Matrix(
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);
291  }
292 
293  template <typename T>
295  {
296  return Matrix<T, 3, 3>(
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]);
300  }
301 
302  template <typename T>
304  {
305  return Matrix<T, 3, 3>(
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]);
309  }
310 
311  template <typename T>
313  {
314  return Matrix<T, 3, 3>(
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]);
318  }
319 
320  template <typename T>
322  {
323  return Matrix<T, 3, 3>(
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]);
327  }
328 
329  template <typename T>
331  {
332  return Matrix<T, 3, 3>(
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]);
336  }
337 
338  template <typename T>
340  {
341  return m.Mul(*this);
342  }
343 
344  template <typename T>
346  {
347  return Matrix<T, 3, 3>(
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]);
351  }
352 
353  template <typename T>
355  {
356  m_elements[0] += s;
357  m_elements[1] += s;
358  m_elements[2] += s;
359  m_elements[3] += s;
360  m_elements[4] += s;
361  m_elements[5] += s;
362  m_elements[6] += s;
363  m_elements[7] += s;
364  m_elements[8] += s;
365  }
366 
367  template <typename T>
369  {
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];
379  }
380 
381  template <typename T>
383  {
384  m_elements[0] -= s;
385  m_elements[1] -= s;
386  m_elements[2] -= s;
387  m_elements[3] -= s;
388  m_elements[4] -= s;
389  m_elements[5] -= s;
390  m_elements[6] -= s;
391  m_elements[7] -= s;
392  m_elements[8] -= s;
393  }
394 
395  template <typename T>
397  {
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];
407  }
408 
409  template <typename T>
411  {
412  m_elements[0] *= s;
413  m_elements[1] *= s;
414  m_elements[2] *= s;
415  m_elements[3] *= s;
416  m_elements[4] *= s;
417  m_elements[5] *= s;
418  m_elements[6] *= s;
419  m_elements[7] *= s;
420  m_elements[8] *= s;
421  }
422 
423  template <typename T>
425  {
426  Set(Mul(m));
427  }
428 
429  template <typename T>
431  {
432  m_elements[0] /= s;
433  m_elements[1] /= s;
434  m_elements[2] /= s;
435  m_elements[3] /= s;
436  m_elements[4] /= s;
437  m_elements[5] /= s;
438  m_elements[6] /= s;
439  m_elements[7] /= s;
440  m_elements[8] /= s;
441  }
442 
443  template <typename T>
445  {
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]);
449  }
450 
451  template <typename T>
453  {
454  T d = Determinant();
455 
456  Matrix m;
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];
466  m.IDiv(d);
467 
468  Set(m);
469  }
470 
471  template <typename T>
473  {
474  T sum = 0;
475 
476  for (size_t i = 0; i < 9; ++i)
477  {
478  sum += m_elements[i];
479  }
480 
481  return sum;
482  }
483 
484  template <typename T>
486  {
487  return Sum() / 9;
488  }
489 
490  template <typename T>
492  {
493  return m_elements[std::distance(std::begin(m_elements), std::min_element(std::begin(m_elements), std::end(m_elements)))];
494  }
495 
496  template <typename T>
498  {
499  return m_elements[std::distance(std::begin(m_elements), std::max_element(std::begin(m_elements), std::end(m_elements)))];
500  }
501 
502  template <typename T>
504  {
505  return CubbyFlow::AbsMinN(data(), 9);
506  }
507 
508  template <typename T>
510  {
511  return CubbyFlow::AbsMaxN(data(), 9);
512  }
513 
514  template <typename T>
516  {
517  return m_elements[0] + m_elements[4] + m_elements[8];
518  }
519 
520  template <typename T>
522  {
523  return
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];
530  }
531 
532  template <typename T>
534  {
535  return Matrix<T, 3, 3>(
536  m_elements[0], 0, 0,
537  0, m_elements[4], 0,
538  0, 0, m_elements[8]);
539  }
540 
541  template <typename T>
543  {
544  return Matrix<T, 3, 3>(
545  0, m_elements[1], m_elements[2],
546  m_elements[3], 0, m_elements[5],
547  m_elements[6], m_elements[7], 0);
548  }
549 
550  template <typename T>
552  {
553  return Matrix<T, 3, 3>(
554  0, 0, 0,
555  m_elements[3], 0, 0,
556  m_elements[6], m_elements[7], 0);
557  }
558 
559  template <typename T>
561  {
562  return Matrix<T, 3, 3>(
563  0, m_elements[1], m_elements[2],
564  0, 0, m_elements[5],
565  0, 0, 0);
566  }
567 
568  template <typename T>
570  {
571  return Matrix<T, 3, 3>(
572  m_elements[0], 0, 0,
573  m_elements[3], m_elements[4], 0,
574  m_elements[6], m_elements[7], m_elements[8]);
575  }
576 
577  template <typename T>
579  {
580  return Matrix<T, 3, 3>(
581  m_elements[0], m_elements[1], m_elements[2],
582  0, m_elements[4], m_elements[5],
583  0, 0, m_elements[8]);
584  }
585 
586  template <typename T>
588  {
589  return Matrix<T, 3, 3>(
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]);
593  }
594 
595  template <typename T>
597  {
598  Matrix m(*this);
599  m.Invert();
600  return m;
601  }
602 
603  template <typename T>
604  template <typename U>
606  {
607  return Matrix<U, 3, 3>(
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]));
617  }
618 
619  template <typename T>
621  {
622  Set(m);
623  return *this;
624  }
625 
626  template <typename T>
628  {
629  IAdd(s);
630  return *this;
631  }
632 
633  template <typename T>
635  {
636  IAdd(m);
637  return *this;
638  }
639 
640  template <typename T>
642  {
643  ISub(s);
644  return *this;
645  }
646 
647  template <typename T>
649  {
650  ISub(m);
651  return *this;
652  }
653 
654  template <typename T>
656  {
657  IMul(s);
658  return *this;
659  }
660 
661  template <typename T>
663  {
664  IMul(m);
665  return *this;
666  }
667 
668  template <typename T>
670  {
671  IDiv(s);
672  return *this;
673  }
674 
675  template <typename T>
677  {
678  return m_elements[i];
679  }
680 
681  template <typename T>
682  const T& Matrix<T, 3, 3>::operator[](size_t i) const
683  {
684  return m_elements[i];
685  }
686 
687  template <typename T>
688  T& Matrix<T, 3, 3>::operator()(size_t i, size_t j)
689  {
690  return m_elements[i * 3 + j];
691  }
692 
693  template <typename T>
694  const T& Matrix<T, 3, 3>::operator()(size_t i, size_t j) const
695  {
696  return m_elements[i * 3 + j];
697  }
698 
699  template <typename T>
700  bool Matrix<T, 3, 3>::operator==(const Matrix& m) const
701  {
702  return
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];
712  }
713 
714  template <typename T>
715  bool Matrix<T, 3, 3>::operator!=(const Matrix& m) const
716  {
717  return
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];
727  }
728 
729  template <typename T>
731  {
732  return Matrix<T, 3, 3>(
733  0, 0, 0,
734  0, 0, 0,
735  0, 0, 0);
736  }
737 
738  template <typename T>
740  {
741  return Matrix<T, 3, 3>(
742  1, 0, 0,
743  0, 1, 0,
744  0, 0, 1);
745  }
746 
747  template <typename T>
749  {
750  return Matrix<T, 3, 3>(
751  sx, 0, 0,
752  0, sy, 0,
753  0, 0, sz);
754  }
755 
756  template <typename T>
758  {
759  return MakeScaleMatrix(s.x, s.y, s.z);
760  }
761 
762  template <typename T>
764  {
765  return Matrix(
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,
769 
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,
773 
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));
777  }
778 
779  template <typename T>
781  {
782  return a.Mul(-1);
783  }
784 
785  template <typename T>
787  {
788  return a.Add(b);
789  }
790 
791  template <typename T>
793  {
794  return a.Add(b);
795  }
796 
797  template <typename T>
799  {
800  return b.RAdd(a);
801  }
802 
803  template <typename T>
805  {
806  return a.Sub(b);
807  }
808 
809  template <typename T>
811  {
812  return a.Sub(b);
813  }
814 
815  template <typename T>
817  {
818  return b.RSub(a);
819  }
820 
821  template <typename T>
823  {
824  return a.Mul(b);
825  }
826 
827  template <typename T>
829  {
830  return b.RMul(a);
831  }
832 
833  template <typename T>
835  {
836  return a.Mul(b);
837  }
838 
839  template <typename T>
841  {
842  return a.Mul(b);
843  }
844 
845  template <typename T>
847  {
848  return a.Div(b);
849  }
850 
851  template <typename T>
853  {
854  return b.RDiv(a);
855  }
856 }
857 
858 #endif
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