Minkowski sums and differences
There are many ways to do collision detection, but a fairly general one is Minkowski differences. The idea is that you do a binary operation on two shapes to get a new shape, and if the origin (the zero vector) is inside that shape, then they are colliding. The minkowski sum lets you define some interesting shapes that are both easy to draw and easy to do collision detection on.
The Minkowski sum
What does it mean to add shapes?
One representation of a shape is a (possibly infinite) set of points. so, a point is just a set with one element, and a circle is the set { v | || v - c || <=r}, or the set of all points within radius r of a centre point c.
The minkowski sum of A and B is the set of all points that are the sum of any point in A and B. The formula is:
Some examples
To instill you with intuition of what a minkowski sum looks like, here are a few examples:
The sum of any shape and a point is that shape translated by that point.
The sum of any shape and two points is two translated (possibly overlapping) copies of that shape.
The sum of two circles is a larger circle (sum the radii) with its centre at the sum of the centres of the smaller circles.
The sum of any shape and a line is that shape swept through that line. Think of placing your shape in sand, and dragging it along the line.
Similarly, the sum of a shape and any curve is what you’d get by sweeping the shape through the curve.
The sum of two parallel lines is a longer line.
For perpendicular lines, you get a square.
Minkowski difference
The minkowski difference is what you get by taking the minkowski sum of a shape and the mirror of another shape. So, your second shape gets flipped about the origin (all of its points are negated).
And if we ask “are these objects colliding?”, we’re really asking if they have any points in common. If they do have a point p in common, then p - p = 0 must be in the Minkowski difference. If they do not share a point, then a - b is never 0, because a 不等于 b. So, we have reduced the collision detection problem to a Minkowski sum problem.