• Advertisement
Sign in to follow this  

Bounding Volumes

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

Why does every article about bounding volumes mention using "the squared sum to avoid using square root" when calculating the distance? For a sphere, what would be wrong with a simple
if (locA - locB <= radA + radB)
?

Share this post


Link to post
Share on other sites
Advertisement
Because LocA and LocB (and their difference) are 2D, or 3D vectors, with x, y, and z components. The radius of the spheres are 1D, so you need some meaningful way to convert those vectors from [2|3]D to 1D. One way is to use pythagorean's theorem, a^2+b^2=c^2. For a 2D vector, the x component would be the value a, the y component would be the value b. To solve for c, you would do sqrt(a^2+b^2). Note that c is the length of the 2D vector, so you can now compare c to the radius of the sphere to. The reason why the square radius can be done is because, given two variables a and b with the inequality a > b, then a^2 > b^2 is also true.

Share this post


Link to post
Share on other sites
Because then you're comparing a vector type with a scalar type, which doesn't make sense, instead you need to be comparing with the vector's magnitude (squared for efficiency) which is a scalar.

Share this post


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

  • Advertisement