Algebra3D
Algebra for 3D transformations
 All Classes Namespaces Files Functions Variables Typedefs Macros
Matrix3.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Jaroslaw Glowacki
3  * jarek (dot) glowacki (at) gmail (dot) com
4  *
5  * This file is part of algebra3d.
6  *
7  * algebra3d is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * algebra3d is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with algebra3d. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
26 #ifndef _MATRIX_H_
27 #define _MATRIX_H_
28 
29 #include<algebra3d/global.h>
30 
31 namespace algebra3d {
32 
33 /* Forward declarations */
34 template<class fpType>
35 class Vector3;
36 template<class fpType>
37 class Quaternion;
38 
47 template<class fpType>
48 class Matrix3 {
49  // Friendship declarations
50  template<class fpT>
51  friend std::istream& operator>>(std::istream &stream, Matrix3<fpT> &mat);
52 
53 protected:
62  static const int ADJUGATE_INDICES[3][3][4][2];
63 
65  fpType data[3][3];
66 
67 protected:
76  virtual void initialize(bool identity = false);
77 
78 public:
86  Matrix3(bool identity = false);
87 
94  Matrix3(const fpType(&data)[3][3]);
95 
103  Matrix3(const fpType *data);
104 
114  Matrix3(const Vector3<fpType> &col1, const Vector3<fpType> &col2,
115  const Vector3<fpType> &col3);
116 
130  Matrix3(fpType m11, fpType m12, fpType m13, //
131  fpType m21, fpType m22, fpType m23, //
132  fpType m31, fpType m32, fpType m33);
133 
139  Matrix3(const Matrix3<fpType> &mat);
140 
147  Matrix3(const Vector3<fpType> &cvec);
148 
156  Matrix3(Vector3<fpType> axis, fpType angle);
157 
163  Matrix3(const Quaternion<fpType> &quat);
164 
168  virtual ~Matrix3();
169 
175  virtual void set(const fpType data[3][3]);
176 
184  virtual void set(const Vector3<fpType> &col1, const Vector3<fpType> &col2,
185  const Vector3<fpType> &col3);
186 
192  virtual void get(fpType storage[3][3]) const;
193 
202  virtual void get(fpType * const col1, fpType * const col2,
203  fpType * const col3) const;
204 
211  virtual void setColumn(int index, const Vector3<fpType> &col);
212 
219  virtual void getColumn(int index, fpType * const &col);
220 
226  virtual Vector3<fpType> getColumn(int index);
227 
233  fpType getTrace() const;
234 
238  virtual void transpose();
239 
245  virtual Matrix3 getTranspose() const;
246 
256  Vector3<fpType> getAxis() const;
257 
264  fpType getAngle() const;
265 
270  virtual void invert();
271 
278  virtual Matrix3 getInverse() const;
279 
285  virtual fpType det();
286 
294  virtual bool isOrthogonal();
295 
301  virtual void operator=(const Matrix3 &mat);
302 
312  virtual const fpType (&operator[](int i1) const)[3];
313 
322 virtual fpType (&operator[](int i1))[3];
323 
336  virtual bool compare(const Matrix3<fpType> &mat, const fpType &precision =
337  PRECISION) const;
338 
348  virtual bool operator==(const Matrix3 &mat) const;
349 
359  virtual bool operator!=(const Matrix3 &mat) const;
360 
366  virtual void operator+=(const Matrix3 &mat);
367 
374  virtual Matrix3 operator+(const Matrix3 &mat) const;
375 
381  virtual Matrix3 operator-() const;
382 
388  virtual void operator-=(const Matrix3 &mat);
389 
396  virtual Matrix3 operator-(const Matrix3 &mat) const;
397 
403  virtual void operator*=(const Matrix3 &mat);
404 
412  virtual Matrix3 operator*(const Matrix3 &mat) const;
413 
421  virtual Vector3<fpType> operator*(const Vector3<fpType> &vec) const;
422 
428  virtual void operator*=(const fpType &scale);
429 
436  virtual Matrix3 operator*(const fpType &scale) const;
437 
443  virtual void operator/=(const fpType &scale);
444 
452  virtual Matrix3 operator/(const fpType &scale) const;
453 };
454 
462 template<class fpType>
463 Matrix3<fpType> operator*(const double &scale, const Matrix3<fpType> &mat);
464 
472 template<class fpType>
473 Matrix3<fpType> operator*(const float &scale, const Matrix3<fpType> &mat);
474 
482 template<class fpType>
483 std::ostream& operator<<(std::ostream &stream, const Matrix3<fpType> &mat);
484 
492 template<class fpType>
493 std::istream& operator>>(std::istream &stream, Matrix3<fpType> &mat);
494 
501 
508 
509 } /* namespace algebra3d */
510 
511 #endif /* _MATRIX_H_ */
fpType data[3][3]
Definition: Matrix3.h:65
virtual void setColumn(int index, const Vector3< fpType > &col)
virtual Matrix3 getInverse() const
virtual void operator+=(const Matrix3 &mat)
virtual void invert()
virtual Matrix3 operator+(const Matrix3 &mat) const
A class to store vectors of 3 elements.
Definition: Matrix3.h:35
std::istream & operator>>(std::istream &stream, Matrix3< fpType > &mat)
virtual void getColumn(int index, fpType *const &col)
virtual void operator/=(const fpType &scale)
virtual void operator=(const Matrix3 &mat)
fpType getAngle() const
virtual bool operator==(const Matrix3 &mat) const
fpType getTrace() const
Matrix3(bool identity=false)
virtual void operator-=(const Matrix3 &mat)
virtual bool compare(const Matrix3< fpType > &mat, const fpType &precision=PRECISION) const
Matrix3< fpType > operator*(const double &scale, const Matrix3< fpType > &mat)
virtual void initialize(bool identity=false)
Matrix3< float > Matrix3F
Definition: Matrix3.h:507
A class to store 3x3 rotation matrices.
Definition: Matrix3.h:48
virtual Matrix3 operator-() const
virtual bool operator!=(const Matrix3 &mat) const
static const int ADJUGATE_INDICES[3][3][4][2]
Definition: Matrix3.h:62
#define PRECISION
Definition: global.h:51
virtual void transpose()
virtual fpType det()
virtual Matrix3 operator/(const fpType &scale) const
Matrix3< double > Matrix3D
Definition: Matrix3.h:500
A class to store quaternions.
Definition: Matrix3.h:37
virtual void operator*=(const Matrix3 &mat)
virtual Matrix3 getTranspose() const
virtual void set(const fpType data[3][3])
Vector3< fpType > getAxis() const
virtual Matrix3 operator*(const Matrix3 &mat) const
virtual bool isOrthogonal()