For convex polygons the sum is convex, has at most vertices, and is computed in by merging the two edge sequences by angle.
| Property | Value |
|---|---|
| commutative, associative | |
| convexity | preserved |
| vertex count (convex) | |
| perimeter | |
| area | (mixed area, Steiner formula) |
| translation by | |
| offset polygon with rounded corners: perimeter , area | |
| non-convex inputs | complexity up to ; decompose into convex pieces, sum pairwise, take the union (rarely needed) |
The construction
- Rotate each polygon (CCW) so that its bottom-most, then left-most, vertex is first.
- Merge the two edge sequences by polar angle, as in merge sort (equal angles advance both).
- Accumulate the edge vectors starting from the sum of the two first 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;
}Proof: the edges of the sum are the merged edges
For a direction , the support function satisfies , and the face of maximizing is the sum of the faces of and maximizing it. As turns around the circle, the maximizing face of a convex polygon is a vertex except at the outer normals of its edges, where it is that edge. So the sum’s edges appear exactly at the edge normals of and , in angular order, and an edge of the sum is the sum of the edges of and with that normal (one of which may be a single vertex). Starting both polygons at their lowest-leftmost vertex aligns the angular starting point, and merging by the cross product of consecutive edges is a merge by angle. Tested against the convex hull of all pairwise vertex sums on random integer polygons.
Uses
| Problem | Formulation |
|---|---|
| collision detection | (basis of GJK in physics engines) |
| distance between convex polygons | distance from the origin to |
| motion planning for a translating robot | grow each obstacle by , move a point |
| maximum of over convex sets for linear | support function of the sum |
| reachable set after two moves | sum of the two move sets |
| max-plus convolution of concave sequences | merge of the slope sequences (below) |
| widest empty corridor | via Minkowski differences |
The collision test is a point-in-convex-polygon query on the Minkowski difference: to build, per query (Convex Polygon Queries).
Proof: the collision criterion
iff there are , with , i.e. a common point. The distance version follows the same way: .
Max-plus convolution of concave sequences
For concave and (non-increasing differences), is obtained by merging the difference sequences in decreasing order, instead of . This speeds up “combine two convex DP tables” steps (for example in tree knapsack with concave values). Without concavity no subquadratic algorithm is known.
vector<long long> maxPlusConcave(const vector<long long>& f, const vector<long long>& g) { // f, g concave
int n = sz(f), m = sz(g); vector<long long> h{f[0] + g[0]};
int i = 0, j = 0;
while (i + 1 < n || j + 1 < m) { // take the larger next increment (merge of slopes)
if (j + 1 == m || (i + 1 < n && f[i + 1] - f[i] >= g[j + 1] - g[j])) i++; else j++;
h.push_back(f[i] + g[j]);
}
return h;
}Proof: merging slopes is optimal
is the maximum sum of increments chosen as a prefix of ‘s differences plus a prefix of ‘s differences. Since both difference sequences are non-increasing, the largest increments of the merged multiset form a prefix of each sequence, and the greedy merge always takes the larger next increment, so after steps it holds exactly the largest. This is the one-dimensional case of the Minkowski sum of the hypographs of and . Tested against the definition.
Related: Convex Hull, Rotating Calipers.