1 | /************************************************************************* |
---|
2 | * * |
---|
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * |
---|
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org * |
---|
5 | * * |
---|
6 | * This library is free software; you can redistribute it and/or * |
---|
7 | * modify it under the terms of EITHER: * |
---|
8 | * (1) The GNU Lesser General Public License as published by the Free * |
---|
9 | * Software Foundation; either version 2.1 of the License, or (at * |
---|
10 | * your option) any later version. The text of the GNU Lesser * |
---|
11 | * General Public License is included with this library in the * |
---|
12 | * file LICENSE.TXT. * |
---|
13 | * (2) The BSD-style license that is included with this library in * |
---|
14 | * the file LICENSE-BSD.TXT. * |
---|
15 | * * |
---|
16 | * This library is distributed in the hope that it will be useful, * |
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * |
---|
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. * |
---|
20 | * * |
---|
21 | *************************************************************************/ |
---|
22 | |
---|
23 | // matrix class. this is mostly for convenience in the testing code, it is |
---|
24 | // not optimized at all. correctness is much more importance here. |
---|
25 | |
---|
26 | #ifndef _ODE_MAT_H_ |
---|
27 | #define _ODE_MAT_H_ |
---|
28 | |
---|
29 | #include <ode/common.h> |
---|
30 | |
---|
31 | |
---|
32 | class dMatrix { |
---|
33 | int n,m; // matrix dimension, n,m >= 0 |
---|
34 | dReal *data; // if nonzero, n*m elements allocated on the heap |
---|
35 | |
---|
36 | public: |
---|
37 | // constructors, destructors |
---|
38 | dMatrix(); // make default 0x0 matrix |
---|
39 | dMatrix (int rows, int cols); // construct zero matrix of given size |
---|
40 | dMatrix (const dMatrix &); // construct copy of given matrix |
---|
41 | // create copy of given data - element (i,j) is data[i*rowskip+j*colskip] |
---|
42 | dMatrix (int rows, int cols, dReal *_data, int rowskip, int colskip); |
---|
43 | ~dMatrix(); // destructor |
---|
44 | |
---|
45 | // data movement |
---|
46 | dReal & operator () (int i, int j); // reference an element |
---|
47 | void operator= (const dMatrix &); // matrix = matrix |
---|
48 | void operator= (dReal); // matrix = scalar |
---|
49 | dMatrix transpose(); // return transposed matrix |
---|
50 | // return a permuted submatrix of this matrix, made up of the rows in p |
---|
51 | // and the columns in q. p has np elements, q has nq elements. |
---|
52 | dMatrix select (int np, int *p, int nq, int *q); |
---|
53 | |
---|
54 | // operators |
---|
55 | dMatrix operator + (const dMatrix &); |
---|
56 | dMatrix operator - (const dMatrix &); |
---|
57 | dMatrix operator - (); |
---|
58 | dMatrix operator * (const dMatrix &); |
---|
59 | void operator += (const dMatrix &); |
---|
60 | void operator -= (const dMatrix &); |
---|
61 | |
---|
62 | // utility |
---|
63 | void clearUpperTriangle(); |
---|
64 | void clearLowerTriangle(); |
---|
65 | void makeRandom (dReal range); |
---|
66 | void print (char *fmt = "%10.4f ", FILE *f=stdout); |
---|
67 | dReal maxDifference (const dMatrix &); |
---|
68 | }; |
---|
69 | |
---|
70 | |
---|
71 | #endif |
---|