Hello.
I'm having strange results of XMVector3AngleBetweenVectors function. Consider this code:
float angle = XMConvertToDegrees(XMVectorGetX(
XMVector3AngleBetweenVectors(GMathFV(XMFLOAT3(0.0f, 100.0f, 0.0f)),
GMathFV(XMFLOAT3(0.0f, 200.0f, 0.0f)))));
It's looking for angle between two 3D vectors, described by XMFLOAT3 structures. GMathFV is user-defined function which converts XMFLOAT3 to XMVECTOR as follows:
inline XMVECTOR GMathFV(XMFLOAT3& val)
{
return XMLoadFloat3(&val);
}
Everything else is directxmath.h library. Here everything is fine and result angle is 0.00000 just as expected.
But for other vectors with negative y-axis value, for example:
float angle = XMConvertToDegrees(XMVectorGetX(
XMVector3AngleBetweenVectors(GMathFV(XMFLOAT3(0.0f, -100.0f, 0.0f)),
GMathFV(XMFLOAT3(0.0f, -99.0f, 0.0f)))));
Result is 0.0197823402, which I can hardly call a zero angle.
Please someone help me figure out the problem. Is it negative number precision, too close vector coordinates or maybe something else?
UPD: It's very strange, because it gives 0.0197823402 for a(0.0f, 100.0f, 0.0f) x b(0.0f, 99.0f, 0.0f), but 0.000000 for a(0.0f, 101.0f, 0.0f) x b(0.0f, 100.0f, 0.0f)