2D AABBs
In what follows are various notes and equations dealing with 2D AABBs.
AABB of Points
- \(A\) is the bottom left of the AABB
- \(B\) is the top right of the AABB
- \((x_1, y_1), (x_2, y_2), \ldots, (x_n, y_n)\) are the points
- \(A_x = \min(x_1, x_2, \ldots, x_n)\)
- \(A_y = \min(y_1, y_2, \ldots, y_n)\)
- \(B_x = \max(x_1, x_2, \ldots, x_n)\)
- \(B_y = \max(y_1, y_2, \ldots, y_n)\)
Point-AABB Hit Detection
- \((x, y)\) is the point
- \(A\) is the bottom left of the AABB
- \(B\) is the top right of the AABB
No collision iff
\(x \lt A_x\) or \(x \gt B_x\) or
\(y \lt A_y\) or \(y \gt B_y\)
AABB-AABB Hit Detection
- \(A\) is the bottom left of the first AABB
- \(B\) is the top right of the first AABB
- \(C\) is the bottom left of the second AABB
- \(D\) is the top right of the second AABB
No collision iff
\(B_x \lt C_x\) or \(A_x \gt D_x\) or
\(B_y \lt C_y\) or \(A_y \gt D_y\)