QCAD Application Framework
CAD Application Development and Automation.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RMatrix.h
Go to the documentation of this file.
1 #ifndef RMATRIX_H
2 #define RMATRIX_H
3 
4 #include "RMath.h"
5 
6 #define RMATRIX_TOLERANCE 1.0e-8
7 
14 class RMatrix {
15 public:
16  RMatrix();
17  RMatrix(int r, int c);
18  RMatrix(const RMatrix& other);
19  ~RMatrix();
20 
21  bool isValid() const;
22 
23  static RMatrix createIdentity2x2();
24  static RMatrix createIdentity3x3();
25  static RMatrix createIdentity(int size);
26  static RMatrix create3x3(double a11, double a12, double a13, double a21,
27  double a22, double a23, double a31, double a32, double a33);
28  static RMatrix create3x1(double a11, double a21, double a31);
29  static RMatrix create2x3(double a11, double a12, double a13, double a21,
30  double a22, double a23);
31 
32  RMatrix& operator =(const RMatrix& other);
33  bool operator ==(const RMatrix& other) const;
34  RMatrix operator *=(double f);
35  RMatrix operator *(const RMatrix& other) const;
36  RMatrix multiplyWith(const RMatrix& w) const;
37  double* operator [](int i);
38 
39  void init(int r, int c);
40  void reset();
41  void clear();
42 
43  void set3x3(double a11, double a12, double a13, double a21, double a22,
44  double a23, double a31, double a32, double a33);
45  void set3x1(double a11, double a21, double a31);
46  void set2x3(double a11, double a12, double a13, double a21, double a22,
47  double a23);
48 
49  void set(int r, int c, double v);
50  double get(int r, int c) const;
51 
55  int getRows() const {
56  return rows;
57  }
61  int getCols() const {
62  return cols;
63  }
64 
65  void print() const;
66  void printRow(int r) const;
67 
68  bool rref();
69 
70  RMatrix getInverse() const;
71  RMatrix getTransposed() const;
72  RMatrix getAppended(const RMatrix& v) const;
73 
74 protected:
75  bool ref(int startRow);
76  void multiplyRow(int r, double factor);
77  void addRow(int r, double factor, int r2);
78  void swapRows(int r1, int r2);
79  int getPivotRow(int startRow);
80  int getPivotCol(int r);
81 
82 private:
83  double** m;
84  int rows, cols;
85 };
86 
87 RMatrix operator *(const RMatrix& matrix, double factor);
88 RMatrix operator *(double factor, const RMatrix& matrix);
89 
92 
93 #endif