Furthermore we can show that if the two objects have unequal mass, then they must depart at a non-right angle. We can prove this fact by applying the conservation of momentum (physical law), the conservation of energy (true iff the collision is perfectly elastic), and the law of cosines (pure math). After they collide and assuming the collision is perfectly elastic, the two objects will always depart at a right angle to each other.
Object one is stationary, whereas object two is moving toward object one. Here is a remarkable fact: Suppose we have two objects with the same mass.
If you do not have a PDF viewer, you can download Adobe Reader free. This approach is much simpler than using trigonometry.
You might wonder why we don’t check the BC line - this is because we can implicitly rule out the origin being along its perpendicular.In high school physics we learned about momentum, kinetic energy, and elastic collisions. This document shows how to solve two-dimensional elastic collision problems using vectors instead of trigonometry. The implementation of the support function is quite simple:Ĭlass Polygon implements IShape Since the Minkowski Difference is shape a farthest point - shape b farthest point having the point of shape b being sampled from the opposite direction results in a support point that is as far as possible in the direction provided. The reason we take points from opposite directions is so that we get a point on the Minkowski Difference that will result in the largest area, so there’s a better chance we can encapsulate the origin. Using these two farthest points a support point can be calculated on the Minkowski Difference shape. The support function then takes a point from each shape, the farthest in two opposite directions. For a review of vector algebra, necessary to understand the topic, you can also see the arti c le of this site. The support function takes the two shapes being compared, and the direction you want to check in. This article describes the primitive geometric forms used in 2D collisions, with references to the features provided by the Unity’s 2D Physics engine. Of particular interest for collision detection should be the section on projecting.This is a good 2D collision detection tutorial. The support function is a way to sample a point on the edge of the Minkowski Difference - without building the entire shape. Quote: This is a pretty good vector and matrix math tutorial. In order to avoid this GJK uses two key concepts support functions and simplexes. Calculating Minkowski Differences could take a long time, especially if you are checking if two shapes with many points are intersecting. Taking these concepts the GJK algorithm optimises them. Minkowski Difference of Shape A and B: Note AD in the table and chart refers to A - D Taking the values of shape A and shape B we can calculate the Minkowski Difference:
The Minkowski Difference has the interesting property that if the two shapes are intersecting/overlapping the resulting Minkowski Difference will contain the origin. This is referred to in resources I’ve seen as the ‘Minkowski Difference’. Since this is a 2D problem, the momentum equation is a vector equation. GJK utilises a form of the Minkowski Sum that instead of A + B, it’s A - B. After the collision the white ball travels at a final velocity of 2m/s at 110. Minkowski Sum of Shape A and B: Note AD in the table and chart refers to A + DĪ nice way to think about the Minkowski Sum is imagine you take Shape A and trace the outline of Shape B with it, the shape it would result in would be the Minkowski Sum. If we take these values we can plot them on a graph and see the shape it results in.
Taking the values of shape A and shape B we can calculate the Minkowski sum: The Minkowski Sum is calculated by adding all the points of two shapes. GJK uses a concept called the Minkowski Sum. It is fast, and is implemented using a generic ‘support function’ which allows for a more general approach - you can treat polygons and curved shapes such as ellipses in the same way. GJK is an algorithm designed to determine if two convex shapes are intersecting. This post is written based on this article and the video it recommends:
The code samples make use of some structures I have created and won’t detail in this post, but they are simple and you can see them in the GitHub repo:Īll the code this post uses is in a GitHub repo here: I’ve been trying to learn how collision detection works this lead me to the Gilbert-Johnson-Keerthi (GJK) algorithm.Īll code samples in this post are in TypeScript.