Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef MATRIX_H
00012 #define MATRIX_H
00013
00014 #include "mat2.h"
00015 #include "mat3.h"
00016
00022 class Matrix
00023 {
00024 public:
00025
00027 Matrix(unsigned lines, unsigned columns){
00028 m_Lines = lines;
00029 m_Columns = columns;
00030 m_Values = new double[lines*columns];
00031 for (unsigned i = 0; i< lines*columns; i++) {
00032 m_Values[i] = 0;
00033 }
00034 }
00035
00036 Matrix(const CMat2 matrix2) {
00037 m_Lines = 2;
00038 m_Columns = 2;
00039 m_Values = new double[4];
00040 for(unsigned i = 0; i < m_Lines * m_Columns; i++) {
00041 m_Values[i] = matrix2.valueAt(i);
00042 }
00043 }
00044
00045 Matrix(const CMat3 matrix3) {
00046 m_Lines = 3;
00047 m_Columns = 3;
00048 m_Values = new double[9];
00049 for(unsigned i = 0; i < m_Lines * m_Columns; i++) {
00050 m_Values[i] = matrix3.valueAt(i);
00051 }
00052 }
00053
00055 ~Matrix() {
00056 delete[] m_Values;
00057 }
00058
00059 inline double getValue(int line, int column) const{
00060 return m_Values[line*m_Columns + column];
00061 }
00062
00063 inline void setValue(int line, int column, double value) {
00064 m_Values[line*m_Columns + column] = value;
00065 }
00066
00067 Matrix transpose();
00068
00069 Matrix operator *(double scalar){
00070 Matrix returnMatrix(m_Lines, m_Columns);
00071 for (unsigned i = 0; i < m_Lines * m_Columns; i++) {
00072 returnMatrix.setValue(i/m_Lines, i%m_Lines, this->getValue(i/m_Lines, i%m_Lines) * scalar);
00073 }
00074 return returnMatrix;
00075 }
00076
00077 Matrix operator /(double scalar){
00078 Matrix returnMatrix(m_Lines, m_Columns);
00079 for (unsigned i = 0; i < m_Lines * m_Columns; i++) {
00080 returnMatrix.setValue(i/m_Lines, i%m_Lines, this->getValue(i/m_Lines, i%m_Lines) / scalar);
00081 }
00082 return returnMatrix;
00083 }
00084
00085 Matrix operator *(const Matrix rhs){
00086 Matrix returnMatrix(m_Lines, m_Columns);
00087 for (unsigned i = 0; i < m_Lines * m_Columns; i++) {
00088 returnMatrix.setValue(i/m_Lines, i%m_Lines, this->getValue(i/m_Lines, i%m_Lines) * rhs.getValue(i%m_Lines, i/m_Lines));
00089 }
00090 return returnMatrix;
00091 }
00092
00093 Matrix operator +(const Matrix rhs){
00094 Matrix returnMatrix(m_Lines, m_Columns);
00095 for (unsigned i = 0; i < m_Lines * m_Columns; i++) {
00096 returnMatrix.setValue(i/m_Lines, i%m_Lines, this->getValue(i/m_Lines, i%m_Lines) + rhs.getValue(i/m_Lines, i%m_Lines));
00097 }
00098 return returnMatrix;
00099 }
00100
00101 Matrix operator -(const Matrix rhs){
00102 Matrix returnMatrix(m_Lines, m_Columns);
00103 for (unsigned i = 0; i < m_Lines * m_Columns; i++) {
00104 returnMatrix.setValue(i/m_Lines, i%m_Lines, this->getValue(i/m_Lines, i%m_Lines) - rhs.getValue(i/m_Lines, i%m_Lines));
00105 }
00106 return returnMatrix;
00107 }
00108
00109 private:
00110
00111 unsigned int m_Lines;
00112 unsigned int m_Columns;
00113 double* m_Values;
00114 };
00115
00116 #endif