Originally Posted by
nerexis
Looks like its wrong.
I made function based on your suggestion, tried to calculate angle between vectors i posted in 1 first post and it doesn't work.
Returns -1.#IND00 :P
Function:
Code:
float AngleTo(const Vector3df& q)
{
Vector3df v1(this->X,this->Y,this->Z);
Vector3df v2(q);
return acos(sqrt( (v2.X * v1.X) + (v2.Y * v1.Y)) / v2.Magnitude() - v1.Magnitude() )*180/PI;
}
Why '^2'?..
I think your first appraoch is right.
The angle between 2 vectors is defined by
Code:
cos(a) = abs(vec1 * vec2) / ( abs(vec1) * abs(vec2) )
which means
Code:
cos(a) = abs(vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z + ) / ( sqrt(vec1.x^2 + vec1.y^2 + vec1.z^2) * sqrt(vec2.x^2 + vec2.y^2 + vec2.z^2) )
edit
This is what a code could look like
Code:
acos( abs(vec1.x * vec2.x + vec1.y * vec2.y + vec1.z * vec2.z + ) / ( sqrt( pow(vec1.x,2) + pow(vec1.y,2) + pow(vec1.z,2) ) * sqrt( pow(vec2.x,2) + pow(vec2.y,2) + pow(vec2.z,2) ) ) )