QCAD
Open Source 2D CAD
RMatrix.h
Go to the documentation of this file.
1 
20 #ifndef RMATRIX_H
21 #define RMATRIX_H
22 
23 #include "../core_global.h"
24 
25 #include "RMath.h"
26 
27 #define RMATRIX_TOLERANCE 1.0e-8
28 
37 public:
38  RMatrix();
39  RMatrix(int r, int c);
40  RMatrix(const RMatrix& other);
41  ~RMatrix();
42 
43  bool isValid() const;
44 
45  static RMatrix createIdentity2x2();
46  static RMatrix createIdentity3x3();
47  static RMatrix createIdentity(int size);
48  static RMatrix createRotation(double angle);
49  static RMatrix create2x2(double a11, double a12,
50  double a21, double a22);
51  static RMatrix create3x3(double a11, double a12, double a13,
52  double a21, double a22, double a23,
53  double a31, double a32, double a33);
54  static RMatrix create3x1(double a11, double a21, double a31);
55  static RMatrix create2x3(double a11, double a12, double a13,
56  double a21, double a22, double a23);
57 
61  RMatrix& operator =(const RMatrix& other);
65  bool operator ==(const RMatrix& other) const;
66 
67  RMatrix operator *(double s) const;
68 
72  RMatrix operator *=(double f);
76  RMatrix operator *(const RMatrix& other) const;
77 
78  RMatrix multiplyWith(const RMatrix& w) const;
79  RMatrix multiplyWith(double w) const;
80  RVector multiplyWith(const RVector& w) const;
81 
85  double* operator [](int i);
86 
87  void init(int r, int c);
88  void reset();
89  void clear();
90 
91  void set3x3(double a11, double a12, double a13,
92  double a21, double a22, double a23,
93  double a31, double a32, double a33);
94  void set3x1(double a11, double a21, double a31);
95  void set2x3(double a11, double a12,
96  double a13, double a21,
97  double a22, double a23);
98 
99  void set(int r, int c, double v);
100  double get(int r, int c) const;
101 
105  int getRows() const {
106  return rows;
107  }
111  int getCols() const {
112  return cols;
113  }
114 
115  bool rref();
116 
117  RMatrix getInverse() const;
118  RMatrix getTransposed() const;
119  RMatrix getAppended(const RMatrix& v) const;
120 
121  bool isRotationAndUniformScale() const;
122  double getUniformScaleFactor() const;
123  double getRotationAngle() const;
124 
125 protected:
126  bool ref(int startRow);
127  void multiplyRow(int r, double factor);
128  void addRow(int r, double factor, int r2);
129  void swapRows(int r1, int r2);
130  int getPivotRow(int startRow);
131  int getPivotCol(int r);
132 
133 private:
134  double** m;
135  int rows, cols;
136 };
137 
138 RMatrix operator *(double factor, const RMatrix& matrix);
139 
140 QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RMatrix& m);
141 
144 
145 #endif
RMatrix::rows
int rows
Definition: RMatrix.h:135
RMath.h
RVector
Represents a 3d vector (x/y/z).
Definition: RVector.h:46
RMatrix::getCols
int getCols() const
Definition: RMatrix.h:111
i
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition: autostart.js:49
RMatrix::m
double ** m
Definition: RMatrix.h:134
RMatrix::getRows
int getRows() const
Definition: RMatrix.h:105
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(RMath *)
operator<<
QCADCORE_EXPORT QDebug operator<<(QDebug dbg, const RMatrix &m)
Stream operator for QDebug.
Definition: RMatrix.cpp:695
RMatrix
Simple matrix class.
Definition: RMatrix.h:36
operator*
RMatrix operator*(double factor, const RMatrix &matrix)
Definition: RMatrix.cpp:688
init
void init(void basePath)
Definition: AddBlockInit.js:2
QCADCORE_EXPORT
#define QCADCORE_EXPORT
Definition: core_global.h:10