How do I detect if two polygons overlap each other or not?

900 Views Asked by At

I'm developing a game engine. Currently I'm writing the collision detection part. I have to write down an algorithm which detects if two given polygons are overlapping each other or they are separated objects. I gave an illustrative example below, but in practice I will try to model the objects with less vertexes as possible.

Modeling the hit-boxes in rectangular shape may look like a simple solution, but there will be very large and very small non-rectangular objects together in the game map. If I do that way, the collisions will not look realistic.

My example figure below contains too much vertexes, but in real, there will be 10 vertexes at most. I may try to model the polygons convex if it will make the algorithm easier.

The world is two dimensioned. Given the vertexes of the fist polygon as $(a_i,b_i), \;\; 1<i<n$. And the second one's as $(c_j,d_j), \;\; 1<j<m$.

How do I find if these two objects overlap or not?

enter image description here