| 1 |
/* |
| 2 |
* Copyright (C) 2000-2004 Object Oriented Parallel Simulation Engine (OOPSE) project |
| 3 |
* |
| 4 |
* Contact: oopse@oopse.org |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2.1 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* All we ask is that proper credit is given for our work, which includes |
| 11 |
* - but is not limited to - adding the above copyright notice to the beginning |
| 12 |
* of your source code files, and to any copyright notice that you may distribute |
| 13 |
* with programs based on this work. |
| 14 |
* |
| 15 |
* This program is distributed in the hope that it will be useful, |
| 16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
* GNU Lesser General Public License for more details. |
| 19 |
* |
| 20 |
* You should have received a copy of the GNU Lesser General Public License |
| 21 |
* along with this program; if not, write to the Free Software |
| 22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
/** |
| 27 |
* @file Matrix3x3d.hpp |
| 28 |
* @author Teng Lin |
| 29 |
* @date 10/11/2004 |
| 30 |
* @version 1.0 |
| 31 |
*/ |
| 32 |
#ifndef MATH_MATRIX3X3D_HPP |
| 33 |
#define MATH_MATRIX3X3D_HPP |
| 34 |
|
| 35 |
#include "Vector3d.hpp" |
| 36 |
|
| 37 |
namespace oopse { |
| 38 |
|
| 39 |
/** |
| 40 |
* @class Matrix3x3d Matrix3x3d.hpp "math/Matrix3x3d.hpp" |
| 41 |
* @brief A 3x3 matrix class |
| 42 |
*/ |
| 43 |
class Matrix3x3d{ |
| 44 |
public: |
| 45 |
|
| 46 |
/** default constructor */ |
| 47 |
Matrix3x3d(); |
| 48 |
|
| 49 |
/** Constructs and initializes every element of this matrix to a scalar */ |
| 50 |
Matrix3x3d(double s); |
| 51 |
|
| 52 |
/** |
| 53 |
* Return the reference of a single element of this matrix. |
| 54 |
* @return the reference of a single element of this matrix |
| 55 |
* @param i row index |
| 56 |
* @param j colum index |
| 57 |
*/ |
| 58 |
double& operator()(unsigned int i, unsigned int j) { return data_[i][j]; } |
| 59 |
|
| 60 |
/** |
| 61 |
* Return the value of a single element of this matrix. |
| 62 |
* @return the value of a single element of this matrix |
| 63 |
* @param i row index |
| 64 |
* @param j colum index |
| 65 |
*/ |
| 66 |
double operator()(unsigned int i, unsigned int j) const { return data_[i][j]; } |
| 67 |
|
| 68 |
/** |
| 69 |
* Returns a row of this matrix as a vector. |
| 70 |
* @return a row of this matrix as a vector |
| 71 |
* @param i the row index |
| 72 |
*/ |
| 73 |
Vector3d getRow(unsigned int i); |
| 74 |
|
| 75 |
/** |
| 76 |
* Sets a row of this matrix |
| 77 |
* @param i the row index |
| 78 |
* @param v the vector to be set |
| 79 |
*/ |
| 80 |
void setRow(unsigned int i, const Vector3d& v); |
| 81 |
|
| 82 |
/** |
| 83 |
* Returns a column of this matrix as a vector. |
| 84 |
* @return a column of this matrix as a vector |
| 85 |
* @param i the column index |
| 86 |
*/ |
| 87 |
Vector3d getColum(unsigned int i); |
| 88 |
|
| 89 |
/** |
| 90 |
* Sets a column of this matrix |
| 91 |
* @param i the column index |
| 92 |
* @param v the vector to be set |
| 93 |
*/ |
| 94 |
void setColum(unsigned int i, const Vector3d& v); |
| 95 |
|
| 96 |
/** |
| 97 |
* Adds a scalar into every element of this matrix. |
| 98 |
* @param s the scalar value |
| 99 |
*/ |
| 100 |
Matrix3x3d& operator +=(const double s); |
| 101 |
|
| 102 |
/** |
| 103 |
* Subtracts a scalar from every element of this matrix. |
| 104 |
* @param s the scalar value |
| 105 |
*/ |
| 106 |
Matrix3x3d& operator -=(const double s); |
| 107 |
|
| 108 |
/** |
| 109 |
* Multiples a scalar into every element of this matrix. |
| 110 |
* @param s the scalar value |
| 111 |
*/ |
| 112 |
Matrix3x3d& operator *=(const double s); |
| 113 |
|
| 114 |
Matrix3x3d& operator /=(const double s); |
| 115 |
|
| 116 |
/** |
| 117 |
* Sets the value of this matrix to the sum of the other matrix and itself (*this += m). |
| 118 |
* @param m the other matrix |
| 119 |
*/ |
| 120 |
Matrix3x3d& operator += (const Matrix3x3d& m); |
| 121 |
|
| 122 |
/** |
| 123 |
* Sets the value of this matrix to the differerence of itself and the other matrix (*this -= m) |
| 124 |
* @param m the other matrix |
| 125 |
*/ |
| 126 |
Matrix3x3d& operator -= (const Matrix3x3d& m); |
| 127 |
|
| 128 |
/** Returns the inverse of this matrix. */ |
| 129 |
Matrix3x3d inverse(); |
| 130 |
|
| 131 |
/** Returns the transpose of this matrix. */ |
| 132 |
Matrix3x3d transpose(); |
| 133 |
|
| 134 |
/** Returns the determinant of this matrix. */ |
| 135 |
double determinant() const; |
| 136 |
|
| 137 |
/** Returns the trace of this matrix. */ |
| 138 |
double trace() const; |
| 139 |
|
| 140 |
/** Tests if this matrix is symmetrix. */ |
| 141 |
bool isSymmetric() const; |
| 142 |
|
| 143 |
/** Tests if this matrix is orthogona. */ |
| 144 |
bool isOrthogonal() const; |
| 145 |
|
| 146 |
/** Tests if this matrix is diagonal. */ |
| 147 |
bool isDiagonal() const; |
| 148 |
|
| 149 |
/** Tests if this matrix is the unit matrix. */ |
| 150 |
bool isUnitMatrix() const; |
| 151 |
|
| 152 |
/** Negate the value of every element of this matrix. */ |
| 153 |
friend inline Matrix3x3d operator -(const Matrix3x3d& m); |
| 154 |
|
| 155 |
/** |
| 156 |
* Return the sum of two matrixes (m1 + m2). |
| 157 |
* @return the sum of two matrixes |
| 158 |
* @param m1 the first matrix |
| 159 |
* @param m2 the second matrix |
| 160 |
*/ |
| 161 |
friend inline Matrix3x3d operator + (const Matrix3x3d& m1, const Matrix3x3d& m2); |
| 162 |
|
| 163 |
/** |
| 164 |
* Return the difference of two matrixes (m1 - m2). |
| 165 |
* @return the sum of two matrixes |
| 166 |
* @param m1 the first matrix |
| 167 |
* @param m2 the second matrix |
| 168 |
*/ |
| 169 |
friend inline Matrix3x3d operator - (const Matrix3x3d& m1, const Matrix3x3d& m2); |
| 170 |
|
| 171 |
/** |
| 172 |
* Return the multiplication of two matrixes (m1 * m2). |
| 173 |
* @return the multiplication of two matrixes |
| 174 |
* @param m1 the first matrix |
| 175 |
* @param m2 the second matrix |
| 176 |
*/ |
| 177 |
friend inline Matrix3x3d operator * (const Matrix3x3d& m1, const Matrix3x3d& m2); |
| 178 |
|
| 179 |
/** |
| 180 |
* Return the multiplication of matrixes and vector (m1 * v1). |
| 181 |
* @return the multiplication of matrixes and vector |
| 182 |
* @param m1 the matrix |
| 183 |
* @param v1 the vector |
| 184 |
*/ |
| 185 |
friend inline Matrix3x3d operator * (const Matrix3x3d& m1, const Matrix3x3d& v1); |
| 186 |
|
| 187 |
protected: |
| 188 |
double data_[3][3]; /**< matrix element */ |
| 189 |
|
| 190 |
} |
| 191 |
} |
| 192 |
#endif //MATH_MATRIX3X3D_HPP |