Jump to content
  • Advertisement
Sign in to follow this  
VanillaSnake21

What does -1.#IND mean?

This topic is 4219 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I print out a float to screen, that is supposed to be the degrees in radians between two vectors, I get -1.#IND, what could it mean? I thought maybe it means that the function that I used to compute it returned an imaginary number and thats how its displaying it, I couldn't find anything online on it. Thnx for replies.

Share this post


Link to post
Share on other sites
Advertisement
It means you've done something unlegal with the float, most likely there's a divide by zero you're missing somewhere. If you post the code (both calculating the angle as well as printing), we can help catch it and suggest a safer alternative.

-jouley

[Edit: Actually, dividing by zero yields a "1.#INF" error (emphasis mine). This points out that "1.#IND" is caused by trying to performing trigonometric operations on a number that's out of range (like acos(2.3f)).]

[Edit 2: Actually, dividing zero by zero yields a "-1.#IND" error (thanks, miodragsm!). My money's still on an illegal trig operation, though.]

Share this post


Link to post
Share on other sites
This means that the variable is not a number (NaN). This could be caused by using an unitialized variable or possibly dividing by zero.

Share this post


Link to post
Share on other sites
This is the parts of the source that I use to compue the angle between 2 vects.
Like Mr.Awesome said theres the value procuced for acos() is probably greater than 1.


BALL_angle += MXMATH::AngleBetweenVectors(spherePoint, nowPoint);

float MXMATH::AngleBetweenVectors(D3DXVECTOR3 v1, D3DXVECTOR3 v2)
{
return (float)(acos( (v1.x * v2.x + v1.y * v2.y + v1.z * v2.z)/(Vect3DLength(v1)*Vect3DLength(v2)) ));
}

float MXMATH::Vect3DLength(D3DXVECTOR3 v)
{
return (float)sqrt( sqr(v.x) + sqr(v.y) + sqr(v.z) );
}

Share this post


Link to post
Share on other sites
You should probably check that your argument to acos is in the interval [-1, 1]. Even a small amount outside this range will cause a NaN.

Share this post


Link to post
Share on other sites
You may want to look into the atan2(float y, float x) function. It'll get the quadrant correct for you, and can take any sort of input (except (0, 0)).
Usage, where point1 = x1, y1 and point2 = x2, y2:
float fAngle = atan2(y2 - y1, x2 - x1);

Share this post


Link to post
Share on other sites
Quote:
Original post by VanillaSnake21
Thanks for replies guys, I appreciate the help. Im just gonna check the input for acos() to make sure its not greater than 1 or less than -1. Thanks again.

Don't do that. At values close to 1 or -1, even those which don't look out of range, strange things can happen. acos is not a good way to find the angle between vectors.

For 3D vectors, the best way is atan2(dot(v1,v2), magnitude(cross(v1,v2))). This is robust and well-behaved under all circumstances.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!