ICF 3.0.5.47
Technical documentation of ICF Libraries
CMatrix2d.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// ICF includes
10#include <imath/TMatrix.h>
11
12#include <i2d/CVector2d.h>
13
14
15namespace i2d
16{
17
18
22class CMatrix2d: public imath::TMatrix<2, 2>
23{
24public:
26
30 CMatrix2d();
31 CMatrix2d(const CMatrix2d& transform);
35 CMatrix2d(const CVector2d& axisX, const CVector2d& axisY);
39 CMatrix2d(double m11, double m12, double m21, double m22);
40
44 void Reset();
51 void Reset(double angle, double scale = 1.0, bool isPosDef = true);
58 void Reset(double angle, const CVector2d& scale, bool isPosDef = true);
59
60 // operations
62 CVector2d GetMultiplied(const CVector2d& position) const;
63 CMatrix2d GetMultiplied(const CMatrix2d& matrix) const;
64 void Multiply(const CMatrix2d& matrix);
65 void MultiplyLeft(const CMatrix2d& matrix);
66
70 CVector2d GetAxisX() const;
74 CVector2d GetAxisY() const;
75
83 void GetAxesLengths(CVector2d& result) const;
88 double GetApproxAngle() const;
92 double GetApproxScale() const;
93
101 bool GetInvMultiplied(const i2d::CVector2d& position, i2d::CVector2d& result) const;
102
106 CMatrix2d GetInverted() const;
110 bool GetInverted(CMatrix2d& result) const;
111
116 CMatrix2d GetTransposed() const;
117
122 bool GetEigenVectors(i2d::CVector2d& vector1, i2d::CVector2d& vector2, double& value1, double& value2) const;
123
127 double GetDet() const;
128
129 // operators
133 CMatrix2d& operator=(const CMatrix2d& matrix);
134
135 CMatrix2d operator+(const BaseClass& matrix) const;
136 CMatrix2d operator-(const BaseClass& matrix) const;
141 CMatrix2d operator*(double scale) const;
145 CMatrix2d operator/(double scale) const;
146
147 // static methods
148 static const CMatrix2d& GetIdentity();
149
150private:
151 // static members
152 static CMatrix2d s_identity;
153};
154
155
156// inline methods
157
159{
160}
161
162
163inline CMatrix2d::CMatrix2d(const CMatrix2d& matrix)
164: BaseClass(matrix)
165{
166}
167
168
169inline CMatrix2d::CMatrix2d(const CVector2d& axisX, const CVector2d& axisY)
170{
171 SetAt(0, 0, axisX[0]);
172 SetAt(0, 1, axisX[1]);
173 SetAt(1, 0, axisY[0]);
174 SetAt(1, 1, axisY[1]);
175}
176
177
178inline CMatrix2d::CMatrix2d(double m11, double m12, double m21, double m22)
179{
180 SetAt(0, 0, m11);
181 SetAt(0, 1, m12);
182 SetAt(1, 0, m21);
183 SetAt(1, 1, m22);
184}
185
186
187inline CVector2d CMatrix2d::GetMultiplied(const CVector2d& position) const
188{
189 CVector2d retVal;
190
191 GetMultiplied(position, retVal);
192
193 return retVal;
194}
195
196
198{
199 CMatrix2d retVal;
200
201 GetMultiplied(matrix, retVal);
202
203 return retVal;
204}
205
206
208{
209 return CVector2d(GetAt(0, 0), GetAt(0, 1));
210}
211
212
214{
215 return CVector2d(GetAt(1, 0), GetAt(1, 1));
216}
217
218
220{
221 CVector2d result;
222
223 GetAxesLengths(result);
224
225 return result;
226}
227
228
229inline void CMatrix2d::GetAxesLengths(CVector2d& result) const
230{
231 result.SetX(GetAxisX().GetLength());
232 result.SetY(GetAxisY().GetLength());
233}
234
235
237{
238 CMatrix2d result;
239
240 GetInverted(result);
241
242 return result;
243}
244
245
247{
248 return CMatrix2d(GetAt(0, 0), GetAt(1, 0), GetAt(0, 1), GetAt(1, 1));
249}
250
251
252inline double CMatrix2d::GetDet() const
253{
254 return GetAt(0, 0) * GetAt(1, 1) - GetAt(0, 1) * GetAt(1, 0);
255}
256
257
258// operators
259
260inline CMatrix2d CMatrix2d::operator+(const BaseClass& matrix) const
261{
262 CMatrix2d retVal;
263
264 BaseClass::GetAdded(matrix, retVal);
265
266 return retVal;
267}
268
269
270inline CMatrix2d CMatrix2d::operator-(const BaseClass& matrix) const
271{
272 CMatrix2d retVal;
273
274 BaseClass::GetSubstracted(matrix, retVal);
275
276 return retVal;
277}
278
279
281{
282 CMatrix2d retVal;
283
284 BaseClass::GetNegated(retVal);
285
286 return retVal;
287}
288
289
291{
292 BaseClass::operator=(matrix);
293
294 return *this;
295}
296
297
298inline CMatrix2d CMatrix2d::operator*(double scale) const
299{
300 CMatrix2d retVal;
301
302 GetScaled(scale, retVal);
303
304 return retVal;
305}
306
307
308inline CMatrix2d CMatrix2d::operator/(double scale) const
309{
310 return CMatrix2d(GetAt(0, 0) / scale, GetAt(0, 1) / scale, GetAt(1, 0) / scale, GetAt(1, 1) / scale);
311}
312
313
314// static methods
315
317{
318 return s_identity;
319}
320
321
322} // namespace i2d
323
324
2D matrix.
Definition CMatrix2d.h:23
CMatrix2d operator-()
Definition CMatrix2d.h:280
void Multiply(const CMatrix2d &matrix)
CVector2d GetAxesLengths() const
Get lengths of axes vectors.
Definition CMatrix2d.h:219
void Reset()
Default reset to identity.
CMatrix2d GetTransposed() const
Calculate transposed matrix.
Definition CMatrix2d.h:246
CVector2d GetAxisX() const
Get axis X vector.
Definition CMatrix2d.h:207
CVector2d GetMultiplied(const CVector2d &position) const
Definition CMatrix2d.h:187
void MultiplyLeft(const CMatrix2d &matrix)
CMatrix2d GetInverted() const
Calculate inverted matrix.
Definition CMatrix2d.h:236
CVector2d GetAxisY() const
Get axis Y vector.
Definition CMatrix2d.h:213
CMatrix2d operator*(double scale) const
Multiplication by scalar number.
Definition CMatrix2d.h:298
CMatrix2d operator+(const BaseClass &matrix) const
Definition CMatrix2d.h:260
i2d::CVector2d GetInvMultiplied(const i2d::CVector2d &position) const
Inverted operation to GetApply().
static const CMatrix2d & GetIdentity()
Definition CMatrix2d.h:316
imath::TMatrix< 2, 2 > BaseClass
Definition CMatrix2d.h:25
void Reset(double angle, const CVector2d &scale, bool isPosDef=true)
Set the deformation matrix using specified angle (in radians) and scale determined for both axis sepa...
CMatrix2d()
Constructor with no member initialization.
Definition CMatrix2d.h:158
double GetApproxAngle() const
Get angle of axis X in radians.
bool GetEigenVectors(i2d::CVector2d &vector1, i2d::CVector2d &vector2, double &value1, double &value2) const
Calculate eigen vectors and eigen values.
CMatrix2d & operator=(const CMatrix2d &matrix)
Copy operator.
Definition CMatrix2d.h:290
CMatrix2d operator/(double scale) const
Division by scalar number.
Definition CMatrix2d.h:308
double GetDet() const
Calculate determinant of deformation matrix.
Definition CMatrix2d.h:252
double GetApproxScale() const
Get approximated scale.
bool GetInvMultiplied(const i2d::CVector2d &position, i2d::CVector2d &result) const
Inverted operation to GetApply().
bool GetInverted(CMatrix2d &result) const
Calculate inverted matrix.
void Reset(double angle, double scale=1.0, bool isPosDef=true)
Set the matrix using specified angle (in radians) and uniform scale.
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
void SetY(double y)
Set Y position of this vector.
Definition CVector2d.h:190
void SetX(double x)
Set X position of this vector.
Definition CVector2d.h:178
Definition of mathematical matrix with fixed dimensions.
Definition TMatrix.h:33
TMatrix< Height, Width, double > GetTransposed() const
Definition TMatrix.h:347
void GetAdded(const TMatrix< Width, Height, double > &matrix, TMatrix< Width, Height, double > &result) const
Definition TMatrix.h:735
void GetMultiplied(const TMatrix< SecondWidth, Width, double > &matrix, TMatrix< SecondWidth, Height, double > &result) const
Definition TMatrix.h:200
void GetNegated(TMatrix< Width, Height, double > &result)
Definition TMatrix.h:724
void GetScaled(double value, TMatrix< Width, Height, double > &result) const
Definition TMatrix.h:771
void SetAt(const IndexType &index, const ElementType &value)
Definition TMatrix.h:656
const ElementType & GetAt(const IndexType &index) const
Definition TMatrix.h:628
void GetSubstracted(const TMatrix< Width, Height, double > &matrix, TMatrix< Width, Height, double > &result) const
Definition TMatrix.h:746
Contains the 2D objects.
Definition CAffine2d.h:15

© Witold Gantzke and Kirill Lepskiy