1
\$\begingroup\$

So I was just doing an example 2D SAT collision detection problem on paper when I encountered something unexpected. I ran the algorithm on a triangle and a square, and the result of the algorithm was that there was a collision, when indeed there was not. Take a look at this:

grey lines are the axes, red marks are extremes of projection endpoints (from both shapes) on each axis enter image description here

I was under the impression that the SAT algorithm checked for overlapping vertices on all unique axes generated by both shapes sides' normals, and if no gap is found on any axis, then there is a collision. It looks like that does not work in this example. Can someone explain what I am missing? Maybe I'm understanding the algorithm wrongly.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ There's a gap when you project onto the normal to the triangle's hypotenuse (the diagonal green lines), is there not? \$\endgroup\$
    – DMGregory
    Commented Nov 1, 2017 at 23:07
  • \$\begingroup\$ @DMGregory Wait so we are supposed to project onto the normals? or the lines perpendicular to the normals? \$\endgroup\$
    – Ibrahim
    Commented Nov 1, 2017 at 23:10
  • \$\begingroup\$ Well, which one finds the separating axis in this case? That should tell you all you need. ;) \$\endgroup\$
    – DMGregory
    Commented Nov 1, 2017 at 23:12
  • \$\begingroup\$ Wow, no wonder all my other polygons were having the same issue, thanks man! \$\endgroup\$
    – Ibrahim
    Commented Nov 1, 2017 at 23:16
  • 1
    \$\begingroup\$ If you've solved your problem, try writing up your solution as an answer so it can benefit future users. :) \$\endgroup\$
    – DMGregory
    Commented Nov 1, 2017 at 23:17

1 Answer 1

1
\$\begingroup\$

Figured it out thanks to @DMGregory 's comment. The slanted axis in the picture shouldn't be there. The axes should be parallel to the normal of each side of both shapes, not perpendicular. This idea goes the same for any 2D convex polygon.

grey lines are the separating axes of this triangle and are also normal to the sides of the triangle, as indicated by the yellow arrows

enter image description here

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .