Collision detection between triangle and polygon

I have some difficulties to understand how to be sure if there is a collision between a space ship (black) and an asteroid (in blue). A space ship is placed on a case and an asteroid comes from the right, like on the image.

Also Y1 != Y2, there are not exactly on the same line. What is the best way, in that case, to detect if there is a collision ? Is AABB collision the correct algorith I need ?

• Hi Asm, are you using the shapes of the objects as the colliders? If you are then you can split your hexagon into 2 triangles and a square to simplify your collision algorithm, or are you just checking for a point to point collision? Dec 19, 2014 at 0:12
• Hi Matthew, thank you for your comment. I confirm that I'm using the shapes of the objects. If an asteroid touch the point (X2, Y2) of the triangle, the space ship will be erased. I have got severeal lines and columns and many objects on my grid.
– Asm
Dec 19, 2014 at 0:18
• possible duplicate of Triangle-triangle continuous collision detection Dec 19, 2014 at 0:30
• You probably want the separation algorithm, but are you aware that most games use simple hitboxes rather than complex polygon collision detection? Dec 19, 2014 at 2:32

I think either AABB collision test or circle-circle is sufficient for your needs. Usually it is not necessary to have perfect pixel level precision in determining whether 2 objects hit.

For circle-circle, have all your objects have a center x,y and a radius r; to determine whether 2 circles overlap: test (obj1.x-obj2.x)^2 + (obj1.y-obj2.y)^2 > (obj1.r + obj2.r)^2

For box, have all your objects have x,y, width and height, and check whether the box overlap in x axis and y axis.

Edit: In case that you really really want to use triangle - polygon level of precision, you need to first implement/find a intersection test for lineSegment vs lineSegment. Then for the intersection test between 2 polygons, test whether any combination of their edges intersects OR whether one object fully contains the other (point in shape test).

To complete @user55564 I give some more information about line segments intersection.

In general you can check if any Intersection exist between your two polygon (even non-convex) as what I've described Here.