Skip to content

Instantly share code, notes, and snippets.

@boboboa32
Created October 11, 2012 14:15
Show Gist options
  • Save boboboa32/3872618 to your computer and use it in GitHub Desktop.
Save boboboa32/3872618 to your computer and use it in GitHub Desktop.
bool sat(polygon a, polygon b){
for (int i = 0; i < a.edges.length; i++){
vector axis = a.edges[i].direction; // Get the direction vector of the edge
axis = vec_normal(axis); // We need to find the normal of the axis vector.
axis = vec_unit(axis); // We also need to "normalize" this vector, or make its length/magnitude equal to 1
// Find the projection of the two polygons onto the axis
segment proj_a = project(a, axis), proj_b = project(b, axis);
if(!seg_overlap(proj_a, proj_b)) return false; // If they do not overlap, then return false
}
... // Same thing for polygon b
// At this point, we know that there were always intersections, hence the two polygons must be colliding
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment