CMatrix3d.h
Go to the documentation of this file.
1 #ifndef i3d_CMatrix3d_included
2 #define i3d_CMatrix3d_included
3 
4 
5 // ACF includes
6 #include <imath/TMatrix.h>
7 #include <i3d/CVector3d.h>
8 
9 
10 namespace i3d
11 {
12 
13 
17 class CMatrix3d: public imath::TMatrix<3, 3>
18 {
19 public:
21 
25  CMatrix3d();
26  CMatrix3d(const CMatrix3d& transform);
30  CMatrix3d( const CVector3d& axisX,
31  const CVector3d& axisY,
32  const CVector3d& axisZ);
36  CMatrix3d( double m11, double m12, double m13,
37  double m21, double m22, double m23,
38  double m31, double m32, double m33);
39 
43  void Reset();
44 
45  // operations
47  CVector3d GetMultiplied(const CVector3d& position) const;
48  CMatrix3d GetMultiplied(const CMatrix3d& matrix) const;
49  void Multiply(const CMatrix3d& matrix);
50  void MultiplyLeft(const CMatrix3d& matrix);
51 
55  CVector3d GetAxisX() const;
56 
60  CVector3d GetAxisY() const;
61 
65  CVector3d GetAxisZ() const;
66 
70  CVector3d GetAxesLengths() const;
71 
75  void GetAxesLengths(CVector3d& result) const;
76 
80  i3d::CVector3d GetInvMultiplied(const i3d::CVector3d& position) const;
81 
85  bool GetInvMultiplied(const i3d::CVector3d& position, i3d::CVector3d& result) const;
86 
90  CMatrix3d GetInverted() const;
91 
95  bool GetInverted(CMatrix3d& result) const;
96 
98 
102  CMatrix3d GetTransposed() const;
103 
107  double GetDet() const;
108 
112  CMatrix3d& operator=(const CMatrix3d& matrix);
113 
117  CMatrix3d operator*(double scale) const;
121  CMatrix3d operator/(double scale) const;
122 
123  // static methods
124  static const CMatrix3d& GetIdentity();
125 
126 private:
127  // static members
128  static CMatrix3d s_identity;
129 };
130 
131 
132 // inline methods
133 
135 {
136 }
137 
138 
139 inline CMatrix3d::CMatrix3d(const CMatrix3d& matrix)
140 : BaseClass(matrix)
141 {
142 }
143 
144 
146  const CVector3d& axisX,
147  const CVector3d& axisY,
148  const CVector3d& axisZ)
149 {
150  SetAt(0, 0, axisX[0]);
151  SetAt(0, 1, axisX[1]);
152  SetAt(0, 2, axisX[2]);
153  SetAt(1, 0, axisY[0]);
154  SetAt(1, 1, axisY[1]);
155  SetAt(1, 2, axisY[2]);
156  SetAt(2, 0, axisZ[0]);
157  SetAt(2, 1, axisZ[1]);
158  SetAt(2, 2, axisZ[2]);
159 }
160 
161 
163  double m11, double m12, double m13,
164  double m21, double m22, double m23,
165  double m31, double m32, double m33)
166 {
167  SetAt(0, 0, m11);
168  SetAt(0, 1, m12);
169  SetAt(0, 2, m13);
170  SetAt(1, 0, m21);
171  SetAt(1, 1, m22);
172  SetAt(1, 2, m23);
173  SetAt(2, 0, m31);
174  SetAt(2, 1, m32);
175  SetAt(2, 2, m33);
176 }
177 
178 
179 inline CVector3d CMatrix3d::GetMultiplied(const CVector3d& position) const
180 {
181  CVector3d retVal;
182 
183  GetMultiplied(position, retVal);
184 
185  return retVal;
186 }
187 
188 
189 inline CMatrix3d CMatrix3d::GetMultiplied(const CMatrix3d& matrix) const
190 {
191  CMatrix3d retVal;
192 
193  GetMultiplied(matrix, retVal);
194 
195  return retVal;
196 }
197 
198 
200 {
201  return CVector3d(GetAt(0, 0), GetAt(0, 1), GetAt(0, 2));
202 }
203 
204 
206 {
207  return CVector3d(GetAt(1, 0), GetAt(1, 1), GetAt(1, 2));
208 }
209 
211 {
212  return CVector3d(GetAt(2, 0), GetAt(2, 1), GetAt(2, 2));
213 }
214 
215 
217 {
218  CVector3d result;
219 
220  GetAxesLengths(result);
221 
222  return result;
223 }
224 
225 
226 inline void CMatrix3d::GetAxesLengths(CVector3d& result) const
227 {
228  result.SetX(GetAxisX().GetLength());
229  result.SetY(GetAxisY().GetLength());
230  result.SetZ(GetAxisZ().GetLength());
231 }
232 
233 
235 {
236  CMatrix3d result;
237 
238  GetInverted(result);
239 
240  return result;
241 }
242 
243 
245 {
246  return CMatrix3d( GetAt(0, 0), GetAt(0, 1), GetAt(0, 2),
247  GetAt(1, 0), GetAt(1, 1), GetAt(1, 2),
248  GetAt(2, 0), GetAt(2, 1), GetAt(2, 2));
249 }
250 
251 
252 inline double CMatrix3d::GetDet() const
253 {
254  return (GetAt(0, 0) * GetAt(1, 1) * GetAt(2, 2)) +
255  (GetAt(0, 1) * GetAt(1, 2) * GetAt(2, 0)) +
256  (GetAt(0, 2) * GetAt(1, 0) * GetAt(2, 1)) -
257  (GetAt(0, 0) * GetAt(1, 2) * GetAt(2, 1)) -
258  (GetAt(0, 1) * GetAt(1, 0) * GetAt(2, 2)) -
259  (GetAt(0, 2) * GetAt(1, 1) * GetAt(2, 0));
260 }
261 
262 
263 // operators
264 
266 {
267  BaseClass::operator=(matrix);
268 
269  return *this;
270 }
271 
272 
273 inline CMatrix3d CMatrix3d::operator*(double scale) const
274 {
275  CMatrix3d retVal;
276 
277  GetScaled(scale, retVal);
278 
279  return retVal;
280 }
281 
282 
283 inline CMatrix3d CMatrix3d::operator/(double scale) const
284 {
285  return CMatrix3d( GetAt(0, 0) / scale,
286  GetAt(0, 1) / scale,
287  GetAt(0, 2) / scale,
288  GetAt(1, 0) / scale,
289  GetAt(1, 1) / scale,
290  GetAt(1, 2) / scale,
291  GetAt(2, 0) / scale,
292  GetAt(2, 1) / scale,
293  GetAt(2, 2) / scale);
294 }
295 
296 
297 // static methods
298 
300 {
301  return s_identity;
302 }
303 
304 
305 } // namespace i3d
306 
307 
308 #endif // !i3d_CMatrix3d_included
309 
CVector3d GetAxisY() const
Get axis Y vector.
Definition: CMatrix3d.h:205
const ElementType & GetAt(const IndexType &index) const
Get element stored at specified index.
CVector3d GetMultiplied(const CVector3d &position) const
Definition: CMatrix3d.h:179
TMatrix< Height, Width, double > GetTransposed() const
Get transposed matrix.
CVector3d GetAxesLengths() const
Get lengths of axes vectors.
Definition: CMatrix3d.h:216
void SetAt(const IndexType &index, const ElementType &value)
Set element at specified index.
CVector3d GetAxisZ() const
Get axis Z vector.
Definition: CMatrix3d.h:210
void MultiplyLeft(const CMatrix3d &matrix)
CMatrix3d & operator=(const CMatrix3d &matrix)
Copy operator.
Definition: CMatrix3d.h:265
CMatrix3d GetTransposed() const
Calculate transposed matrix.
Definition: CMatrix3d.h:244
i3d::CVector3d GetInvMultiplied(const i3d::CVector3d &position) const
Inverted operation to GetApply().
Definition of position or mathematical vector in 3D space.
Definition: CVector3d.h:21
3D-matrix definition.
Definition: CMatrix3d.h:17
CMatrix3d operator/(double scale) const
Division by scalar number.
Definition: CMatrix3d.h:283
CMatrix3d operator*(double scale) const
Multiplication by scalar number.
Definition: CMatrix3d.h:273
void Reset()
Default reset to identity.
CMatrix3d GetInverted() const
Calculate inverted matrix.
Definition: CMatrix3d.h:234
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
double GetDet() const
Calculate determinant of deformation matrix.
Definition: CMatrix3d.h:252
Definition of mathematical matrix with fixed dimensions.
Definition: TMatrix.h:27
void Multiply(const CMatrix3d &matrix)
imath::TMatrix< 3, 3 > BaseClass
Definition: CMatrix3d.h:20
CVector3d GetAxisX() const
Get axis X vector.
Definition: CMatrix3d.h:199
void SetX(double value)
Set X position of this vector.
Definition: CVector3d.h:146
static const CMatrix3d & GetIdentity()
Definition: CMatrix3d.h:299
void SetZ(double value)
Set Y position of this vector.
Definition: CVector3d.h:170
void SetY(double value)
Set Y position of this vector.
Definition: CVector3d.h:158
CMatrix3d()
Constructor with no member initialization.
Definition: CMatrix3d.h:134
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