GteMatrix3x3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteMatrix.h>
11 #include <Mathematics/GteVector3.h>
12 
13 namespace gte
14 {
15 
16 // Template alias for convenience.
17 template <typename Real>
19 
20 // Geometric operations.
21 template <typename Real>
23  bool* reportInvertibility = nullptr);
24 
25 template <typename Real>
27 
28 template <typename Real>
29 Real Determinant(Matrix3x3<Real> const& M);
30 
31 template <typename Real>
32 Real Trace(Matrix3x3<Real> const& M);
33 
34 
35 template <typename Real>
36 Matrix3x3<Real> Inverse(Matrix3x3<Real> const& M, bool* reportInvertibility)
37 {
38  Matrix3x3<Real> inverse;
39  bool invertible;
40  Real c00 = M(1, 1)*M(2, 2) - M(1, 2)*M(2, 1);
41  Real c10 = M(1, 2)*M(2, 0) - M(1, 0)*M(2, 2);
42  Real c20 = M(1, 0)*M(2, 1) - M(1, 1)*M(2, 0);
43  Real det = M(0, 0)*c00 + M(0, 1)*c10 + M(0, 2)*c20;
44  if (det != (Real)0)
45  {
46  Real invDet = ((Real)1) / det;
47  inverse = Matrix3x3<Real>
48  {
49  c00*invDet,
50  (M(0, 2)*M(2, 1) - M(0, 1)*M(2, 2))*invDet,
51  (M(0, 1)*M(1, 2) - M(0, 2)*M(1, 1))*invDet,
52  c10*invDet,
53  (M(0, 0)*M(2, 2) - M(0, 2)*M(2, 0))*invDet,
54  (M(0, 2)*M(1, 0) - M(0, 0)*M(1, 2))*invDet,
55  c20*invDet,
56  (M(0, 1)*M(2, 0) - M(0, 0)*M(2, 1))*invDet,
57  (M(0, 0)*M(1, 1) - M(0, 1)*M(1, 0))*invDet
58  };
59  invertible = true;
60  }
61  else
62  {
63  inverse.MakeZero();
64  invertible = false;
65  }
66 
67  if (reportInvertibility)
68  {
69  *reportInvertibility = invertible;
70  }
71  return inverse;
72 }
73 
74 template <typename Real>
76 {
77  return Matrix3x3<Real>
78  {
79  M(1, 1)*M(2, 2) - M(1, 2)*M(2, 1),
80  M(0, 2)*M(2, 1) - M(0, 1)*M(2, 2),
81  M(0, 1)*M(1, 2) - M(0, 2)*M(1, 1),
82  M(1, 2)*M(2, 0) - M(1, 0)*M(2, 2),
83  M(0, 0)*M(2, 2) - M(0, 2)*M(2, 0),
84  M(0, 2)*M(1, 0) - M(0, 0)*M(1, 2),
85  M(1, 0)*M(2, 1) - M(1, 1)*M(2, 0),
86  M(0, 1)*M(2, 0) - M(0, 0)*M(2, 1),
87  M(0, 0)*M(1, 1) - M(0, 1)*M(1, 0)
88  };
89 }
90 
91 template <typename Real>
93 {
94  Real c00 = M(1, 1)*M(2, 2) - M(1, 2)*M(2, 1);
95  Real c10 = M(1, 2)*M(2, 0) - M(1, 0)*M(2, 2);
96  Real c20 = M(1, 0)*M(2, 1) - M(1, 1)*M(2, 0);
97  Real det = M(0, 0)*c00 + M(0, 1)*c10 + M(0, 2)*c20;
98  return det;
99 }
100 
101 template <typename Real>
102 Real Trace(Matrix3x3<Real> const& M)
103 {
104  Real trace = M(0, 0) + M(1, 1) + M(2, 2);
105  return trace;
106 }
107 
108 
109 }
Matrix2x2< Real > Adjoint(Matrix2x2< Real > const &M)
Definition: GteMatrix2x2.h:108
Real Trace(Matrix2x2< Real > const &M)
Definition: GteMatrix2x2.h:125
void MakeZero()
Definition: GteMatrix.h:442
Quaternion< Real > Inverse(Quaternion< Real > const &d)
Real Determinant(GMatrix< Real > const &M)
Definition: GteGMatrix.h:618


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01