Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

mmatrix.cpp

Go to the documentation of this file.
00001 #include "mmatrix.h"
00002 
00003 MMatrix::MMatrix (int m, int n) {
00004     if ((dimN > 4) || (dimM > 4)) {
00005     dimN = 0;
00006     dimM = 0;
00007     } else {
00008         dimN = n;
00009     dimM = m;
00010     };
00011     
00012     for (int x = 1; x <= MAX_MMATRIX_M; x++) {
00013     for (int y = 1; y <= MAX_MMATRIX_N; y++) {
00014         mat[x][y] = 0;
00015     };
00016     };
00017     
00018     return;
00019 };
00020 
00021 MMatrix::~MMatrix () {
00022 };
00023 
00024 int MMatrix::getM () {
00025     return dimM;
00026 };
00027 
00028 int MMatrix::getN () {
00029     return dimN;
00030 };
00031 
00032 void MMatrix::set (int m, int n, float val) {
00033     if ((m < 1) || (m > MAX_MMATRIX_M) || (n < 1) || (y > MAX_MMATRIX_N)) return;
00034     
00035     mat[m][n] = val;
00036 };
00037 
00038 float MMatrix::get (int m, int n) {
00039     if ((m < 1) || (m > MAX_MMATRIX_M) || (n < 1) || (y > MAX_MMATRIX_N)) return 0.0;
00040     
00041     return mat[m][n];
00042 };
00043 
00044 MMatrix MMatrix::trans () {
00045     MMatrix tmp(dimN, dimM);
00046     
00047     for (int x = 1; x <= dimN; x++) {
00048     for (int y = 1; y <= dimM; y++) {
00049         tmp.set (x, y, mat[y][x]);
00050     };
00051     };
00052     
00053     return tmp;
00054 };
00055         
00056 MMatrix MMatrix::operator+ (MMatrix m) {
00057     MMatrix tmp(dimM, dimN);
00058     
00059     if ((m.getN () != dimN) || (m.getM () != dimM)) return tmp;
00060     
00061     for (int x = 1; x <= dimM; x ++) {
00062     for (int y = 1; y <= dimN; y++) {
00063         tmp.set (x, y, (mat[x][y] + m.get (x, y)));
00064     };
00065     };
00066     
00067     return tmp;
00068 };
00069 
00070 MMatrix MMatrix::operator- (MMatrix m) {
00071     MMatrix tmp(dimM, dimN);
00072     
00073     if ((m.getN () != dimN) || (m.getM () != dimM)) return tmp;
00074     
00075     for (int x = 1; x <= dimM; x ++) {
00076     for (int y = 1; y <= dimN; y++) {
00077         tmp.set (x, y, (mat[x][y] - m.get (x, y)));
00078     };
00079     };
00080     
00081     return tmp;
00082 };
00083 
00084 MMatrix MMatrix::operator* (MMatrix m) {
00085     MMatrix tmp(m.getN (), dimM);
00086     float      f;
00087     
00088     if (dimN != m.getM ()) return tmp;
00089     
00090     for (int x = 1; x <= m.getM (); x ++) {
00091     for (int y = 1; y <= dimN; y++) {
00092         f = 0;
00093         for (int z = 1; z <= dimM; z++) {
00094         f += mat[z][y] * m.get (x, z);
00095         };
00096                 
00097         tmp.set (x, y, f);
00098     };
00099     };
00100     
00101     return tmp;
00102 };
00103 
00104 MMatrix MMatrix::operator* (float f) {
00105     MMatrix tmp(dimM, dimN);
00106     
00107     for (int x = 1; x <= dimM; x ++) {
00108     for (int y = 1; y <= dimN; y++) {
00109         tmp.set (x, y, (mat[x][y] * f));
00110     };
00111     };
00112     
00113     return tmp;
00114 };
00115 
00116 void MMatrix::operator= (Vector v) {
00117     dimM = 1;
00118     dimN = 3;
00119 
00120     mat[1][1] = v.x;
00121     mat[2][1] = v.y;
00122     mat[3][1] = v.z;
00123 };
00124     
00125 MMatrix MMatrix::homogen () {
00126     if ((dimN < MAX_MMATRIX_N) && (dimM < MAX_MMATRIX_M)) {
00127     MMatrix tmp (dimM + 1, dimN + 1);
00128     
00129     for (int x = 1; x <= dimM; x++) {
00130         for (int y = 1; y <= dimN; y++) {
00131         tmp.set (x, y, mat[x][y]);
00132         };
00133     };
00134     
00135     tmp.set (dimM +1, dimN +1, 1);
00136     return tmp;
00137     } else {
00138     MMatrix tmp;
00139     return tmp;
00140     };
00141 };
00142 
00143 MMatrix MMatrix::reduce () {
00144     if ((dimM > 1) && (dimN > 1)) {
00145     MMatrix tmp (dimM - 1, dimN - 1);
00146     
00147     for (int x = 1; x < dimM; x++) {
00148         for (int y = 1; y < dimN; y++) {
00149         tmp.set (x, y, mat[x][y]);
00150         };
00151     };
00152     
00153     return tmp;
00154     } else {
00155     MMatrix tmp;
00156     return tmp;
00157     };
00158 };

Generated at Sat May 13 13:50:20 2000 for 3Dsia by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000