# Axis Aligned Bounding Boxes logic error?

## Recommended Posts

ryjax    125
Hello All, I have a quick question regarding Collision Detection. In the book that I'm currently reading, it describes Axis Aligned Bounding Boxes (AABB) and gives the logic: float Dx = Math.Abs(r2.x - r1.x); float Dy = Math.Abs(r2.y - r1.y); if (Dx > (r1.extentX + r2.extentX) && (Dy > (r1.extentY + r2.extentY)) // the boxes do not overlap else // the boxes overlap My question is what is extentX and extentY? Is it the Height and Width? Using x and y as the top left value of a rectangle and ExtentX, ExtentY as the height and width, I can't seem to get it to work as expected.

#### Share this post

##### Share on other sites
jyk    2094
'x' and 'y' represent the center of the box, the x extent is half the width, and the y extent is half the height.

Also, I think it should probably be 'or', not 'and':
if (Dx > (r1.extentX + r2.extentX) || (Dy > (r1.extentY + r2.extentY)) {}

## 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