#include <HxMatrix.h>
Constructors | |
HxMatrix () | |
Empty matrix. More... | |
HxMatrix (int nrow, int ncol) | |
Empty matrix with given number of rows and columns. More... | |
HxMatrix (int nrow, int ncol, double a) | |
Matrix with constant value. More... | |
HxMatrix (int nrow, int ncol, double *data) | |
Matrix with given data. More... | |
HxMatrix (const HxMatrix &m) | |
Copy constructor. More... | |
HxMatrix (const HxVector &v) | |
Copy from vector constructor. More... | |
HxMatrix (const HxVector &v1, const HxVector &v2) | |
Copy from 2 vectors constructor. More... | |
HxMatrix (const HxVector &v1, const HxVector &v2, const HxVector &v3) | |
Copy from 3 vectors constructor. More... | |
HxMatrix (const HxVector &v1, const HxVector &v2, const HxVector &v3, const HxVector &v4) | |
Copy from 4 vectors constructor. More... | |
HxMatrix (const HxVector &v1, const HxVector &v2, const HxVector &v3, const HxVector &v4, const HxVector &v5) | |
Copy from 5 vectors constructor. More... | |
HxMatrix (const HxVector &v1, const HxVector &v2, const HxVector &v3, const HxVector &v4, const HxVector &v5, const HxVector &v6) | |
Copy from 6 vectors constructor. More... | |
Inquiry | |
int | nRow () const |
Number of rows. More... | |
int | nCol () const |
Number of columns. More... | |
int | nElem () const |
Number of elements. More... | |
int | valid () const |
Indicates whether the matrix is valid. More... | |
Operators | |
HxMatrix & | operator= (double a) |
Assign constant value. More... | |
HxMatrix & | operator= (const HxMatrix &m) |
Normal assigment. More... | |
double * | operator[] (int i) const |
Subscripting, start with 0. More... | |
HxMatrix | operator- () const |
Unary minus. More... | |
HxMatrix | operator * (const HxMatrix &a, double b) |
Multiplication. More... | |
HxMatrix | operator * (double a, const HxMatrix &b) |
Multiplication. More... | |
HxMatrix | operator * (const HxMatrix &a, const HxMatrix &b) |
Multiplication. More... | |
HxVector | operator * (const HxVector &a, const HxMatrix &b) |
Multiplication. More... | |
HxVector | operator * (const HxMatrix &a, const HxVector &b) |
Multiplication. More... | |
HxMatrix | operator/ (const HxMatrix &a, double b) |
Division. More... | |
HxMatrix | operator/ (double a, const HxMatrix &b) |
Division. More... | |
HxMatrix | operator+ (const HxMatrix &a, const HxMatrix &b) |
Addition. More... | |
HxMatrix | operator+ (const HxMatrix &a, double b) |
Addition. More... | |
HxMatrix | operator+ (double a, const HxMatrix &b) |
Addition. More... | |
HxMatrix | operator- (const HxMatrix &a, const HxMatrix &b) |
Subtraction. More... | |
HxMatrix | operator- (const HxMatrix &a, double b) |
Subtraction. More... | |
HxMatrix | operator- (double a, const HxMatrix &b) |
Subtraction. More... | |
int | operator== (const HxMatrix &a, const HxMatrix &b) |
Equal. More... | |
int | operator!= (const HxMatrix &a, const HxMatrix &b) |
Not equal. More... | |
HxVec3Double | operator * (const HxVec3Double &a, const HxMatrix &b) |
Multiplication. More... | |
HxVec3Double | operator * (const HxMatrix &a, const HxVec3Double &b) |
Multiplication. More... | |
Operations | |
HxMatrix | i () const |
Inverse. More... | |
HxMatrix | t () const |
Transpose. More... | |
HxMatrix | svd (HxVector &W, HxMatrix &V) const |
Singular Value Decomposition. More... | |
HxMatrix | add (const HxMatrix &b) const |
Addition. More... | |
HxMatrix | add (const double val) const |
Addition. More... | |
HxMatrix | sub (const HxMatrix &b) const |
Subtraction. More... | |
HxMatrix | sub (const double val) const |
Subtraction. More... | |
HxMatrix | mul (const HxMatrix &b) const |
Multiplication. More... | |
HxMatrix | mul (const HxVector &v) const |
Multiplication. More... | |
HxMatrix | mul (const double val) const |
Multiplication. More... | |
HxMatrix | div (const double val) const |
Division. More... | |
HxMatrix | sin () const |
Apply sin to each element. More... | |
HxMatrix | cos () const |
Apply cos to each element. More... | |
HxMatrix | tan () const |
Apply tan to each element. More... | |
HxMatrix | sinh () const |
Apply sinh to each element. More... | |
HxMatrix | cosh () const |
Apply cosh to each element. More... | |
HxMatrix | tanh () const |
Apply tanh to each element. More... | |
HxMatrix | exp () const |
Apply exp to each element. More... | |
HxMatrix | log () const |
Apply log to each element. More... | |
HxMatrix | sqrt () const |
Apply sqrt to each element. More... | |
HxMatrix | abs () const |
Apply abs to each element. More... | |
HxMatrix | sgn () const |
Apply sgn to each element. More... | |
HxMatrix | map (double(*f)(double)) const |
Map f to each element of this. More... | |
Matrix generation | |
Generate coordinate transformation matrices for postfix vector multiplication | |
HxMatrix | translate2d (double x, double y) |
Translation in 2D. More... | |
HxMatrix | scale2d (double sx, double sy) |
Scaling in 2D. More... | |
HxMatrix | rotate2d (double alpha) |
Rotation in 2D (alpha in rad). More... | |
HxMatrix | rotate2dDeg (double alpha) |
Rotation in 2D (alpha in deg). More... | |
HxMatrix | reflect2d (int doX, int doY) |
Reflection in 2D (if (doX != 0) reflect X), etc. More... | |
HxMatrix | shear2d (double sx, double sy) |
Shearing in 2D. More... | |
HxMatrix | translate3d (double x, double y, double z) |
Translation in 3D. More... | |
HxMatrix | scale3d (double sx, double sy, double sz) |
Scaling in 3D. More... | |
HxMatrix | rotateX3d (double alpha) |
Rotation around X-axis in 3D (alpha in rad). More... | |
HxMatrix | rotateX3dDeg (double alpha) |
Rotation around X-axis in 3D (alpha in deg). More... | |
HxMatrix | rotateY3d (double alpha) |
Rotation around Y-axis in 3D (alpha in rad). More... | |
HxMatrix | rotateY3dDeg (double alpha) |
Rotation around Y-axis in 3D (alpha in deg). More... | |
HxMatrix | rotateZ3d (double alpha) |
Rotation around Z-axis in 3D (alpha in rad). More... | |
HxMatrix | rotateZ3dDeg (double alpha) |
Rotation around Z-axis in 3D (alpha in deg). More... | |
HxMatrix | reflect3d (int doX, int doY, int doZ) |
Reflection in 3D (if (doX != 0) reflect X), etc. More... | |
HxMatrix | projection (double f) |
Projection matrix. More... | |
HxMatrix | camera (double f) |
Camera transformation. More... | |
HxMatrix | lift2dTo3dXY () |
Lift 2D plane to 3D XY-plane. More... | |
Public Methods | |
~HxMatrix () | |
std::ostream & | put (std::ostream &os) const |
Friends | |
class | HxVector |
The dimensions are of arbitrary size.
|
Empty matrix.
00323 { 00324 _nr = 0; 00325 _nc = 0; 00326 _data = 0; 00327 } |
|
Empty matrix with given number of rows and columns.
|
|
Matrix with constant value.
|
|
Matrix with given data.
|
|
Copy constructor.
|
|
Copy from vector constructor.
|
|
Copy from 2 vectors constructor.
00048 { 00049 if (v1.nElem() != v2.nElem()) { 00050 error("differently sized input vectors for matrix construction."); 00051 _nr = 0; _nc = 0; _data = 0; 00052 return; 00053 } 00054 _nc = v1.nElem(); 00055 _nr = 2; 00056 _data = new double[_nr * _nc]; 00057 00058 double* t = v1._data; 00059 double* u = _data; 00060 int i = v1.nElem(); 00061 while (--i >= 0) 00062 *u++ = *t++; 00063 00064 i = v2.nElem(); 00065 t = v2._data; 00066 while (--i >= 0) 00067 *u++ = *t++; 00068 } |
|
Copy from 3 vectors constructor.
00071 { 00072 if ((v1.nElem() != v2.nElem()) || (v1.nElem() != v3.nElem())) { 00073 error("differently sized input vectors for matrix construction."); 00074 _nr = 0; _nc = 0; _data = 0; 00075 return; 00076 } 00077 _nc = v1.nElem(); 00078 _nr = 3; 00079 _data = new double[_nr * _nc]; 00080 00081 double* t = v1._data; 00082 double* u = _data; 00083 int i = v1.nElem(); 00084 while (--i >= 0) 00085 *u++ = *t++; 00086 00087 i = v2.nElem(); 00088 t = v2._data; 00089 while (--i >= 0) 00090 *u++ = *t++; 00091 00092 i = v3.nElem(); 00093 t = v3._data; 00094 while (--i >= 0) 00095 *u++ = *t++; 00096 } |
|
Copy from 4 vectors constructor.
00100 { 00101 if ((v1.nElem() != v2.nElem()) || (v1.nElem() != v3.nElem()) || 00102 (v1.nElem() != v4.nElem())) { 00103 error("differently sized input vectors for matrix construction."); 00104 _nr = 0; _nc = 0; _data = 0; 00105 return; 00106 } 00107 _nc = v1.nElem(); 00108 _nr = 4; 00109 _data = new double[_nr * _nc]; 00110 00111 double* t = v1._data; 00112 double* u = _data; 00113 int i = v1.nElem(); 00114 while (--i >= 0) 00115 *u++ = *t++; 00116 00117 i = v2.nElem(); 00118 t = v2._data; 00119 while (--i >= 0) 00120 *u++ = *t++; 00121 00122 i = v3.nElem(); 00123 t = v3._data; 00124 while (--i >= 0) 00125 *u++ = *t++; 00126 00127 i = v4.nElem(); 00128 t = v4._data; 00129 while (--i >= 0) 00130 *u++ = *t++; 00131 } |
|
Copy from 5 vectors constructor.
00135 { 00136 if ((v1.nElem() != v2.nElem()) || (v1.nElem() != v3.nElem()) || 00137 (v1.nElem() != v4.nElem()) || (v1.nElem() != v5.nElem())) { 00138 error("differently sized input vectors for matrix construction."); 00139 _nr = 0; _nc = 0; _data = 0; 00140 return; 00141 } 00142 _nc = v1.nElem(); 00143 _nr = 5; 00144 _data = new double[_nr * _nc]; 00145 00146 double* t = v1._data; 00147 double* u = _data; 00148 int i = v1.nElem(); 00149 while (--i >= 0) 00150 *u++ = *t++; 00151 00152 i = v2.nElem(); 00153 t = v2._data; 00154 while (--i >= 0) 00155 *u++ = *t++; 00156 00157 i = v3.nElem(); 00158 t = v3._data; 00159 while (--i >= 0) 00160 *u++ = *t++; 00161 00162 i = v4.nElem(); 00163 t = v4._data; 00164 while (--i >= 0) 00165 *u++ = *t++; 00166 00167 i = v5.nElem(); 00168 t = v5._data; 00169 while (--i >= 0) 00170 *u++ = *t++; 00171 } |
|
Copy from 6 vectors constructor.
00175 { 00176 if ((v1.nElem() != v2.nElem()) || (v1.nElem() != v3.nElem()) || 00177 (v1.nElem() != v4.nElem()) || (v1.nElem() != v5.nElem()) || 00178 (v1.nElem() != v6.nElem())) { 00179 error("differently sized input vectors for matrix construction."); 00180 _nr = 0; _nc = 0; _data = 0; 00181 return; 00182 } 00183 _nc = v1.nElem(); 00184 _nr = 6; 00185 _data = new double[_nr * _nc]; 00186 00187 double* t = v1._data; 00188 double* u = _data; 00189 int i = v1.nElem(); 00190 while (--i >= 0) 00191 *u++ = *t++; 00192 00193 i = v2.nElem(); 00194 t = v2._data; 00195 while (--i >= 0) 00196 *u++ = *t++; 00197 00198 i = v3.nElem(); 00199 t = v3._data; 00200 while (--i >= 0) 00201 *u++ = *t++; 00202 00203 i = v4.nElem(); 00204 t = v4._data; 00205 while (--i >= 0) 00206 *u++ = *t++; 00207 00208 i = v5.nElem(); 00209 t = v5._data; 00210 while (--i >= 0) 00211 *u++ = *t++; 00212 00213 i = v6.nElem(); 00214 t = v6._data; 00215 while (--i >= 0) 00216 *u++ = *t++; 00217 } |
|
Translation in 2D.
00221 { 00222 HxMatrix m(3,3); 00223 m[0][0] = 1; m[0][1] = 0; m[0][2] = x; 00224 m[1][0] = 0; m[1][1] = 1; m[1][2] = y; 00225 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00226 /* prefix: 00227 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; 00228 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; 00229 m[2][0] = x; m[2][1] = y; m[2][2] = 1; 00230 */ 00231 return m; 00232 } |
|
Scaling in 2D.
00236 { 00237 HxMatrix m(3,3); 00238 m[0][0] = sx; m[0][1] = 0; m[0][2] = 0; 00239 m[1][0] = 0; m[1][1] = sy; m[1][2] = 0; 00240 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00241 return m; 00242 } |
|
Rotation in 2D (alpha in rad).
00246 { 00247 HxMatrix m(3,3); 00248 m[0][0] = ::cos(alpha); m[0][1] = -::sin(alpha); m[0][2] = 0; 00249 m[1][0] = ::sin(alpha); m[1][1] = ::cos(alpha); m[1][2] = 0; 00250 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00251 /* prefix: 00252 m[0][0] = ::cos(alpha); m[0][1] = ::sin(alpha); m[0][2] = 0; 00253 m[1][0] = -::sin(alpha); m[1][1] = ::cos(alpha); m[1][2] = 0; 00254 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00255 */ 00256 return m; 00257 } |
|
Rotation in 2D (alpha in deg).
00261 { 00262 return rotate2d(M_PI*alpha/180.0); 00263 } |
|
Reflection in 2D (if (doX != 0) reflect X), etc.
00267 { 00268 double rx = (doX) ? -1 : 1; 00269 double ry = (doY) ? -1 : 1; 00270 HxMatrix m(3,3); 00271 m[0][0] = rx; m[0][1] = 0; m[0][2] = 0; 00272 m[1][0] = 0; m[1][1] = ry; m[1][2] = 0; 00273 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00274 return m; 00275 } |
|
Shearing in 2D.
00279 { 00280 HxMatrix m(3,3); 00281 m[0][0] = 1; m[0][1] = sx; m[0][2] = 0; 00282 m[1][0] = sy; m[1][1] = 1; m[1][2] = 0; 00283 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00284 /* prefix: 00285 m[0][0] = 1; m[0][1] = sy; m[0][2] = 0; 00286 m[1][0] = sx; m[1][1] = 1; m[1][2] = 0; 00287 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; 00288 */ 00289 return m; 00290 } |
|
Translation in 3D.
00294 { 00295 HxMatrix m(4,4); 00296 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = x; 00297 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = y; 00298 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = z; 00299 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00300 /* prefix: 00301 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00302 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00303 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0; 00304 m[3][0] = x; m[3][1] = y; m[3][2] = z; m[3][3] = 1; 00305 */ 00306 return m; 00307 } |
|
Scaling in 3D.
00311 { 00312 HxMatrix m(4,4); 00313 m[0][0] = sx; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00314 m[1][0] = 0; m[1][1] = sy; m[1][2] = 0; m[1][3] = 0; 00315 m[2][0] = 0; m[2][1] = 0; m[2][2] = sz; m[2][3] = 0; 00316 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00317 return m; 00318 } |
|
Rotation around X-axis in 3D (alpha in rad).
00322 { 00323 HxMatrix m(4,4); 00324 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00325 m[1][0] = 0; m[1][1] = ::cos(alpha); m[1][2] = -::sin(alpha); m[1][3] = 0; 00326 m[2][0] = 0; m[2][1] = ::sin(alpha); m[2][2] = ::cos(alpha); m[2][3] = 0; 00327 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00328 /* prefix 00329 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00330 m[1][0] = 0; m[1][1] = ::cos(alpha); m[1][2] = ::sin(alpha); m[1][3] = 0; 00331 m[2][0] = 0; m[2][1] = -::sin(alpha); m[2][2] = ::cos(alpha); m[2][3] = 0; 00332 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00333 */ 00334 return m; 00335 } |
|
Rotation around X-axis in 3D (alpha in deg).
00339 { 00340 return rotateX3d(M_PI*alpha/180.0); 00341 } |
|
Rotation around Y-axis in 3D (alpha in rad).
00345 { 00346 HxMatrix m(4,4); 00347 alpha = M_PI*alpha/180.0; 00348 m[0][0] = ::cos(alpha); m[0][1] = 0; m[0][2] = ::sin(alpha); m[0][3] = 0; 00349 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00350 m[2][0] = -::sin(alpha); m[2][1] = 0; m[2][2] = ::cos(alpha); m[2][3] = 0; 00351 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00352 /* prefix: 00353 m[0][0] = ::cos(alpha); m[0][1] = 0; m[0][2] = -::sin(alpha); m[0][3] = 0; 00354 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00355 m[2][0] = ::sin(alpha); m[2][1] = 0; m[2][2] = ::cos(alpha); m[2][3] = 0; 00356 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00357 */ 00358 return m; 00359 } |
|
Rotation around Y-axis in 3D (alpha in deg).
00363 { 00364 return rotateY3d(M_PI*alpha/180.0); 00365 } |
|
Rotation around Z-axis in 3D (alpha in rad).
00369 { 00370 HxMatrix m(4,4); 00371 m[0][0] = ::cos(alpha); m[0][1] = -::sin(alpha); m[0][2] = 0; m[0][3] = 0; 00372 m[1][0] = ::sin(alpha); m[1][1] = ::cos(alpha); m[1][2] = 0; m[1][3] = 0; 00373 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0; 00374 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00375 /* prefix: 00376 m[0][0] = ::cos(alpha); m[0][1] = ::sin(alpha); m[0][2] = 0; m[0][3] = 0; 00377 m[1][0] = -::sin(alpha); m[1][1] = ::cos(alpha); m[1][2] = 0; m[1][3] = 0; 00378 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0; 00379 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00380 */ 00381 return m; 00382 } |
|
Rotation around Z-axis in 3D (alpha in deg).
00386 { 00387 return rotateZ3d(M_PI*alpha/180.0); 00388 } |
|
Reflection in 3D (if (doX != 0) reflect X), etc.
00392 { 00393 double rx = (doX) ? -1 : 1; 00394 double ry = (doY) ? -1 : 1; 00395 double rz = (doZ) ? -1 : 1; 00396 HxMatrix m(4,4); 00397 m[0][0] = rx; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00398 m[1][0] = 0; m[1][1] = ry; m[1][2] = 0; m[1][3] = 0; 00399 m[2][0] = 0; m[2][1] = 0; m[2][2] = rz; m[2][3] = 0; 00400 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00401 return m; 00402 } |
|
Projection matrix.
00406 { 00407 HxMatrix m(4,4); 00408 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00409 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00410 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 1/f; 00411 m[3][0] = 0; m[3][1] = 0; m[3][2] = 0; m[3][3] = 1; 00412 /* prefix: 00413 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00414 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00415 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1; m[2][3] = 0; 00416 m[3][0] = 0; m[3][1] = 0; m[3][2] = 1/f; m[3][3] = 1; 00417 */ 00418 return m; 00419 } |
|
Camera transformation.
00423 { 00424 HxMatrix m(3,4); 00425 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00426 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00427 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1/f; m[2][3] = 1; 00428 /* prefix: 00429 HxMatrix m(4,3); 00430 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; 00431 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; 00432 m[2][0] = 0; m[2][1] = 0; m[2][2] = 1/f; 00433 m[3][0] = 0; m[3][1] = 0; m[3][2] = 1; 00434 */ 00435 return m; 00436 } |
|
Lift 2D plane to 3D XY-plane.
00440 { 00441 HxMatrix m(4,3); 00442 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; 00443 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; 00444 m[2][0] = 0; m[2][1] = 0; m[2][2] = 0; 00445 m[3][0] = 0; m[3][1] = 0; m[3][2] = 1; 00446 /* prefix: 00447 HxMatrix m(3,4); 00448 m[0][0] = 1; m[0][1] = 0; m[0][2] = 0; m[0][3] = 0; 00449 m[1][0] = 0; m[1][1] = 1; m[1][2] = 0; m[1][3] = 0; 00450 m[2][0] = 0; m[2][1] = 0; m[2][2] = 0; m[2][3] = 1; 00451 */ 00452 return m; 00453 } |
|
Number of rows.
00378 { 00379 return _nr; 00380 } |
|
Number of columns.
00384 { 00385 return _nc; 00386 } |
|
Number of elements.
00390 { 00391 return _nr * _nc; 00392 } |
|
Indicates whether the matrix is valid.
00396 { 00397 return ((_nc != 0) && (_nr != 0)); 00398 } |
|
Assign constant value.
|
|
Normal assigment.
|
|
Subscripting, start with 0.
00429 { 00430 return &_data[i*_nc]; 00431 } |
|
Unary minus.
|
|
Inverse.
00591 { 00592 if (nRow() != nCol()) { 00593 error("Inverse: matrix is not square!."); 00594 return HxMatrix(0, 0); 00595 } 00596 00597 int size = nRow(); 00598 HxMatrix m(size,size), tmp(*this); 00599 short* idx = new short [size]; 00600 double d; 00601 00602 if (!ludcmp(tmp._data, size, idx, &d)) { 00603 error( "Inverse: singular matrix can't be inverted." ); 00604 delete [] idx; 00605 return HxMatrix(0,0); 00606 } 00607 00608 double* res = new double [size]; 00609 00610 for (int j = 0; j < size; j++) { 00611 00612 // ADB 6 Feb 2001 - Fix for new 'for' scoping. 00613 int i; 00614 00615 for (i = 0; i < size; i++) 00616 res[i] = 0.0; 00617 res[j] = 1.0; 00618 lubksb(tmp._data, size, idx, res); 00619 for (i = 0; i < size; i++) 00620 m[i][j] = res[i]; 00621 } 00622 00623 delete [] res; 00624 delete [] idx; 00625 00626 return m; 00627 } |
|
Transpose.
|
|
Singular Value Decomposition. m = m.svd(W,V) * W.diag() * V.t()
00632 { 00633 int row = nRow(); 00634 int col = nCol(); 00635 00636 if (col > row) { 00637 error( "Svd: Matrix must be augmented with extra rows of zeros." ); 00638 W = HxVector(0); 00639 V = HxMatrix(0,0); 00640 return HxMatrix(0,0); 00641 } 00642 00643 HxMatrix U(*this); 00644 W = HxVector(col); 00645 V = HxMatrix(col,col); 00646 00647 svdcmp(U._data, W._data, V._data, col, row); 00648 00649 /* sort on eigenvalue */ 00650 for (int i = 0; i < col; i++) { 00651 int idx = i; 00652 double val = W[idx]; 00653 00654 for (int j = i+1; j < col; j++) 00655 if( W[j] > val ) { 00656 idx = j; 00657 val = W[idx]; 00658 } 00659 00660 if (idx != i) { 00661 val = W[idx]; W[idx] = W[i]; W[i] = val; 00662 00663 00664 // ADB 6 Feb 2001 - Fix for new 'for' scoping. 00665 int j; 00666 for (j = 0; j < col; j++) { 00667 val = V[j][idx]; 00668 V[j][idx] = V[j][i]; 00669 V[j][i] = val; 00670 } 00671 for (j = 0; j < row; j++) { 00672 val = U[j][idx]; 00673 U[j][idx] = U[j][i]; 00674 U[j][i] = val; 00675 } 00676 } 00677 } 00678 00679 return U; 00680 } |
|
Addition. Equivalent to : a+b
00684 { 00685 return *this+b; 00686 } |
|
Addition. Equivalent to : a+val
00690 { 00691 return *this+val; 00692 } |
|
Subtraction. Equivalent to : a-b
00696 { 00697 return *this-b; 00698 } |
|
Subtraction. Equivalent to : a-val
00702 { 00703 return *this-val; 00704 } |
|
Multiplication. Equivalent to : a*b
00708 { 00709 return *this*b; 00710 } |
|
Multiplication. Equivalent to : a*v
00720 { 00721 return *this*v; 00722 } |
|
Multiplication. Equivalent to : a*val
00714 { 00715 return *this*val; 00716 } |
|
Division. Equivalent to : a/val
00726 { 00727 return *this/val; 00728 } |
|
Apply sin to each element.
|
|
Apply cos to each element.
|
|
Apply tan to each element.
|
|
Apply sinh to each element.
|
|
Apply cosh to each element.
|
|
Apply tanh to each element.
|
|
Apply exp to each element.
|
|
Apply log to each element.
|
|
Apply sqrt to each element.
|
|
Apply abs to each element.
00786 { 00787 return map(::fabs); 00788 } |
|
Apply sgn to each element.
|
|
Map f to each element of this.
|
|
Multiplication.
|
|
Multiplication.
|
|
Multiplication.
00504 { 00505 if (a.nCol() != b.nRow()) { 00506 error("nonconformant HxMatrix * HxMatrix operands."); 00507 return HxMatrix(0,0); 00508 } 00509 HxMatrix m(a.nRow(), b.nCol()); 00510 double sum; 00511 int i, j, k; 00512 for (i=0 ; i<a.nRow() ; i++) { 00513 for (j=0 ; j<b.nCol() ; j++) { 00514 sum = 0; 00515 for (k=0 ; k<a.nCol() ; k++) 00516 sum += a[i][k] * b[k][j]; 00517 m[i][j] = sum; 00518 } 00519 } 00520 return m; 00521 } |
|
Multiplication.
00525 { 00526 if (a.nElem() != b.nRow()) { 00527 error("nonconformant HxVector * HxMatrix operands."); 00528 return HxVector(0); 00529 } 00530 HxVector v(b.nCol()); 00531 double sum; 00532 int i, j; 00533 for (i=0 ; i<b.nCol() ; i++) { 00534 sum = 0; 00535 for (j=0 ; j<b.nRow() ; j++) 00536 sum += a[j] * b[j][i]; 00537 v[i] = sum; 00538 } 00539 return v; 00540 } |
|
Multiplication.
00544 { 00545 if (b.nElem() != a.nCol()) { 00546 error("nonconformant HxMatrix * HxVector operands."); 00547 return HxVector(0); 00548 } 00549 HxVector v(a.nRow()); 00550 double sum; 00551 int i, j; 00552 for (i=0 ; i<a.nRow() ; i++) { 00553 sum = 0; 00554 for (j=0 ; j<a.nCol() ; j++) 00555 sum += a[i][j] * b[j]; 00556 v[i] = sum; 00557 } 00558 return v; 00559 } |
|
Division.
|
|
Division.
|
|
Addition.
00472 { 00473 if ((a.nCol() != b.nCol()) || (a.nRow() != b.nRow()) ) { 00474 error("nonconformant HxMatrix + HxMatrix operands."); 00475 return HxMatrix(0,0); 00476 } 00477 HxMatrix m(a.nRow(), b.nCol()); 00478 int i, j; 00479 for (i=0 ; i<a.nRow() ; i++) { 00480 for (j=0 ; j<a.nCol() ; j++) 00481 m[i][j] = a[i][j] + b[i][j]; 00482 } 00483 return m; 00484 } |
|
Addition.
|
|
Addition.
|
|
Subtraction.
00488 { 00489 if ((a.nCol() != b.nCol()) || (a.nRow() != b.nRow()) ) { 00490 error("nonconformant HxMatrix - HxMatrix operands."); 00491 return HxMatrix(0,0); 00492 } 00493 HxMatrix m(a.nRow(), b.nCol()); 00494 int i, j; 00495 for (i=0 ; i<a.nRow() ; i++) { 00496 for (j=0 ; j<a.nCol() ; j++) 00497 m[i][j] = a[i][j] - b[i][j]; 00498 } 00499 return m; 00500 } |
|
Subtraction.
|
|
Subtraction.
|
|
Equal.
|
|
Not equal.
00543 { 00544 return !(a == b); 00545 } |
|
Multiplication. Matrix must have matching dimensions.
00563 { 00564 if ((b.nRow() != 3) || (b.nCol() != 3)) { 00565 error("nonconformant HxVec3Double * HxMatrix operands."); 00566 return HxVec3Double(); 00567 } 00568 double v[3]; 00569 for (int i=0 ; i<b.nCol() ; i++) { 00570 v[i] = a.x()*b[i][0] + a.y()*b[i][1] + a.z()*b[i][2]; 00571 } 00572 return HxVec3Double(v[0], v[1], v[2]); 00573 } |
|
Multiplication. Matrix must have matching dimensions.
00577 { 00578 if ((a.nRow() != 3) || (a.nCol() != 3)) { 00579 error("nonconformant HxMatrix * HxVec3Double operands."); 00580 return HxVec3Double(); 00581 } 00582 double v[3]; 00583 for (int i=0 ; i<a.nRow() ; i++) { 00584 v[i] = a[i][0]*b.x() + a[i][1]*b.y() + a[i][2]*b.z(); 00585 } 00586 return HxVec3Double(v[0], v[1], v[2]); 00587 } |