GteMatrix2x2.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/GteVector2.h>
12 
13 namespace gte
14 {
15 
16 // Template alias for convenience.
17 template <typename Real>
19 
20 // Create a rotation matrix from an angle (in radians). The matrix is
21 // [GTE_USE_MAT_VEC]
22 // R(t) = {{c,-s},{s,c}}
23 // [GTE_USE_VEC_MAT]
24 // R(t) = {{c,s},{-s,c}}
25 // where c = cos(t), s = sin(t), and the inner-brace pairs are rows of the
26 // matrix.
27 template <typename Real>
28 void MakeRotation(Real angle, Matrix2x2<Real>& rotation);
29 
30 // Get the angle (radians) from a rotation matrix. The caller is
31 // responsible for ensuring the matrix is a rotation.
32 template <typename Real>
33 Real GetRotationAngle(Matrix2x2<Real> const& rotation);
34 
35 // Geometric operations.
36 template <typename Real>
38  bool* reportInvertibility = nullptr);
39 
40 template <typename Real>
42 
43 template <typename Real>
44 Real Determinant(Matrix2x2<Real> const& M);
45 
46 template <typename Real>
47 Real Trace(Matrix2x2<Real> const& M);
48 
49 
50 template <typename Real>
51 void MakeRotation(Real angle, Matrix2x2<Real>& rotation)
52 {
53  Real cs = cos(angle);
54  Real sn = sin(angle);
55 #if defined(GTE_USE_MAT_VEC)
56  rotation(0, 0) = cs;
57  rotation(0, 1) = -sn;
58  rotation(1, 0) = sn;
59  rotation(1, 1) = cs;
60 #else
61  rotation(0, 0) = cs;
62  rotation(0, 1) = sn;
63  rotation(1, 0) = -sn;
64  rotation(1, 1) = cs;
65 #endif
66 }
67 
68 template <typename Real>
69 Real GetRotationAngle(Matrix2x2<Real> const& rotation)
70 {
71 #if defined(GTE_USE_MAT_VEC)
72  return atan2(rotation(1, 0), rotation(0, 0));
73 #else
74  return atan2(rotation(0, 1), rotation(0, 0));
75 #endif
76 }
77 
78 template <typename Real>
79 Matrix2x2<Real> Inverse(Matrix2x2<Real> const& M, bool* reportInvertibility)
80 {
81  Matrix2x2<Real> inverse;
82  bool invertible;
83  Real det = M(0, 0)*M(1, 1) - M(0, 1)*M(1, 0);
84  if (det != (Real)0)
85  {
86  Real invDet = ((Real)1) / det;
87  inverse = Matrix2x2<Real>
88  {
89  M(1, 1)*invDet, -M(0, 1)*invDet,
90  -M(1, 0)*invDet, M(0, 0)*invDet
91  };
92  invertible = true;
93  }
94  else
95  {
96  inverse.MakeZero();
97  invertible = false;
98  }
99 
100  if (reportInvertibility)
101  {
102  *reportInvertibility = invertible;
103  }
104  return inverse;
105 }
106 
107 template <typename Real>
109 {
110  return Matrix2x2<Real>
111  {
112  M(1, 1), -M(0, 1),
113  -M(1, 0), M(0, 0)
114  };
115 }
116 
117 template <typename Real>
119 {
120  Real det = M(0, 0)*M(1, 1) - M(0, 1)*M(1, 0);
121  return det;
122 }
123 
124 template <typename Real>
125 Real Trace(Matrix2x2<Real> const& M)
126 {
127  Real trace = M(0, 0) + M(1, 1);
128  return trace;
129 }
130 
131 
132 }
Matrix2x2< Real > Adjoint(Matrix2x2< Real > const &M)
Definition: GteMatrix2x2.h:108
GLfloat angle
Definition: glext.h:6466
Real Trace(Matrix2x2< Real > const &M)
Definition: GteMatrix2x2.h:125
void MakeRotation(Real angle, Matrix2x2< Real > &rotation)
Definition: GteMatrix2x2.h:51
void MakeZero()
Definition: GteMatrix.h:442
Quaternion< Real > Inverse(Quaternion< Real > const &d)
Real GetRotationAngle(Matrix2x2< Real > const &rotation)
Definition: GteMatrix2x2.h:69
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