Skip to content
AABB Collision
step 1/5

Reading — step 1 of 5

Read

~1 min readCollision Detection

AABB Collision

AABB (Axis-Aligned Bounding Box): rectangle aligned with x,y axes.

python

Two AABBs intersect iff they overlap on BOTH axes:

python

For axis overlap: a's max ≥ b's min AND a's min ≤ b's max.

Compute penetration depth:

python

Resolve along the smaller axis:

python

This is a simple positional fix. Real engines use impulses (momentum) for more realistic bouncing.

Other shapes:

  • Circle: distance between centers < sum of radii.
  • Capsule: rectangle + 2 semicircles. Common for character collision.
  • OBB (Oriented Bounding Box): rotated. Use SAT (Separating Axis Theorem).
  • Convex polygon: SAT or GJK algorithm.

Circle vs circle:

python

Circle vs AABB:

python

Find closest point on AABB to circle, compare distance to radius.

These tests are O(1) per pair. Need to optimize O(N²) for many bodies.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…