Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Silly_con

Normalization Tolerance

This topic is 5557 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

Anyone could explain me how these tests works, the three makes similar tolerance test, but I don''t understand the math behind it const bool Vector::nearlyEqual(const Vector &v,const float s) const { const Vector _v = *this - v; //difference return _v.dot(_v) < s*s; //radius } const bool Vector::isNormalized(float tolerance) const { return fabsf(length() - 1.0f) <= tolerance; } const bool Vector::isNull(float tolerance) const { return PreModule() <= (tolerance * tolerance); } THANKS

Share this post


Link to post
Share on other sites
Advertisement
The first function is checking if the distance between two vectors is less than some threshold s. First it uses the fact that the dot product of a vector with itself is that vector''s magnitude squared. Then it uses the fact that for positive numbers if a < b then a^2 < b^2. It''s also faster to calculate the square of a number than the square root of a number, so instead of checking if the distance between the two vectors is less than s, it just checks if the distance squared is less than s squared.

The second function seems very self-explanatory to me... do you know much about vectors? Maybe I''m assuming you know more than you do. Do you know about vector addition, vector subtraction, vector magnitude, etc. ?

The third one... I have no idea what the function PreModule is. I assume it has something to do with the vector''s length since that''s what makes sense in that context.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
yes I know about vectors but not in computer field, its what I am trying to learn now, I understand all except this tolerance functions, the first you have explained me, thanks.
In the third, Premodule is (Length)^2 or sqrModule

Share this post


Link to post
Share on other sites
Let me take another approach here. I assume if you''re not familiar with vectors on computers then you''re not too familiar with floating point numbers either. Decimal numbers on computers, aka floating point numbers, are inexact because they have limited storage - since you can only store so many digits (in practice between about 6 and 15) the computer has to round numbers. This sometimes make them very unintuitive. Suppose for example that you have two floating point numbers A and B. What is A - B + B? The answer should be A, but it may not be because of the way the intermediate value A - B is rounded. Depending on the values of A and B the result might differ from A by a little, a lot, or not at all. This sort of rounding error can accumulate as you do more calculations, making it bad practice to compare floating point numbers directly for equality. Instead it''s usually better to see if the difference between two numbers is small enough that you can consider them almost equal, or "equal enough."

A 3d vector on a computer is usually stored as 3 floating point numbers, x y z. So what if you want to check if a vector is normalized (has magnitude 1)? If you simply check if length() == 1.0 then you''ll have problems because some vector that you think should have length 1.0 might actually have length 0.99999995 because of rounding errors. So instead you check if the difference between that length and 1 is less than some threshold, 0.1 or 0.01 or whatever depending on how strict you want your comparison to be.

Similarly if you want to check for the zero vector you don''t simply want to check if length == 0. If the length is 0.000001 that check will fail, again because of rounding errors, even though you intended it to pass. The solution again is to check if the length is less than some small threshold.

Does that help?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!