SpaceMatrix.h
Dosyayı İndir
#ifndef SPACEMATRIX_H_INCLUDED
#define SPACEMATRIX_H_INCLUDED
#include "MathUtilities.h"
#include "SpaceVector.h"
class SpaceMatrix {
public:
SpaceMatrix();
SpaceMatrix(double values[DIMENSION_COUNT][DIMENSION_COUNT]);
SpaceMatrix(const SpaceMatrix &another);
~SpaceMatrix();
SpaceVector &getRow (int index) const;
void setRow(int index,SpaceVector &row);
int getRowCount() const;
int getColumnCount() const;
double getValue (int row,int column) const;
void setValue (int row,int column,double value);
void print() const;
SpaceVector operator[] (int index) const;
SpaceVector &operator[] (int index);
friend SpaceMatrix operator*(const SpaceMatrix &left, const SpaceMatrix &right);
friend SpaceVector operator*(const SpaceMatrix &left, const SpaceVector &right);
friend SpaceMatrix operator*(const double &left, const SpaceMatrix &right);
protected:
SpaceVector **_table;
};
SpaceMatrix::SpaceMatrix() {
_table=new SpaceVector*[DIMENSION_COUNT];
for(int row=0;row<DIMENSION_COUNT;row++){
_table[row]=new SpaceVector();
}
}
SpaceMatrix::SpaceMatrix(double values[DIMENSION_COUNT][DIMENSION_COUNT])
{
_table=new SpaceVector*[DIMENSION_COUNT];
for(int row=0;row<DIMENSION_COUNT;row++){
_table[row]=new SpaceVector(values[row]);
}
}
SpaceMatrix::SpaceMatrix(const SpaceMatrix &another){
_table=new SpaceVector*[DIMENSION_COUNT];
for(int row=0;row<DIMENSION_COUNT;row++){
_table[row]=new SpaceVector(another.getRow(row));
}
}
SpaceMatrix::~SpaceMatrix(){
for(int row=0;row<DIMENSION_COUNT;row++){
delete &_table[row];
}
delete [] _table;
}
int SpaceMatrix::getRowCount() const{
return DIMENSION_COUNT;
}
int SpaceMatrix::getColumnCount() const{
return DIMENSION_COUNT;
}
SpaceVector &SpaceMatrix::getRow (int index) const{
return *_table[index];
}
void SpaceMatrix::setRow (int index,SpaceVector &value){
*_table[index]=value;
}
double SpaceMatrix::getValue (int row,int column) const{
return (*_table[row])[column];
}
void SpaceMatrix::setValue (int row,int column,double value){
(*_table[row])[column]=value;
}
void SpaceMatrix::print() const{
for(int row=0;row<getRowCount();row++){
(*_table[row]).print();
}
cout<<endl;
}
SpaceVector SpaceMatrix::operator [] (int index) const{
return *(_table[index]);
}
SpaceVector &SpaceMatrix::operator [] (int index) {
return *(_table[index]);
}
SpaceMatrix operator*(const SpaceMatrix &left, const SpaceMatrix &right){
SpaceMatrix result;
double product;
for(int row=0;row<DIMENSION_COUNT;row++){
for(int column=0;column<DIMENSION_COUNT;column++){
product=0;
for(int index=0;index<DIMENSION_COUNT;index++){
product+=left[row][index]*right[index][column];
}
result[row][column]=product;
}
}
return result;
}
SpaceVector operator*(const SpaceMatrix &left, const SpaceVector &right){
SpaceVector result;
double product;
for(int row=0;row<DIMENSION_COUNT;row++){
product=0;
for(int column=0;column<DIMENSION_COUNT;column++){
product+=left[row][column]*right[column];
}
result[row]=product;
}
return result;
}
SpaceMatrix operator*(const double &left, const SpaceMatrix &right){
SpaceMatrix result;
for(int row=0;row<DIMENSION_COUNT;row++){
for(int column=0;column<DIMENSION_COUNT;column++){
result[row][column]=left*right[row][column];
}
}
return result;
}
#endif
Dosyayı İndir