Minkowski Sum

Computes the Minkowski sum of the convex hulls of two point sets.

General form

let result =
  minkowskiSum(
    left,
    right,
  )

Parameters and types

Input points may be in any order and may contain duplicates, interior points, or redundant points on hull edges. The implementation normalizes both inputs to convex hulls before computing their Minkowski sum.

The input sequences are not modified.

Preconditions

T must be an exact ordered-ring-like type supporting:

int64 is the typical choice. Coordinate operations and cross products must fit in T.

Return value

If either input is empty, the result is empty.

Otherwise, the result is:

Degenerate point and segment results are supported.

Example

import atcoder/extra/geometry/geometryimport atcoder/extra/geometry/minkowski_sumlet left =  @[    initPoint(0'i64, 0'i64),    initPoint(1'i64, 0'i64),    initPoint(1'i64, 1'i64),    initPoint(0'i64, 1'i64),  ]let right =  @[    initPoint(-1'i64, -2'i64),    initPoint(2'i64, -2'i64),    initPoint(2'i64, 3'i64),    initPoint(-1'i64, 3'i64),  ]doAssert minkowskiSum(  left,  right,) == @[  initPoint(-1'i64, -2'i64),  initPoint(3'i64, -2'i64),  initPoint(3'i64, 4'i64),  initPoint(-1'i64, 4'i64),]

The implementation normalizes arbitrary point sets and merges the two convex hulls' edge vectors by polar angle.

Complexity and implementation

Let the input sizes be n and m.

Even when inputs are already convex polygons, the public API normalizes them to guarantee a consistent canonical result.