← Back to Portfolio ← Back to Projects

SAT Collision Detection

Real-time convex polygon resolution using the Separating Axis Theorem

Real-time visual of projected vertices along the axis to test for intersection. Cyan lines are projected vertices along the x and y axes, green/red line is when collision detection.

Overview

This project showcases a 2D implementation of the Separating Axis Theorem (SAT) for real-time collision detection between convex polygons. It includes visual debugging for projected axes, overlap intervals, contact normals, and penetration resolution.

Core Concepts

  • Projection of polygon edges onto normal axes
  • Detection of overlap using interval comparison
  • Calculation of minimum penetration depth and resolution vector
  • Support for arbitrary convex shapes and dynamic objects

YouTube Demo

Theory: SAT Axis Projection

Desmos rendering of the Separating Axis Theorem. Polygons are projected onto a candidate axis (gray), testing overlap of projection intervals (amin to amax vs. bmin to bmax). The Boolean logic and inequalities shown on the left evaluate whether a separation exists.

The unity scene view displays debug lines testing the vertices of both polygons.

SATCollision.cs (C#)

This class provides a full implementation of the Separating Axis Theorem (SAT) for 2D collision detection in Unity. It includes support for both polygon-polygon and circle-polygon collisions. The algorithm projects vertices onto candidate axes (perpendicular to edges) and checks for overlap. If no separating axis is found, it calculates the minimum intersection depth and normal vector to resolve the collision. The system includes debugging visualizations, vector projections, and MTV (Minimum Translation Vector) resolution logic to prevent tunneling and ensure consistent separation.

          Loading...