• Create Account

### #ActualGuardianX

Posted 11 February 2013 - 07:35 AM

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)
{
}


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)

### #1GuardianX

Posted 11 February 2013 - 07:21 AM

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)
{
}


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?

PARTNERS