// overloaded multiplication of matrix by a vector MathVector MathMatrix::operator*(const MathVector& v) const { if (n != v.size()) { throw "Matrix and Vector do not"; } //Create matrix object of the correct size to hold the resulting matrix from multiplication MathVector temp(v.size()); //Go across the rows of the matrix the method was called on for (int i=0; i<nrows; i++) { //Declare empty variable to hold the multiplication result double sum = 0; //Go across the columns on the matrix that was passed as a parameter for (int j=0; j<ncols; j++) { sum+=(*this)(i, j) * v[0]; } //Set element in temp at the corresponding loop iteration index to the result temp[i] = sum; } return temp; }
MathVector Math::normal(MathVector a, MathVector b, MathVector c) { MathVector r1; MathVector r2; MathVector output; r2=c-b; r1=b-a; output = r1.cross(r2); output=(1.0f/output.size())*output; return output; }
Quat Math::rot2Quat( MathVector in) { MathVector inv = in; Quat nq; double invs; double phi; MathVector unitV; invs = inv.size(); if(invs != 0) { unitV = 1/invs * inv ; } else { unitV = MathVector(1,0,0); } phi = invs * 3.14159265/180; nq.v = sin(phi/2) * unitV; nq.scale = cos(phi/2); return nq; }
double Math::distance(MathVector a, MathVector b) { MathVector delta = a - b; return delta.size(); }
double Math::size(MathVector in) { return in.size(); }