   Any quick way to calculate min distance between 2 bounding boxes?
  Is there any quick way to calculate the minimumdistance between 2 bounding boxes?It is very easy to find an article describinghow to find the distance between a point and a bounding box on the net..But not for 2 bounding boxes... Any ideas?ThanksJack   
  Are they axis aligned? If so it's really similar to the point case.Just project the situation onto each axis. Then find the distance between their projections, sum the squares of those distances, and take the square root of that.   ;Quote:Original post by quasar3dAre they axis aligned? If so it's really similar to the point case.Just project the situation onto each axis. Then find the distance between their projections, sum the squares of those distances, and take the square root of that.For simplicity sake, you can assume they are axis aligned...Do you know of any online/downloadable articles from the net that I can take a look at (for your method)?ThanksJack   ;  Don't know of any, but here's the code of my function:float Box::GetDist(const Box &b) const{float sqrDist = 0;for(int i = 0;i < 3;i++){if(b.max < min){float d = b.max - min;sqrDist += d * d;}else if(b.min > max){float d = b.min - max;sqrDist += d * d;}}return sqrtf(sqrDist);};Quote:Original post by quasar3dDon't know of any, but here's the code of my function:float Box::GetDist(const Box &b) const{float sqrDist = 0;for(int i = 0;i < 3;i++){if(b.max < min){float d = b.max - min;sqrDist += d * d;}else if(b.min > max){float d = b.min - max;sqrDist += d * d;}}return sqrtf(sqrDist);}Maybe I am missing the obvious, but will this not calculate the minimal distance between the corner points of the two boxes?   ;  something will be added to sqrDist only when the projections onto the current axis do not overlap.This means that when the min distance is the distance between two edges, nothing will be added to sqrDist for the axis parallel to it, and so it will in effect be the distance between two corners of a 2D projection of the situation.similarly, if the min distance is between two faces, sqrDist is only added to for one of the axes.   ;Quote:Original post by quasar3dsomething will be added to sqrDist only when the projections onto the current axis do not overlap.This means that when the min distance is the distance between two edges, nothing will be added to sqrDist for the axis parallel to it, and so it will in effect be the distance between two corners of a 2D projection of the situation.similarly, if the min distance is between two faces, sqrDist is only added to for one of the axes.I see, indeed I missed the obvious. Been a while since I wrote such functionality :)   ;Quote:Original post by quasar3dDon't know of any, but here's the code of my function:float Box::GetDist(const Box &b) const{float sqrDist = 0;for(int i = 0;i < 3;i++){if(b.max < min){float d = b.max - min;sqrDist += d * d;}else if(b.min > max){float d = b.min - max;sqrDist += d * d;}}return sqrtf(sqrDist);}this can be also nicely vectorized using sse with just 3 instructions (if squared distance is ok, which is the case in a lot of situations):submaxdot