Sign in to follow this  
stakon

[DirectX9 C++] - D3DXVec3Normalize returns inaccurate results

Recommended Posts

Good day, I have found that by using D3DXVec3Normalize() an inaccurate result is returned. Theoretically a normalized vector pointing in the +y direction should be (0.0,1.0,0.0) However sometimes D3DXVec3Normalize() returns (0.0,0.99999994,0.0) This definitely isn't a normalized vector although the error is very small. Unfortunately this also leads to further errors, like comparing 2 vectors etc. Is there a way to get around this? Is there any better function than D3DXVec3Normalize which i can use? Thanx in advance, stakon

Share this post


Link to post
Share on other sites
That's a margin of error of 0.000006%, which is more than adequate for floating point values...

You can't directly compare floating point values anyway due to the way they work, I really wish operator== would give a warning. If you're comparing two floating point values, you should use an epsilon value anyway, e.g. instead of:
if(x == 1.0f)
Use:
static const float EPSILON = 0.00001f;
if(x > 1.0f-EPSILON && x < 1.0f+EPSILON)

Share this post


Link to post
Share on other sites
Thanx!

Such a warning would be useful indeed.

I think i'll use a slight variation of your method:

static const float EPSILON = 0.00001f;
float a,b; //floats to compare

if(abs(a - b) <EPSILON)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this