I'm trying to learn the Separating Axis Theorem, for my programming. I'm making a simple 2D game an I need this as a way to detect wether two polygons are intersecting.

Problem is, I suck at math.

So far, I understand that in order to know if two polygon are intersecting, I need to do the following:

  1. Creata a perpendicular line to every edge of the two polygons.
  2. Project each polygon to each of the new lines created (the axes).

If all projections of the first polygon overlap all projections of the second polygon, the shapes intersect. Else, the shapes do not intersect.

I know how to do step 1. But I don't understand how to perform step two.

Can you explain to me how to project a polygon onto an axis, in a language that a person with pretty basic knowledge at math will be able to understand?

Thanks a lot


Projecting is a bit like casting a shadow. In this case, if you're looking at the $x$ and $y$ axes, the projections would be the shadow the object would create on the axes if you shined a flashlight behind the object.

Let's say one of your sides goes from $(2,2)$ to $(5,7)$. The projection onto the $x$ axis would be the line segment going from $x=2$ to $x=5$ on the $x$ axis. The projection onto the $y$ axis would be the line segment going from $y=2$ to $y=7$ on the $y$ axis.

Sometimes the projection is meant just to be the length of the shadow.

The more general approach involves taking the two endpoints, and dropping perpendiculars to the axis from those endpoints. The projection is defined by the place where those perpendiculars intersect the axis.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.