For convex polygons the sum is convex, has at most vertices, and is computable in .
The construction
The edges of are exactly the edges of and , merged by angle. So:
- Rotate each polygon so its bottom-most (then left-most) vertex is first.
- Merge the two edge sequences by angle, as in a merge sort.
- Accumulate the edge vectors from the sum of the two starting vertices.
vector<P> minkowski(vector<P> a, vector<P> b) { // both CCW, both starting at the lowest point
a.push_back(a[0]); a.push_back(a[1]);
b.push_back(b[0]); b.push_back(b[1]);
vector<P> res;
size_t i = 0, j = 0;
while (i + 2 < a.size() || j + 2 < b.size()) {
res.push_back(a[i] + b[j]);
long long c = cross(a[i+1] - a[i], b[j+1] - b[j]);
if (c >= 0 && i + 2 < a.size()) i++;
if (c <= 0 && j + 2 < b.size()) j++;
}
return res;
}— one pass, exact in integers.
Why the edges just merge
A convex polygon is determined by its multiset of edge vectors sorted by angle. Supporting the sum in a direction means supporting and separately in , so the sum’s edge in each angular direction is the sum of the two polygons’ edges in that direction. Merging by angle is therefore the whole algorithm.
Uses
| Problem | Formulation |
|---|---|
| Collision detection | and intersect iff |
| Distance between convex polygons | distance from the origin to |
| Motion planning with a robot of shape | grow every obstacle by , then treat the robot as a point |
| Maximum of over convex sets | support function of the sum |
| Sum of two convex sequences (max-plus convolution) | the sequences are the edge slopes |
| Reachable set after two moves | of the two move sets |
| Widest empty corridor | via Minkowski differences |
The collision test
Since (the Minkowski difference) is convex and computable in , the test is a point-in-convex-polygon query — after construction. This is the theoretical basis of the GJK algorithm used in every physics engine.
Max-plus convolution of concave sequences
If and are concave, then
is computable in by merging their difference sequences — because the problem is a Minkowski sum of the two convex hulls of their graphs. Without concavity, max-plus convolution has no known subquadratic algorithm.
This turns certain “combine two convex DP tables” problems from into , and it is a genuinely useful trick in optimisation-flavoured DPs.
Properties
| Property | |
|---|---|
| Commutative and associative | |
| Convexity is preserved | sum of convex sets is convex |
| Vertex count | |
| Perimeter | |
| Area (Steiner formula) | |
| translation of by | |
| “inflated” by — rounded corners |
Inflating a polygon by a disk gives the offset polygon with rounded corners: straight edges pushed out by , joined by arcs of radius . Perimeter grows by exactly , area by .
Non-convex inputs
For non-convex polygons the Minkowski sum can have complexity and requires arrangement machinery to compute. In practice: decompose into convex pieces, sum pairwise, and take the union — expensive, and rarely needed in contests.
See also: Convex Hull · Rotating Calipers · Convex Hull Trick