In this video I look at collisions between convex polygons, including rectangles. A quick examination of AABB (Axis Aligned Bounding Box) followed by SAT (Separated Axis Theorem) and an alternative I don’t know the name of. As well as checking for overlap, I experiment with resolving the collisions statically.

Source:

YouTube:

Discord:

Twitter:

Twitch:

GitHub:

Patreon:

Homepage:

Nguồn: https://milchreis.org/

Xem thêm bài viết khác: https://milchreis.org/game/

### Xem thêm Bài Viết:

- The Sociology of D&D, Running the Game #8
- Explore the World in Virtual Reality with National Geographic (Oculus Quest Gameplay)
- Chuck Pierce – New Era Revelation – Prophecy 2020
- Adley App Reviews | Flip Trickster | NEW GAME ultimate backflip tumbling challenge
- Taste Buddies: Who will win the ‘Beeropoly?’

Hi Javid, what do you think of running around the convex, and just collect the signs of the Dot-Products of edge-normals with difference vector to points of other polygon and if they are all the same sign, it is a collision: https://youtu.be/ntUl7xivTaM

I think you can do concave poly collisions by breaking the concave poly into 2 or more convex polygons.

Is it possible to use this theorem to find the area of intersection between two shapes?

With diagonal every section is made from triangle, then combine with point in triangle formula can also detect the overlaping shape

Very interesting! In a convex polygon, any couple of points is joined by an internal segment.

I LOVE ALL OF YOUR VIDEOS! Your mathematical explanations are top-tier, you are doing something great!

Is it improove perfomance if for each polygon create box that contains this polygon in any rotation in it, and first check is this boxses intersects, and if true only then check intersection with polygons?

hi, could you make a tutorial about newtonian mecanic on polygons ?

There's another easy way to check for the collision of two convex 2D polygons; replace one polygon with a point, and the other polygon with the morphological dilation of one polygon by the other. Then the intersection test can be reduced to a point-in-polygon test. The morphological dilation of two convex polygons can be easily created by taking all the edges of both polygons and then sorting them into clockwise order by angle, then reconnecting them in that order. I don't remember the name of this technique but it works very well.

Best explanation of SAT I've seen. I've been putting off looking into it properly for years but this video really demystified it.

About the only problem I can see with the static diagonal approach is if you tried to put the pentagon between the square and triangle and then use the triangle to push it into the square. If I understood things right, it would resolve the pentagon/triangle first, pushing the pentagon into the square and then resolve the pentagon/square pushing the pentagon out of (and back into) the triangle.

A possible solution from the top of my head would be use two loops of intersection checks. One forward and one backwards, thus swapping the pushing priority. So first T pushes P into S, then S pushes P back into T. Now the backwards check has P pushing T away.

I really like this video. It helped me a lot to get used to collisions and resolving collision, something that I had seriously trouble understanding and getting right.

Your videos are really informative and educatinal, keep it up 🙂

After playing with the code myself, and investigating on other websites and blogs, I have a suggestion.

That is in the SAT/Static algorithm to displace the shape not by the line between their middle points, but rather by the axis in which the overlap occured. Just store the corresponding axis alongside when overwriting the minimum overlap, I think it will make it a little more stable. Cheers!

would applying displacement along the vector to both shapes according to weight ratio work for this car game?

What would happen if you had two polygons that clearly overlapped, but none of the vertices of any polygon was inside the other polygon?

Did someone find the name of this clever diagonals theorem he's using ?

Love the diagonals algorithm 👍❤️ Simple and very effective. Just need to pay attention if one polygon is already contained inside another as starting position or if there are bigger "jumps" possible so that an edge can be crossed without touching it – which is of course not the case here.

"I'm no good at drawing straight things on the screen"

Me tooooooo!

Hmmmm. I think a technique similar to the "diagonals" is possible, where you just check if any of the sides intersect. This wouldnt be so good for resolving static collisions, but it would save some processing time, because you only have to check one polygon

Very good video!

Tried the code myself and the diagonals static collision works perfectly except when 2 rectangles collide when both there sides are parallel one of the rectangles is offseted to the side instead of just being pushed back

Any way I can fix this?

I've discovered a problem with the diagonal method. If you have a shape completely inside of another much larger shape, it's possible for them to not detect any collision.

If a shape can't get inside of another this isn't a problem, but it is important to note that method isn't perfect.

On another note I think I've come up with another. You could measure the angle of every vertex on one shape with the every the angle of every vertex on another shape.

If the angle from every vertex on shape A to one angle on shape B is between the angles to the two connected vertexes on shape A, then that vertex on shape B is inside of shape A.

Using actual angles involving trig functions seems too inefficient, but calculating the slope seems easy enough. I'll have to do some math or run some tests to see if it's worth doing at all.

This is amazing! Also, I lost it at 36:04

Unfortunately, Diag method is not really working for long rectangle forms.

This is amazing, thanks for this. I was looking for it. =)

Haha, a couple of months ago I thought like: I need nothing like this.

However, now I am VERY glad that I found the video again. Thanks!

I think your diagonals approach can return a false negative (incorrectly not detect a collision) if a smaller shape is entirely contained within one 'pie section' of a bigger one (between an edge and its two diagonals).