Пример #1
0
// 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;
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
double Math::distance(MathVector a, MathVector b)
{
	MathVector delta = a - b;
	return delta.size();
}
Пример #5
0
double Math::size(MathVector in)
{
	return in.size();
}