CMatrix2d.h
Go to the documentation of this file.
1 #ifndef i2d_CMatrix2d_included
2 #define i2d_CMatrix2d_included
3 
4 
5 // ACF includes
6 #include <imath/TMatrix.h>
7 
8 #include <i2d/CVector2d.h>
9 
10 
11 namespace i2d
12 {
13 
14 
18 class CMatrix2d: public imath::TMatrix<2, 2>
19 {
20 public:
22 
26  CMatrix2d();
27  CMatrix2d(const CMatrix2d& transform);
31  CMatrix2d(const CVector2d& axisX, const CVector2d& axisY);
35  CMatrix2d(double m11, double m12, double m21, double m22);
36 
40  void Reset();
44  void Reset(double angle, double scale = 1.0);
48  void Reset(double angle, const CVector2d& scale);
49 
50  // operations
52  CVector2d GetMultiplied(const CVector2d& position) const;
53  CMatrix2d GetMultiplied(const CMatrix2d& matrix) const;
54  void Multiply(const CMatrix2d& matrix);
55  void MultiplyLeft(const CMatrix2d& matrix);
56 
60  CVector2d GetAxisX() const;
64  CVector2d GetAxisY() const;
65 
69  CVector2d GetAxesLengths() const;
73  void GetAxesLengths(CVector2d& result) const;
78  double GetApproxAngle() const;
82  double GetApproxScale() const;
83 
87  i2d::CVector2d GetInvMultiplied(const i2d::CVector2d& position) const;
91  bool GetInvMultiplied(const i2d::CVector2d& position, i2d::CVector2d& result) const;
92 
96  CMatrix2d GetInverted() const;
100  bool GetInverted(CMatrix2d& result) const;
101 
106  CMatrix2d GetTransposed() const;
107 
112  bool GetEigenVectors(i2d::CVector2d& vector1, i2d::CVector2d& vector2, double& value1, double& value2) const;
113 
117  double GetDet() const;
118 
119  // operators
123  CMatrix2d& operator=(const CMatrix2d& matrix);
124 
125  CMatrix2d operator+(const BaseClass& matrix) const;
126  CMatrix2d operator-(const BaseClass& matrix) const;
131  CMatrix2d operator*(double scale) const;
135  CMatrix2d operator/(double scale) const;
136 
137  // static methods
138  static const CMatrix2d& GetIdentity();
139 
140 private:
141  // static members
142  static CMatrix2d s_identity;
143 };
144 
145 
146 // inline methods
147 
149 {
150 }
151 
152 
153 inline CMatrix2d::CMatrix2d(const CMatrix2d& matrix)
154 : BaseClass(matrix)
155 {
156 }
157 
158 
159 inline CMatrix2d::CMatrix2d(const CVector2d& axisX, const CVector2d& axisY)
160 {
161  SetAt(0, 0, axisX[0]);
162  SetAt(0, 1, axisX[1]);
163  SetAt(1, 0, axisY[0]);
164  SetAt(1, 1, axisY[1]);
165 }
166 
167 
168 inline CMatrix2d::CMatrix2d(double m11, double m12, double m21, double m22)
169 {
170  SetAt(0, 0, m11);
171  SetAt(0, 1, m12);
172  SetAt(1, 0, m21);
173  SetAt(1, 1, m22);
174 }
175 
176 
177 inline CVector2d CMatrix2d::GetMultiplied(const CVector2d& position) const
178 {
179  CVector2d retVal;
180 
181  GetMultiplied(position, retVal);
182 
183  return retVal;
184 }
185 
186 
187 inline CMatrix2d CMatrix2d::GetMultiplied(const CMatrix2d& matrix) const
188 {
189  CMatrix2d retVal;
190 
191  GetMultiplied(matrix, retVal);
192 
193  return retVal;
194 }
195 
196 
198 {
199  return CVector2d(GetAt(0, 0), GetAt(0, 1));
200 }
201 
202 
204 {
205  return CVector2d(GetAt(1, 0), GetAt(1, 1));
206 }
207 
208 
210 {
211  CVector2d result;
212 
213  GetAxesLengths(result);
214 
215  return result;
216 }
217 
218 
219 inline void CMatrix2d::GetAxesLengths(CVector2d& result) const
220 {
221  result.SetX(GetAxisX().GetLength());
222  result.SetY(GetAxisY().GetLength());
223 }
224 
225 
227 {
228  CMatrix2d result;
229 
230  GetInverted(result);
231 
232  return result;
233 }
234 
235 
237 {
238  return CMatrix2d(GetAt(0, 0), GetAt(0, 1), GetAt(1, 0), GetAt(1, 1));
239 }
240 
241 
242 inline double CMatrix2d::GetDet() const
243 {
244  return GetAt(0, 0) * GetAt(1, 1) - GetAt(0, 1) * GetAt(1, 0);
245 }
246 
247 
248 // operators
249 
250 inline CMatrix2d CMatrix2d::operator+(const BaseClass& matrix) const
251 {
252  CMatrix2d retVal;
253 
254  BaseClass::GetAdded(matrix, retVal);
255 
256  return retVal;
257 }
258 
259 
260 inline CMatrix2d CMatrix2d::operator-(const BaseClass& matrix) const
261 {
262  CMatrix2d retVal;
263 
264  BaseClass::GetSubstracted(matrix, retVal);
265 
266  return retVal;
267 }
268 
269 
271 {
272  CMatrix2d retVal;
273 
274  BaseClass::GetNegated(retVal);
275 
276  return retVal;
277 }
278 
279 
281 {
282  BaseClass::operator=(matrix);
283 
284  return *this;
285 }
286 
287 
288 inline CMatrix2d CMatrix2d::operator*(double scale) const
289 {
290  CMatrix2d retVal;
291 
292  GetScaled(scale, retVal);
293 
294  return retVal;
295 }
296 
297 
298 inline CMatrix2d CMatrix2d::operator/(double scale) const
299 {
300  return CMatrix2d(GetAt(0, 0) / scale, GetAt(0, 1) / scale, GetAt(1, 0) / scale, GetAt(1, 1) / scale);
301 }
302 
303 
304 // static methods
305 
307 {
308  return s_identity;
309 }
310 
311 
312 } // namespace i2d
313 
314 
315 #endif // !i2d_CMatrix2d_included
316 
317 
CMatrix2d & operator=(const CMatrix2d &matrix)
Copy operator.
Definition: CMatrix2d.h:280
const ElementType & GetAt(const IndexType &index) const
Get element stored at specified index.
CVector2d GetMultiplied(const CVector2d &position) const
Definition: CMatrix2d.h:177
TMatrix< Height, Width, double > GetTransposed() const
Get transposed matrix.
imath::TMatrix< 2, 2 > BaseClass
Definition: CMatrix2d.h:21
void SetAt(const IndexType &index, const ElementType &value)
Set element at specified index.
double GetApproxAngle() const
Get angle of axis X in radians.
void MultiplyLeft(const CMatrix2d &matrix)
CVector2d GetAxesLengths() const
Get lengths of axes vectors.
Definition: CMatrix2d.h:209
double GetApproxScale() const
Get approximated scale.
static const CMatrix2d & GetIdentity()
Definition: CMatrix2d.h:306
i2d::CVector2d GetInvMultiplied(const i2d::CVector2d &position) const
Inverted operation to GetApply().
void Multiply(const CMatrix2d &matrix)
void SetX(double x)
Set X position of this vector.
Definition: CVector2d.h:178
2D matrix.
Definition: CMatrix2d.h:18
CVector2d GetAxisY() const
Get axis Y vector.
Definition: CMatrix2d.h:203
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
void SetY(double y)
Set Y position of this vector.
Definition: CVector2d.h:190
CMatrix2d GetTransposed() const
Calculate transposed matrix.
Definition: CMatrix2d.h:236
CVector2d GetAxisX() const
Get axis X vector.
Definition: CMatrix2d.h:197
CMatrix2d GetInverted() const
Calculate inverted matrix.
Definition: CMatrix2d.h:226
CMatrix2d operator/(double scale) const
Division by scalar number.
Definition: CMatrix2d.h:298
void GetAdded(const TMatrix< Width, Height, double > &matrix, TMatrix< Width, Height, double > &result) const
Get sum of two matrices.
bool GetEigenVectors(i2d::CVector2d &vector1, i2d::CVector2d &vector2, double &value1, double &value2) const
Calculate eigen vectors and eigen values.
void Reset()
Default reset to identity.
void GetNegated(TMatrix< Width, Height, double > &result)
Get result matrix with negated all elements.
void GetMultiplied(const TMatrix< SecondWidth, Width, double > &matrix, TMatrix< SecondWidth, Height, double > &result) const
Get result of multiplication of two matrices.
Definition: TMatrix.h:195
Definition of mathematical matrix with fixed dimensions.
Definition: TMatrix.h:27
double GetDet() const
Calculate determinant of deformation matrix.
Definition: CMatrix2d.h:242
CMatrix2d operator-()
Definition: CMatrix2d.h:270
void GetSubstracted(const TMatrix< Width, Height, double > &matrix, TMatrix< Width, Height, double > &result) const
Get result of substraction of two matrices.
CMatrix2d()
Constructor with no member initialization.
Definition: CMatrix2d.h:148
CMatrix2d operator+(const BaseClass &matrix) const
Definition: CMatrix2d.h:250
CMatrix2d operator*(double scale) const
Multiplication by scalar number.
Definition: CMatrix2d.h:288
void GetScaled(double value, TMatrix< Width, Height, double > &result) const
Get result of multiplication of this matrix with scalar value.

© 2007-2017 Witold Gantzke and Kirill Lepskiy