What happens if both checks on a polygon are true?

What happens if both checks on a polygon are true?

If both checks are true, we switch collision to its opposite value. This is different than our previous tests, where we set the collision to simply true or false. After we’ve gone through all the vertices, whatever the final state of collision is is the result. Here’s a full example with everything together:

How to test if a polygon has collided with a circle?

To test if a circle has collided with a polygon, we can simplify the problem to a series of Line/Circle collisions, one for each side of the polygon. Since we’ve already covered the steps to go through the vertices as lines, and Line/Circle collisions, let’s just look at the test for each side: Cool!

How does collision detection work in a polygon?

We have a function to check if a point is in a polygon and it can be used for every vertex in a polygon to allow us to check if a polygon is in a polygon. So if all 5 points of a pentagon are not inside a polygon then we know the polygons are not colliding and if at least one point is inside then we know the polygon is colliding.

How to check if a point is inside a convex polygon?

By checking if a line we draw from the point crosses the polygon border an odd amount of times we will be able to tell if a point is inside a convex or concave polygon. Note: We will only checking for convex polygons with our code however, I just wanted to show that this line method works for both types when checking points.

There are several methods, the simple is just to check if there is and overlap in X or Y bounds. This however only works with rectangles aligned with the axis. There is bounds checking, is the corner of one object withing the bounds of coordinates of the other. From there collision detection gets more advanced.

Can you tell if a polygon is colliding with another polygon?

Polygons don’t have a set radius or a set width and height so we can’t use the previous methods. Let’s take a look at some polygons that are colliding and see what we can tell about polygon collisions. From this image you can see that if a convex polygon is colliding then at least 1 of the corners (vertices) is inside the other polygon.

What happens to the Green Lines in a polygon?

The green lines in the picture are all lines of which all other vertices fall outside of, so a collision will occur if the shape is inside one of them. Both islanded polygons A and B will be further islanded into C, D, E and F after 2b.