41 |
|
template<typename Real> |
42 |
|
class SquareMatrix3 : public SquareMatrix<Real, 3> { |
43 |
|
public: |
44 |
+ |
|
45 |
+ |
typedef Real ElemType; |
46 |
+ |
typedef Real* ElemPoinerType; |
47 |
|
|
48 |
|
/** default constructor */ |
49 |
|
SquareMatrix3() : SquareMatrix<Real, 3>() { |
50 |
|
} |
51 |
|
|
52 |
+ |
/** Constructs and initializes every element of this matrix to a scalar */ |
53 |
+ |
SquareMatrix3(Real s) : SquareMatrix<Real,3>(s){ |
54 |
+ |
} |
55 |
+ |
|
56 |
+ |
/** Constructs and initializes from an array */ |
57 |
+ |
SquareMatrix3(Real* array) : SquareMatrix<Real,3>(array){ |
58 |
+ |
} |
59 |
+ |
|
60 |
+ |
|
61 |
|
/** copy constructor */ |
62 |
|
SquareMatrix3(const SquareMatrix<Real, 3>& m) : SquareMatrix<Real, 3>(m) { |
63 |
|
} |
64 |
< |
|
64 |
> |
|
65 |
|
SquareMatrix3( const Vector3<Real>& eulerAngles) { |
66 |
|
setupRotMat(eulerAngles); |
67 |
|
} |
260 |
|
|
261 |
|
return(x + y + z); |
262 |
|
} |
263 |
+ |
|
264 |
+ |
/** Returns the trace of this matrix. */ |
265 |
+ |
Real trace() const { |
266 |
+ |
return data_[0][0] + data_[1][1] + data_[2][2]; |
267 |
+ |
} |
268 |
|
|
269 |
|
/** |
270 |
|
* Sets the value of this matrix to the inversion of itself. |
271 |
|
* @note since simple algorithm can be applied to inverse the 3 by 3 matrix, we hide the |
272 |
|
* implementation of inverse in SquareMatrix class |
273 |
|
*/ |
274 |
< |
SquareMatrix3<Real> inverse() { |
274 |
> |
SquareMatrix3<Real> inverse() const { |
275 |
|
SquareMatrix3<Real> m; |
276 |
|
double det = determinant(); |
277 |
|
if (fabs(det) <= oopse::epsilon) { |
440 |
|
// transpose the eigenvectors back again |
441 |
|
v = v.transpose(); |
442 |
|
return ; |
443 |
+ |
} |
444 |
+ |
|
445 |
+ |
/** |
446 |
+ |
* Return the multiplication of two matrixes (m1 * m2). |
447 |
+ |
* @return the multiplication of two matrixes |
448 |
+ |
* @param m1 the first matrix |
449 |
+ |
* @param m2 the second matrix |
450 |
+ |
*/ |
451 |
+ |
template<typename Real> |
452 |
+ |
inline SquareMatrix3<Real> operator *(const SquareMatrix3<Real>& m1, const SquareMatrix3<Real>& m2) { |
453 |
+ |
SquareMatrix3<Real> result; |
454 |
+ |
|
455 |
+ |
for (unsigned int i = 0; i < 3; i++) |
456 |
+ |
for (unsigned int j = 0; j < 3; j++) |
457 |
+ |
for (unsigned int k = 0; k < 3; k++) |
458 |
+ |
result(i, j) += m1(i, k) * m2(k, j); |
459 |
+ |
|
460 |
+ |
return result; |
461 |
|
} |
462 |
+ |
|
463 |
+ |
template<typename Real> |
464 |
+ |
inline SquareMatrix3<Real> outProduct(const Vector3<Real>& v1, const Vector3<Real>& v2) { |
465 |
+ |
SquareMatrix3<Real> result; |
466 |
+ |
|
467 |
+ |
for (unsigned int i = 0; i < 3; i++) { |
468 |
+ |
for (unsigned int j = 0; j < 3; j++) { |
469 |
+ |
result(i, j) = v1[i] * v2[j]; |
470 |
+ |
} |
471 |
+ |
} |
472 |
+ |
|
473 |
+ |
return result; |
474 |
+ |
} |
475 |
+ |
|
476 |
+ |
|
477 |
|
typedef SquareMatrix3<double> Mat3x3d; |
478 |
|
typedef SquareMatrix3<double> RotMat3x3d; |
479 |
|
|