Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/util/newmat/newmatrm.h @ 4565

Last change on this file since 4565 was 4565, checked in by patrick, 19 years ago

orxonox/trunk: added the newmat library to the project. needs some translation in directory, temp under util/newmat. is needed by the collision detection engine to perform lin alg operations such as eigenvector decomposition. perhaps we will make our own library to do that later.

File size: 3.8 KB
Line 
1//$$newmatrm.h                            rectangular matrix operations
2
3// Copyright (C) 1991,2,3,4: R B Davies
4
5#ifndef NEWMATRM_LIB
6#define NEWMATRM_LIB 0
7
8#ifdef use_namespace
9namespace NEWMAT {
10#endif
11
12// operations on rectangular matrices
13
14class RectMatrixCol;
15
16class RectMatrixRowCol
17// a class for accessing rows and columns of rectangular matrices
18{
19protected:
20#ifdef use_namespace              // to make namespace work
21public:
22#endif
23   Real* store;                   // pointer to storage
24   int n;                         // number of elements
25   int spacing;                   // space between elements
26   int shift;                     // space between cols or rows
27   RectMatrixRowCol(Real* st, int nx, int sp, int sh)
28      : store(st), n(nx), spacing(sp), shift(sh) {}
29   void Reset(Real* st, int nx, int sp, int sh)
30      { store=st; n=nx; spacing=sp; shift=sh; }
31public:
32   Real operator*(const RectMatrixRowCol&) const;         // dot product
33   void AddScaled(const RectMatrixRowCol&, Real);         // add scaled
34   void Divide(const RectMatrixRowCol&, Real);            // scaling
35   void Divide(Real);                                     // scaling
36   void Negate();                                         // change sign
37   void Zero();                                           // zero row col
38   Real& operator[](int i) { return *(store+i*spacing); } // element
39   Real SumSquare() const;                                // sum of squares
40   Real& First() { return *store; }                       // get first element
41   void DownDiag() { store += (shift+spacing); n--; }
42   void UpDiag() { store -= (shift+spacing); n++; }
43   friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
44   friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
45   FREE_CHECK(RectMatrixRowCol)
46};
47
48class RectMatrixRow : public RectMatrixRowCol
49{
50public:
51   RectMatrixRow(const Matrix&, int, int, int);
52   RectMatrixRow(const Matrix&, int);
53   void Reset(const Matrix&, int, int, int);
54   void Reset(const Matrix&, int);
55   Real& operator[](int i) { return *(store+i); }
56   void Down() { store += shift; }
57   void Right() { store++; n--; }
58   void Up() { store -= shift; }
59   void Left() { store--; n++; }
60   FREE_CHECK(RectMatrixRow)
61};
62
63class RectMatrixCol : public RectMatrixRowCol
64{
65public:
66   RectMatrixCol(const Matrix&, int, int, int);
67   RectMatrixCol(const Matrix&, int);
68   void Reset(const Matrix&, int, int, int);
69   void Reset(const Matrix&, int);
70   void Down() { store += spacing; n--; }
71   void Right() { store++; }
72   void Up() { store -= spacing; n++; }
73   void Left() { store--; }
74   friend void ComplexScale(RectMatrixCol&, RectMatrixCol&, Real, Real);
75   friend void Rotate(RectMatrixCol&, RectMatrixCol&, Real, Real);
76   FREE_CHECK(RectMatrixCol)
77};
78
79class RectMatrixDiag : public RectMatrixRowCol
80{
81public:
82   RectMatrixDiag(const DiagonalMatrix& D)
83      : RectMatrixRowCol(D.Store(), D.Nrows(), 1, 1) {}
84   Real& operator[](int i) { return *(store+i); }
85   void DownDiag() { store++; n--; }
86   void UpDiag() { store--; n++; }
87   FREE_CHECK(RectMatrixDiag)
88};
89
90
91inline RectMatrixRow::RectMatrixRow
92   (const Matrix& M, int row, int skip, int length)
93   : RectMatrixRowCol( M.Store()+row*M.Ncols()+skip, length, 1, M.Ncols() ) {}
94
95inline RectMatrixRow::RectMatrixRow (const Matrix& M, int row)
96   : RectMatrixRowCol( M.Store()+row*M.Ncols(), M.Ncols(), 1, M.Ncols() ) {}
97
98inline RectMatrixCol::RectMatrixCol
99   (const Matrix& M, int skip, int col, int length)
100   : RectMatrixRowCol( M.Store()+col+skip*M.Ncols(), length, M.Ncols(), 1 ) {}
101
102inline RectMatrixCol::RectMatrixCol (const Matrix& M, int col)
103   : RectMatrixRowCol( M.Store()+col, M.Nrows(), M.Ncols(), 1 ) {}
104
105inline Real square(Real x) { return x*x; }
106inline Real sign(Real x, Real y)
107   { return (y>=0) ? x : -x; }                    // assume x >=0
108
109
110
111
112
113
114#ifdef use_namespace
115}
116#endif
117
118#endif
119
120// body file: newmatrm.cpp
121
122
Note: See TracBrowser for help on using the repository browser.