Abstract 1 Introduction 2 Preliminaries 3 Blocking Scheme 4 The Linear Time Algorithm 5 Constructing the Point Oracle 6 Constructing the Cascading Subroutine References

A Linear Time Algorithm for the Maximum Overlap of Two Convex Polygons Under Translation

Timothy M. Chan ORCID Siebel School of Computing and Data Science, University of Illinois at Urbana-Champaign, IL, USA Isaac M. Hair ORCID Department of Computer Science, University of California, Santa Barbara, CA, USA
Abstract

Given two convex polygons P and Q with n and m edges, the maximum overlap problem is to find a translation of P that maximizes the area of its intersection with Q. We give the first randomized algorithm for this problem with linear running time. Our result improves the previous two-and-a-half-decades-old algorithm by de Berg, Cheong, Devillers, van Kreveld, and Teillaud (1998), which ran in O((n+m)log(n+m)) time, as well as multiple recent algorithms given for special cases of the problem.

Keywords and phrases:
Convex polygons, shape matching, prune-and-search, parametric search
Funding:
Timothy M. Chan: Work supported by NSF Grant CCF-2224271.
Copyright and License:
[Uncaptioned image] © Timothy M. Chan and Isaac M. Hair; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry
Editors:
Oswin Aichholzer and Haitao Wang

1 Introduction

Problems related to convex polygons are widely studied in computational geometry, as they are fundamental and give insights to more complex problems. We consider one of the most basic problems in this class:

Problem 1.

Given two convex polygons P and Q in the plane, with n and m edges respectively, find a vector t2 that maximizes the area of (P+t)Q, where P+t denotes P translated by t.

This problem for convex polygons was first explicitly posed as an open question by Mount, Silverman, and Wu [34]. In 1998, de Berg, Cheong, Devillers, van Kreveld, and Teillaud [21] presented the first efficient algorithm which solves the problem in O((n+m)log(n+m)) time. As many problems have nlogn complexity, this would appear to be the end of the story for the above problem – or is it?

Motivation and Background.

The computational geometry literature is replete with various types of problems about polygons [36], e.g., polygon containment [14] (which has seen exciting development even in the convex polygon case, with translations and rotations, as recently as last year’s SoCG [13]). The maximum overlap problem may be viewed as an outgrowth of polygon containment problems.

The maximum overlap problem may also be viewed as a formulation of shape matching [7], which has numerous applications and has long been a popular topic in computational geometry. Many notions of distance between shapes have been used in the past (e.g., Hausdorff distance, Fréchet distance, etc.), and the overlap area is another very natural measure (the larger it is, the closer the two shapes are) and has been considered in numerous papers for different classes of objects (e.g., two convex polytopes in higher dimensions [3, 5, 4], two arbitrary polygons in the plane [18, 25], two unions of balls [10], one convex polygon vs. a discrete point set111In the discrete case, we are maximizing the number of points inside the translated polygon. [9, 1], etc.) as well as different types of motions allowed (translations, rotations, and scaling – with translations-only being the most often studied). Problem 1 is perhaps the simplest and most basic version, but is already quite fascinating from the theoretical or technical perspective, as we will see.

A Superlinear Barrier?

Due to the concavity of (the square root of) the objective function [21], it is not difficult to obtain an O((n+m)polylog(n+m))-time algorithm for the problem by applying the well-known parametric search technique [30, 2] (or more precisely, a multidimensional version of parametric search [38]). De Berg, Cheong, Deviller, van Kreveld, and Teillaud [21] took more care in eliminating extra logarithmic factors to obtain their O((n+m)log(n+m))-time algorithm, by avoiding parametric search and instead using more elementary binary search and matrix search techniques [24]. But any form of binary search would seem to generate at least one logarithmic factor, and so it is tempting to believe that their time bound might be the best possible.

On the other hand, in the geometric optimization literature, there is another well-known technique that can give rise to linear-time algorithms for various problems: namely, prune-and-search (pioneered by Megiddo and Dyer [31, 22, 32]). For prune-and-search to be applicable, one needs a way to prune a fraction of the input elements at each iteration, but our problem is sufficiently complex that it is unclear how one could throw away any vertex from the input polygons and preserve the answer.

Perhaps because of these reasons, no improved algorithms have been reported since de Berg et al.’s 1998 work. This is not because of lack of interest in finding faster algorithms. For example, a (lesser known) paper by Kim, Choi, and Ahn [28] considered an unbalanced case of Problem 1 and gave an algorithm with O(n+m2log3n) running time, which is linear when mn/log3n. Ahn et al. [6] investigated approximation algorithms for the problem and obtain logarithmic running time for approximation factor arbitrarily close to 1, while Har-Peled and Roy [25] more generally gave a linear-time algorithm to approximate the entire objective function, which was then used to obtain a linear-time approximation algorithm for an extension of the problem to polygons that are decomposable into O(1) convex pieces.

Our Result.

We obtain a randomized (exact) algorithm for Problem 1, running in linear (i.e., O(n+m)) expected time! This is the first improvement to de Berg et al.’s result [21] in 26 years, and is clearly optimal, and so fully settles the complexity of Problem 1.

A New Kind of Prune-and-Search?

Besides our result itself, the way we obtain linear time is also interesting. As mentioned, if one does not care about extra log(n+m) factors, one can use (multidimensional) parametric search to solve the problem. Specifically, parametric search allows us to reduce the optimization problem to the implementation of a line oracle (determining which side of a given line the optimal point t lies in), which in turn can be reduced to a point oracle (evaluating the area of (P+t)Q for a given point t). A point oracle can be implemented in linear time by computing the intersection (P+t)Q explicitly. (In de Berg et al.’s work [21], they directly implemented the line oracle in linear time.)

Various linear-time prune-and-search algorithms (e.g., for low-dimensional linear programming [31, 22, 32], ham-sandwich cuts [33], centerpoints [26], Euclidean 1-center [23], rectilinear 1-median [39, 35], etc.) also exploit line or point oracles; using (in modern parlance) cuttings [16], such oracle calls let them refine the search space and eliminate a fraction of the input at each iteration. Unfortunately, for our problem, we can’t technically eliminate any part of the input polygons P and Q. Instead, our new idea is to reduce the cost of the oracles iteratively as the search space is refined, which effectively is as good as reducing the input complexity itself. As the algorithm progresses, oracles get cheaper and cheaper, and we will bound the total running time by a geometric series.

To execute this strategy, one should think of oracles as data structures with sublinear query time (i.e., sublinear in the original input size n+m). Our key idea to designing such data structures is to divide the input polygons into blocks of a certain size based on angles/slopes. This idea is inspired by the recent work of Chan and Hair [13] (they studied the convex polygon containment problem with both translations and rotations, and although our problem without rotations might seem different, their divide-and-conquer algorithms also crucially relied on division of the input convex polygons by angles/slopes). We show that at each iteration, as we refine the search space, we can use the current “block data structure” to obtain a better “block data structure” with a larger block size. (The refinement process from one block structure to another block structure shares some general similarities with the idea of fractional cascading [17].)

We are not aware of any prior algorithms in the computational geometry literature that work in the same way (which makes our techniques interesting). A linear-time algorithm by Chan [12] for a matrix searching problem (reporting all elements in a Monge matrix less than given value) has a recurrence similar to the one we obtain here, but this appears to be a coincidence. An algorithm for computing so-called “ε-approximations” in range spaces by Matoušek [29] also achieved linear time (for constant ε) by iteratively increasing block sizes, but the algorithm still operates in the realm of traditional prune-and-search (reducing actual input size). Chazelle’s infamous linear-time algorithm for triangulating simple polygons [15] also iteratively refines a “granularity” parameter analogous to our block size, and as one of many steps, also requires the implementation of oracles (for ray shooting, in his case) whose cost similarly varies as a function of the granularity (at least from a superficial reading of his paper) – fortunately, our algorithm here will not be as complicated!

Remarks.

Recently, Jung, Kang, and Ahn [27] have announced a linear-time algorithm for a related problem: given two convex polygons P and Q in the plane, find a vector t2 that minimizes the area of the convex hull (P+t)Q. Although the problem may look similar to our problem on the surface, it is in many ways different: in the minimum convex hull problem, the optimal point t is known to lie on one of O(n+m) candidate lines (formed by an edge of one polygon and a corresponding extreme vertex of the other polygon), whereas in the maximum overlap problem (Problem 1), t lies on one of O((n+m)2) candidate lines (defined by pairs of edges of the two polygons). Thus a more traditional prune-and-search approach can be used to solve the minimum convex hull problem, but not the maximum overlap problem. Indeed, Jung et al.’s paper [27] considered the maximum overlap problem, but they do not give an improvement over de Berg et al.’s O((n+m)log(n+m)) time algorithm for the two-dimensional case. Instead, they give some new results for the problem in higher dimensions d, but their time bound is O(n2d/2), which is much larger than linear.

We observe that, in the specific case of maximum overlap for convex polytopes in dimension d=3, one can obtain a significantly faster O((n+m)polylog(n+m))-time algorithm by directly using multi-dimensional parametric search [38], since a point oracle (computing the area of the intersection of two convex polytopes in 3) can be done in O(n+m) time by explicitly computing the intersection [15, 11], and this is parallelizable with O((n+m)polylog(n+m)) work and O(polylog(n+m)) steps by known parallel algorithms for intersection of halfspaces in 3, i.e., convex hull in 3 in the dual (e.g., see [8]). This observation seems to have not appeared in literature before (including [40, 27]).

2 Preliminaries

We may assume that P and Q have no (adjacent) parallel edges, as these can be merged. Without loss of generality, P and Q both contain the origin as an interior point. Throughout, we assume that the edges of P and Q are given in counterclockwise order. We define N:=n+m, and we use [x] to denote the set {1,,x}. If x is not an interger, then we use [x] to denote the set {1,,x}, i.e., x is implicitly rounded up to the nearest integer. “With high probability” means “with probability at least 1nΩ(1).” The interior of a triangle refers to all points strictly inside of its bounding edges, and the interior of a line segment refers to all points strictly between its bounding points.

The Objective Function.

We want to find a translation maximizing

Area((P+t)Q).

De Berg, Cheong, Devillers, van Kreveld, and Teillaud showed several interesting properties of the area as a function of t [21]. For our purposes, we only need to import the following.

Lemma 1.

Area((P+t)Q) is downward concave over all values of t that yield nonzero overlap of P+t with Q.

The restriction on t is important, as A(t) suddenly transitions from a convex function to a constant function A(t)=0 when t is outside of the specified region. For our algorithm, however, this technicality will have little impact.

Cuttings.

First, we give a definition of the type of cuttings we use.

Definition 2 (ε-Cuttings).

A cutting for a set X of n hyperplanes in d, for any d1, is a partition of d into simplices such that the interior of every simplex intersects at most εn hyperplanes of X.

Endowed with the ability to sample random hyperplanes, we can actually produce such a cutting with very high probability in sublinear time, as per Clarkson and Shor [19, 20] (roughly, we can take logarithmically many random hyperplanes, and return a canonical triangulation of their arrangement).

Lemma 3.

Let X be a set of n hyperplanes in d, for any d1. Assume we can sample a uniformly random member of X in expected time O(n0.1). Let ε be any constant. Then in O(n0.1+o(1)) expected time, we can find a set of O(1) simplices that constitutes an ε-cutting of X with high probability.

Area Prefix Sums.

Let v1,,vn be the vertices of P listed in counterclockwise order, and let v1,,vm be the vertices of Q listed in counterclockwise order. Let P[vx:vy] denote the convex hull of the set of points containing: (i) the origin, (ii) the vertices vx and vy, and (iii) all vertices encountered when traversing the boundary of P in counterclockwise order from vx to vy. We define Q[vx:vy] analogously.

By a standard application of prefix sums, we can produce a data structure to report Area(P[vx:vy]) and Area(Q[vx:vy]) with O(N) preprocessing time and O(1) query time. This is since (taking Area(P[vx:vy]) as an example):

Area(P[vx:vy])= Area(P[v1:vy])Area(P[v1:vx]) when y>x, and
Area(P[vx:vy])= Area(P)(Area(P[v1:vx])Area(P[v1:vy])) when y<x.

Throughout, we refer to the above data structure as the area prefix sums for P and Q.

The Configuration Space.

Consider two convex polygons A and B, or more generally, two polygonal chains A and B. Let e be an edge of A and let e be an edge of B. These two edges define a parallelogram π(e,e) in configuration space such that, for any vector t2, we have that e+t intersects e iff tπ(e,e). Let π(e,e) denote the set of four line segments defining π(e,e). We define the set of all such line segments as

Π(A,B):=edge e of A, edge e of Bπ(e,e). (1)

We define Π(A,B) to be Π(A,B) where each line segment is extended to a line.

Angles and Angle Ranges.

The angle of an edge e on the boundary of an arbitrary convex polygon A, denoted θA(e), is the angle (measured counterclockwise) starting from a horizontal rightward ray and ending with a ray coincident with e that has A on its left side. We always have that θA(e)[0,2π). For any subset X of the edges of A, let ΛA(X) denote the minimal interval in [0,2π) such that θA(e)ΛA(X) for all eX. We call ΛA(X) the angle range for the subset X with respect to A.

3 Blocking Scheme

Given a parameter b, referred to as the block size, we define a partition222Actually, it isn’t quite a partition because the boundaries may overlap, but these have zero area. of P and Q into blocks P1,,PN/b and Q1,,QN/b as follows. First (implicitly) sort the set333We assume that no angles are shared between the edges of P and Q, as this case can be handled easily but requires a clumsier definition.

{θP(e):e is an edge of P}{θQ(e):e is an edge of Q}

in increasing order and then partition the resulting sequence into consecutive subsequences S1,SN/b of length b each (except possibly the last one). We then define Pi as the convex hull of the origin and the set of edges444The set of edges may be empty, in which case the block is just a single point (the origin). {e:e is an edge of P, and θP(e)Si}. We define Qj similarly. See Figure 1 for an example.

Now, b uniquely defines the partition, so we refer to P1,,PN/b and Q1,,QN/b as the blocks determined by parameter b. This scheme is useful because the angle ranges ΛP(EP(Pi)) and ΛQ(EQ(Qj)) are strictly disjoint whenever ij, where EP(Pi) is the set of edges that Pi shares with P, and EQ(Qj) is the set of edges that Qj shares with Q. We call EP(Pi) the restriction of Pi’s edges to P, and similarly for EQ(Qj).

Refer to caption
Figure 1: A partition of example polygons P and Q into blocks, with b=4. Note that the spatial sizes of blocks may vary greatly, and the number of edges in each Pi and Qj may differ. In fact, for some indices i, one of Pi or Qj may contain just the origin.

3.1 A Data Structure Using Blocks

Towards producing a prune-and-search style algorithm, we want some way to reduce the time required to compute the vector t which maximizes Area((P+t)Q). Instead of reducing the complexity of P or Q directly, we maintain and refine a specific data structure that contains information about P and Q and allows us to rapidly search for optimal placements.

Definition 4 ((μ,b,𝒯)-Block Structure).

A (μ,b,𝒯)-block structure is a data structure containing the following:

  1. 1.

    Access to the vertices of P and Q in counterclockwise order with O(1) query time, and access to the area prefix sums for P and Q with O(1) query time.

  2. 2.

    A block size parameter b, which implies blocks P1,,PN/b and Q1,,QN/b.

  3. 3.

    A region 𝒯2 that is either (i) a triangle, (ii) a line segment, or (iii) a point.

  4. 4.

    A partition of S:=[N/b] into subsets SGood and SBad, with the requirement |SBad|μ.

  5. 5.

    For every iSGood, access in time O(1) to a constant-complexity quadratic function fi such that fi(t)=Area((Pi+t)Qi) for all t𝒯.

Throughout, we assume that SGood and SBad are sorted, since we can apply radix sort in time O(|SGood|+|SBad|). When using the block structure, we aim to decrease the size of 𝒯 while increasing the block size b. If this is done carefully enough, we get a surprising result: a sublinear time oracle to report Area((P+t)Q) for any translation t𝒯.

4 The Linear Time Algorithm

We will reduce Problem 1 to a few different subroutines/oracles. Roughly speaking, these allow us to produce a highly refined block structure in linear time, which can be used along with multidimensional parametric search [38] to find the translation of P maximizing its area of intersection with Q in time O(N/logN).

Problem 2 (MaxRegion).

Given a (μ,b,𝒯)-block structure for P and Q, find

maxt𝒯Area((P+t)Q)

along with the translation t2 realizing this maximum.555During some calls to MaxRegion, 𝒯 may not contain the global optimum.

Problem 3 (Cascade).

Given a (μ,b,𝒯)-block structure, parameters μ and b such that b divides b, and a triangle or line segment 𝒯𝒯, either produce a (μ,b,𝒯)-block structure, or report failure. Failure may be reported only if the interior of 𝒯 intersects more than μ/2 lines from the set

𝒮:=k{0,,N/b1}((i,j)[bb]×[bb]Π(Pkbb+i,Qkbb+j)), (2)

where P1,,PN/b and Q1,,QN/b are the blocks of P and Q determined by b.

The set 𝒮 may appear mysterious, but it simply corresponds to the line extensions for the edges that could “cause trouble” for the cascading procedure. The only observation necessary right now is that |𝒮|=O(Nb), i.e., 𝒮 is near-linear in size for all b=No(1).

We write the expected time complexity of the fastest algorithm for MaxRegion as Td-Max(N,b,μ), where d is the dimension of the region 𝒯. We write the expected time complexity of the fastest algorithm for Cascade as TCascade(N,b,b,μ). The latter will not depend on μ or the dimensions of 𝒯 and 𝒯.

The next lemmas will be proved in Sections 5 and 6. The main idea behind proving each is to group most of the blocks of P and Q into larger convex polygons that intersect in at most a constant number of locations, and then to process the rest via brute force.

Lemma 5 (Point Oracle).

For all 2bN, for all μ,

T0-Max(N,b,μ)=O(Nlog2bb+μb).
Lemma 6 (Cascading Subroutine).

For all 2b,bN such that b divides b, for all μ,

TCascade(N,b,b,μ)=O(Nlogblogbb+μb2).

4.1 Reducing to the Point Oracle and Cascading Subroutine

We now give an algorithm for MaxRegion when the input (μ,b,𝒯)-block structure has 𝒯 being a triangle or line segment. The algorithm works by invoking MaxRegion on regions with lower dimension to iteratively shrink 𝒯.

Lemma 7.

For all 2b,bNo(1) such that b divides b, for all μ,μ such that μ=N1o(1),

T2-Max(N,b,μ)= O(log(Nb/μ))T1-Max(N,b,μ)+O(N0.1+o(1))+
O(1)TCascade(N,b,b,μ)+T2-Max(N,b,μ)
T1-Max(N,b,μ)= O(log(Nb/μ))T0-Max(N,b,μ)+O(N0.1+o(1))+
O(1)TCascade(N,b,b,μ)+T1-Max(N,b,μ).

Proof.

The algorithm for when 𝒯 is a line segment is nearly identical to the algorithm for when 𝒯 is a triangle, so for brevity we only focus on the triangle case. Let P1,,PN/b and Q1,,QN/b be the blocks of P and Q determined by block size parameter b.

Define 𝒯0:=𝒯. We will produce a series of triangles 𝒯0𝒯1𝒯2 such that each triangle is guaranteed to contain the optimal translation t for the original region 𝒯, and then take the final triangle in this sequence as 𝒯. Once we have 𝒯, we invoke Cascade to produce a (μ,b,𝒯)-block structure, and then find the optimal translation within 𝒯 (along with the area for this translation) by invoking MaxRegion on this new block structure.

In the subsequent analysis, we show that, with high probability, the interior of 𝒯 produced as per our sequence will intersect at most μ/2 lines of the set 𝒮. If this event occurs, then Cascade will be forced to produce a (μ,b,𝒯)-block structure. If this event does not occur, and Cascade returns failure, we can re-run the randomized algorithm to produce a new 𝒯 and try again. The expected number of attempts is O(1), and so all of the steps (except for producing 𝒯) have a time overhead of O(1)TCascade(N,b,b,μ)+T2-Max(N,b,μ).

Refer to caption
Figure 2: A series of triangles 𝒯0, 𝒯1, and 𝒯2 as produced by the algorithm. The (unknown) optimal placement t is denoted by an asterisk. The red curves indicate contour lines of the objective function, with darker circles indicating larger values of Area((P+t)Q).

Producing 𝓣.

As per the above, the expected number of times we need to make 𝒯 is O(1), so we only focus on the time complexity to make 𝒯 once. Consider producing a triangle 𝒯x+1 from a triangle 𝒯x in the sequence. As a first step, we use Lemma 3 to make, with high probability, a 12-cutting for the lines of 𝒮 that intersect the interior of 𝒯x.

To apply this lemma, we need an efficient sampler. We argue that naive rejection sampling will suffice. Observe that if rejection sampling fails to find a random line of 𝒮 that intersects the interior of 𝒯x within time O(N0.1), then with high probability only N1Ω(1) lines of 𝒮 intersect 𝒯x. By assumption μ/2=N1o(1), so we can directly take 𝒯=𝒯x. If rejection sampling is fast enough, then we can produce the required 12-cutting with high probability in time O(|𝒮|0.1+o(1))=O(N0.1+o(1)). Then, we intersect this cutting with 𝒯x and re-triangulate the resulting cells, which takes O(1) time in total.

The final step is to locate the cell of this triangulation that contains t. This cell will be 𝒯x+1. To do this, we check all O(1) triangles by recursing in the dimension. We assume that t is strictly contained within some cell, as the case that it is on the boundary can be detected similarly. Consider a single triangle 𝒳. Let 𝒳 be an infinitesimally smaller copy of 𝒳 that is strictly inscribed within 𝒳.666Infinitesimal shifts are a standard trick, and all of the algorithms in this paper can handle them without modification as long as they are implemented carefully enough. All O(1) bounding line segments for 𝒳 and 𝒳 are contained within 𝒯. Therefore, we can use the input (μ,b,𝒯)-block structure as a block structure for these line segments, and find the optimal translation (along with the area of intersection) restricted to each line segment in time O(1)T1-Max(N,b,μ). If one of the line segments for 𝒳 has a translation realizing a larger area than all of the line segments for 𝒳, then by Lemma 1 we know that t𝒳. Otherwise, 𝒳 does not contain t.777All invocations might return a maximum area of zero, but we can handle this in O(1) time by checking whether an arbitrary translation that causes P and Q to overlap is located within 𝒳.

With high probability, the interior of 𝒯x+1 will intersect at most half as many lines of 𝒮 as 𝒯x. By construction and the fact that b divides b (and hence bb), we have |𝒮|=O(Nb). Thus there are at most O(log|𝒮|μ)=O(log(Nb/μ)) iterations before we produce a triangle that intersects at most μ/2 lines of 𝒮 with high probability and hence can be taken as 𝒯. The time for all iterations is O(log(Nb/μ))(T1-Max(N,b,μ)+O(N0.1+o(1)))=O(log(Nb/μ))T1-Max(N,b,μ)+O(N0.1+o(1)).

4.2 Putting it all Together

We now present our linear time algorithm. This amounts to solving a curious recurrence, and we actually have significant freedom in choosing the values for b and b.

Theorem 8.

There is an algorithm for Problem 1 running in expected time O(n+m).

Proof.

We will always take μ:=20N/b3 and μ:=20N/(b)3, so we can drop the μ and μ arguments from the time complexity of each subroutine/oracle. We begin by reducing from Problem 1 to an instance of MaxRegion over a (20N/23,2,𝒯)-block structure, which requires no work beyond computing the area prefix sums because we can take SBad=[N/2] and SGood=. Thus the total expected running time for Problem 1 will be O(N)+T2-Max(N,2).

Before analyzing T2-Max(N,2), we find a closed-form expression for T1-Max(N,b) when 2bNo(1). As per Lemmas 5, 6, and 7, we have the following for any 2b,bNo(1) such that b divides b:

T1-Max(N,b)=O(Nlogblog2bb)+T1-Max(N,b).

We can efficiently parallelize the algorithm for zero-dimensional MaxRegion given in the proof of Lemma 5. So via a standard application of multidimensional parametric search (see Theorem 4.4 in the full version of [38]) that uses zero-dimensional MaxRegion for the decision problem, T1-Max(N,b)=O(N/logN) when b(logN)C1 for some constant C1. If we take b=2b (for example) and solve the recurrence, we get

T1-Max(N,b)=O(NlogN+a=logbO(loglogN)Nlog3(2a)2a)=O(Nlog3bb+NlogN).

Using the above along with Lemmas 5, 6, and 7, we have the following for any 2b,bNo(1) such that b divides b:

T2-Max(N,b)=O(Nlogblog3bb+NlogblogN)+T2-Max(N,b).

If we again take b=2b and stop to apply multidimensional parametric search when b=(logN)C2 for some constant C2, we have O(loglogN) recursion depth, and logb never exceeds O(loglogN). Solving the recurrence in the same way as for T1-Max(N,b) gives:

T2-Max(N,b)=O(Nlog4bb+Nlog2logNlogN).

Clearly T2(N,2)=O(N), and the theorem follows.

5 Constructing the Point Oracle

In this section, we prove the Point Oracle Lemma, restated below:

See 5

In other words, we need to use a given (μ,b,𝒯)-block structure (where 𝒯 is just a single point t) to calculate Area((P+t)Q). We can decompose the area function as

Area((P+t)Q)=iArea((Pi+t)Qi)+ijArea((Pi+t)Qj)

and then solve for each individual summation rapidly. The first summation is quite easy to compute by simply reading through the lists SGood and SBad that are provided.

Lemma 9.

There is an algorithm running in time O(N/b+μb) such that, given a (μ,b,𝒯)-block structure, where 2bNo(1) and 𝒯 consists of just a single point t, it will compute

iArea((Pi+t)Qi),

where P1,,PN/b and Q1,,QN/b are the blocks of P and Q determined by parameter b.

Proof.

By definition of the block structure, we have a partition of S=[N/b] into two subsets SGood and SBad such that |SBad|μ, and for each iSGood we have a constant complexity quadratic function fi(t)=Area((Pi+t)Qi) for all t𝒯.

We can thus compute

iSGoodArea((Pi+t)Qi)

in time O(N/b) by simply evaluating each fi(t). Since |SBad|μ, we can compute

iSBadArea((Pi+t)Qi)

by evaluating the area for each (Pi+t)Qi directly. The time required is O(μb) using known algorithms for intersecting two convex polygons whose edges are in sorted order.

We now turn our attention to the summation ijArea((Pi+t)Qj). Because every term amounts to computing the intersection for two blocks with different angle ranges, we could use binary searches to evaluate each term in O(polylog(b)) time. However, this is too slow for our purposes, as there are a near quadratic number of terms. Instead, we take advantage of additional structure to decompose the summation into O(N/b) intersections of unions of blocks, such that each intersection can still be computed via binary search.

As a tool, we need a way to efficiently intersect convex chains that meet certain conditions.

Lemma 10.

Let A and B be any two convex polygons, and let X and Y be any two polygonal chains whose edges are a subset of the edges of A and B, respectively. If ΛA(X)ΛB(Y)=, then X and Y intersect at most twice, and we can find the intersection point(s) in time O(log|X|log|Y|).

Proof.

Because the angle ranges for X and Y are disjoint, they act as pseudo-disks, and hence can intersect at most twice. We can find the intersection point(s), if they exist, using a standard nested binary search in O(log|X|log|Y|) time (or a more clever binary search [37] in O(log|X|+log|Y|) time, though we don’t need this improvement).

Now we can show how to compute ijArea((Pi+t)Qj).

Lemma 11.

There is an algorithm running in time O(Nlog2bb) such that, given a (μ,b,𝒯)-block structure, where 𝒯 consists of just a single point t, it will compute

ijArea((Pi+t)Qj),

where P1,,PN/b and Q1,,QN/b are the blocks of P and Q determined by parameter b.

Proof.

We give a recursive algorithm for the problem. As a subroutine, we consider the problem of computing, given two integers x,y[N/b] with x>y,

(i,j)W(x,y)Area((Pi+t)Qj), withW(x,y):={(i,j)[N/b]×[N/b]:ij,xi,jy}.

Let T(yx,b) be the time complexity of this subroutine. Since the original summation ijArea((Pi+t)Qj) is equivalent to (i,j)W(1,N/b)Area((Pi+t)Qj), the lemma amounts to showing that T(N/b1,b)=O(Nlog2bb), or more generally, T(z,b)=O(zlog2b).

Consider an instance of this subroutine with any parameters y>x. Let m:=x+y2 and z:=yx. We can decompose the target summation as follows:

(i,j)W(x,y) Area((Pi+t)Qj)=
(i,j)W(x,m1)Area((Pi+t)Qj)+(i,j)W(m,y)Area((Pi+t)Qj)+
xi<mjyArea((Pi+t)Qj)+xj<miyArea((Pi+t)Qj).

The first two summations can be evaluated in time at most 2T(yx2,b) via recursion (unless xy=1, in which case they are automatically zero). The last two summations can actually be evaluated directly. We consider the case of the very last summation; the remaining one can be evaluated via a symmetric process. First note that

xj<miyArea((Pi+t)Qj)=Area((miyPi+t)(xj<mQj)).

Let A=xi<mPi and B=mjyQj. Observe that A and B are both convex polygons, since each is the union of consecutive blocks. By construction, the edges that A shares with P and the edges that B shares with Q form two convex polygonal chains that have disjoint angle ranges, i.e., ΛP(EP(A))ΛQ(EQ(B))=. These chains account for all but two edges of A and two edges of B. Thus we can decompose A and B into O(1) convex polygonal chains satisfying the preconditions of Lemma 10. This implies that A and B intersect in at most a constant number of locations, and furthermore we can find the intersection points in time O(log2(bz)).

By decomposing A and B into O(1) pieces based on the intersection locations, we can use the area prefix sums888The area prefix sums for P and Q also act as ares prefix sums for A and B., along with a direct computation on the O(1) intersecting pairs of edges, to find the area of intersection in O(1) additional time. So the recurrence is T(z,b)=2T(z/2,b)+O(log2(bz)) when z>1 and T(1,b)=O(log2b). This solves to T(z,b)=O(zlog2b).

6 Constructing the Cascading Subroutine

The last step is to prove the Cascading Subroutine Lemma, restated below:

See 6

In other words, given a (μ,b,𝒯)-block structure, parameters μ and b, and a triangle or line segment 𝒯, we want to either produce a valid (μ,b,𝒯)-block structure, or report that more than μ/2 lines of the set 𝒮 intersect 𝒯. Throughout, let P1,,PN/b and Q1,,QN/b be the blocks of P and Q determined by block size parameter b, and let P1,,PN/b and Q1,,QN/b be the blocks of P and Q determined by block size parameter b.

First, we show that constant-complexity quadratic functions may actually be used to summarize the area function for certain block pairs.

Lemma 12.

Let A and B be any convex polygons, and let 𝒯 be any triangle or line segment contained in one cell of Π(A,B).999It is permissible for 𝒯 to touch the boundary of one cell, as long as it doesn’t strictly intersect. Then there exists a constant-complexity quadratic function f such that f(t)=Area((A+t)B) for all t𝒯.

Proof.

This follows from known observations by de Berg et al. [21].

Before describing how to perform cascading, we need a tool to help classify the new blocks based on their relationship with 𝒯.

Lemma 13.

Let A and B be any two convex polygons, and let X and Y be any two polygonal chains whose edges are a subset of the edges of A and B, respectively. Let 𝒯 be any triangle or line segment. If ΛA(X)ΛB(Y)=, then we can determine if some line segment in Π(X,Y) intersects the interior of 𝒯 in time O(log|X|log|Y|).

Proof.

Let the set of vertices for 𝒯 be V(𝒯). For each tV(𝒯), we know that, by Lemma 10, X+t and Y can intersect in at most two points, and we can find the two pairs of edges that contain these intersection(s) in time O(log|X|log|Y|).101010There is an edge case where at least one of the intersections occurs at a vertex of X or a vertex of Y, but this can be handled with slightly more work without increasing the asymptotic running time. Let the set of all O(1) edge pairs (eX,eY) for all vertices in V(𝒯) be L. We can determine if 𝒯π(eX,eY) for all (eX,eY)L via brute force in time O(1). If this is not the case, then some line segment of Π(X,Y) intersects the interior of 𝒯, and we are done. If this is the case, then because 𝒯 is convex and each π(eX,eY) is convex, we have that each translation t𝒯 realizes a set of intersecting pairs that is a (possibly strict) superset of L.

It remains to determine if any translations t𝒯 realize an intersecting pair not in L, because this case (and only this case) would mean that a line segment in Π(X,Y) intersects the interior of 𝒯. Let X be X with its edges participating in L deleted, and let Y be Y with its edges participating in L deleted. In time O(log|X|log|Y|) we can use techniques similar to the ones given above to determine if the interior of the (implicitly generated) Minkowski sum of 𝒯 and X has any intersection with Y, and then if the interior of the (implicitly generated) Minkowski sum of 𝒯 and X has any intersection with Y.

We are now ready to prove Lemma 6. The main observation is that the new quadratic functions stored in this data structure only need to apply when t𝒯, not the more general case that t𝒯, so many of the previously difficult blocks can now be handled. We will find a quadratic function for almost all indices k[N/b] in two steps:

  1. 1.

    Scan through the information provided in the input (μ,b,𝒯)-block structure, and use this to recover part of the function Area((Pk+t)Qk).

  2. 2.

    Recover the missing information for Area((Pk+t)Qk) by intersecting O(bb) pairs of convex polygons with disjoint angle ranges. We evaluate these using nested binary searches (Lemma 10 or 13) and area prefix sums.

Proof.

For all k[N/b], note that because b divides b, we have a set of indices Ck={(k1)bb+1,,kbb} such that Pk=iCkPi and Qk=jCkQj.111111The set may be smaller for the very last value of k, but this does not impact the proof. If for all (i,j)Ck×Ck and for all t𝒯 we can summarize Area((Pi+t)Qj) with a constant-complexity quadratic function, then we can simply add these to get a new function fk(t)=Area((Pk+t)Qk).

We first argue that each quadratic function fk(t) can be found efficiently, if it exists. Consider just a single value of k. We use the decomposition

fk(t)=(i,j)Ck×CkArea((Pi+t)Qj)=iCkArea((Pi+t)Qi)+(i,j)Ck×Ck:ijArea((Pi+t)Qj).

For the first summation on the right hand side, we scan through the list SGood from the original (μ,b,𝒯)-block structure. Each function Area((Pi+t)Qi) with iSGood already has a quadratic function, and reading these takes time O(bb) for each k, or O(N/b) time for all k. Globally, there are at most μ indices i not in SGood. For each of these, we can check whether 𝒯 lies in a single cell of Π(Pi,Qi) via directly examining each line segment in Π(Pi,Qi) in time O(b2). If this is the case, then by Lemma 12, Area((Pi+t)Qi) can be summarized by a quadratic function for all t𝒯, and we find the function via directly examining each parallelogram in Π(Pi,Qi) in time O(b2); the total additional time is O(μb2). (If this fails for some iCk, we will add the index k to SBad.)

Now consider the second summation on the right hand side. We can rewrite this as

(i,j)Ck×Ck:ijArea((Pi+t)Qj)=iCk(Area((Pi+t)Qi,k)+Area((Pi+t)Qi,k+)),

where Qi,k is the union of all Qj’s in the original sum with j<i, and Qi,k+ is the union of all Qj’s in the original sum with j>i. We evaluate each of the terms individually.

Consider the case of Area((Pi+t)Qi,k), as the case of Area((Pi+t)Qi,k+) is symmetric. Now, Qi,k is a convex polygon, because it is the union of consecutive blocks. By construction, ΛP(EP(Pi))ΛQ(EQ(Qi,k))=. Therefore, we can break Pi+t and Qi,k into O(1) pieces that satisfy the preconditions of Lemma 10, showing that Pi+t and Qi,k can only intersect at a constant number of locations for any translation t2. These same pieces allow us to apply Lemma 13 to determine if 𝒯 lies in a single cell of Π(Pi,Qi,k), which takes time O(log|Pi|log|Qi,k|)=O(logblogb). If this is the case, then by Lemma 12 there exists a quadratic function equal to Area((Pi+t)Qi,k) for all t𝒯. The nonconstant components of this quadratic function only depend on the O(1) intersecting pairs of edges, and we have already found these via Lemma 13. Thus we can break Pi and Qi,k into O(1) pieces based on the intersection points, and use the area prefix sums from the (μ,b,𝒯)-block structure (which also serve as area prefix sums for Pi and Qi,k), to find the quadratic function equal to Area((Pi+t)Qi,k) in O(1) additional time. (If this fails for some iCk, we will add the index k to SBad.)

Adding the time across all terms for all k[N/b] gives an overall time of O(Nlogblogbb).

Each index k for which we found a function fk(t) is added to SGood, and we store its function. The remaining indices are added to SBad. The last step is to argue that |SBad|μ, meaning we have constructed a valid (μ,b,𝒯)-block structure.

By construction, note that every kSBad corresponds to an intersection between (i,j)Ck×CkΠ(Pi,Qj) and the interior of 𝒯. Also by construction (see Equation 2), each line in 𝒮 has at most two indices k such is the line extension of some line segment in (i,j)Ck×CkΠ(Pi,Qj). Therefore we can charge each kSBad to different lines of 𝒮 in such a way that each line of 𝒮 will be charged at most twice. Thus if |SBad|>μ, this implies that more than μ/2 lines of 𝒮 intersect the interior of 𝒯, so the algorithm can just return failure in this case.

References

  • [1] Pankaj K. Agarwal, Torben Hagerup, Rahul Ray, Micha Sharir, Michiel H. M. Smid, and Emo Welzl. Translating a planar object to maximize point containment. In Proc. 10th Annual European Symposium on Algorithms (ESA), volume 2461 of Lecture Notes in Computer Science, pages 42–53. Springer, 2002. doi:10.1007/3-540-45749-6_8.
  • [2] Pankaj K. Agarwal and Micha Sharir. Efficient algorithms for geometric optimization. ACM Comput. Surv., 30(4):412–458, 1998. doi:10.1145/299917.299918.
  • [3] Hee-Kap Ahn, Peter Brass, and Chan-Su Shin. Maximum overlap and minimum convex hull of two convex polyhedra under translations. Comput. Geom., 40(2):171–177, 2008. doi:10.1016/J.COMGEO.2007.08.001.
  • [4] Hee-Kap Ahn, Siu-Wing Cheng, Hyuk Jun Kweon, and Juyoung Yon. Overlap of convex polytopes under rigid motion. Comput. Geom., 47(1):15–24, 2014. doi:10.1016/J.COMGEO.2013.08.001.
  • [5] Hee-Kap Ahn, Siu-Wing Cheng, and Iris Reinbacher. Maximum overlap of convex polytopes under translation. Comput. Geom., 46(5):552–565, 2013. doi:10.1016/J.COMGEO.2011.11.003.
  • [6] Hee-Kap Ahn, Otfried Cheong, Chong-Dae Park, Chan-Su Shin, and Antoine Vigneron. Maximizing the overlap of two planar convex sets under rigid motions. Comput. Geom., 37(1):3–15, 2007. doi:10.1016/J.COMGEO.2006.01.005.
  • [7] Helmut Alt and Leonidas J. Guibas. Discrete geometric shapes: Matching, interpolation, and approximation. In Jörg-Rüdiger Sack and Jorge Urrutia, editors, Handbook of Computational Geometry, pages 121–153. North Holland / Elsevier, 2000. doi:10.1016/B978-044482537-7/50004-8.
  • [8] Nancy M. Amato and Franco P. Preparata. A time-optimal parallel algorithm for three-dimensional convex hulls. Algorithmica, 14(2):169–182, 1995. doi:10.1007/BF01293667.
  • [9] Gill Barequet, Matthew T. Dickerson, and Petru Pau. Translating a convex polygon to contain a maximum number of points. Comput. Geom., 8:167–179, 1997. doi:10.1016/S0925-7721(96)00011-9.
  • [10] Sergio Cabello, Mark de Berg, Panos Giannopoulos, Christian Knauer, René van Oostrum, and Remco C. Veltkamp. Maximizing the area of overlap of two unions of disks under rigid motion. Int. J. Comput. Geom. Appl., 19(6):533–556, 2009. doi:10.1142/S0218195909003118.
  • [11] Timothy M. Chan. A simpler linear-time algorithm for intersecting two convex polyhedra in three dimensions. Discret. Comput. Geom., 56(4):860–865, 2016. doi:10.1007/S00454-016-9785-3.
  • [12] Timothy M. Chan. (Near-)linear-time randomized algorithms for row minima in Monge partial matrices and related problems. In Proc. of the 32nd ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1465–1482, 2021. doi:10.1137/1.9781611976465.88.
  • [13] Timothy M. Chan and Isaac M. Hair. Convex polygon containment: Improving quadratic to near linear time. In Proc. 40th International Symposium on Computational Geometry (SoCG), volume 293 of LIPIcs, pages 34:1–34:15, 2024. doi:10.4230/LIPICS.SOCG.2024.34.
  • [14] Bernard Chazelle. The polygon containment problem. Advances in Computing Research, 1(1):1–33, 1983. URL: https://www.cs.princeton.edu/˜chazelle/pubs/PolygContainmentProb.pdf.
  • [15] Bernard Chazelle. Triangulating a simple polygon in linear time. Discret. Comput. Geom., 6:485–524, 1991. doi:10.1007/BF02574703.
  • [16] Bernard Chazelle. Cuttings. In Dinesh P. Mehta and Sartaj Sahni, editors, Handbook of Data Structures and Applications. Chapman and Hall/CRC, 2004. doi:10.1201/9781420035179.CH25.
  • [17] Bernard Chazelle and Leonidas J. Guibas. Fractional cascading: I. A data structuring technique. Algorithmica, 1(2):133–162, 1986. doi:10.1007/BF01840440.
  • [18] Siu-Wing Cheng and Chi-Kit Lam. Shape matching under rigid motion. Comput. Geom., 46(6):591–603, 2013. doi:10.1016/J.COMGEO.2013.01.002.
  • [19] Kenneth L. Clarkson. New applications of random sampling in computational geometry. Discret. Comput. Geom., 2:195–222, 1987. doi:10.1007/BF02187879.
  • [20] Kenneth L. Clarkson and Peter W. Shor. Application of random sampling in computational geometry, II. Discret. Comput. Geom., 4:387–421, 1989. doi:10.1007/BF02187740.
  • [21] Mark de Berg, Otfried Cheong, Olivier Devillers, Marc J. van Kreveld, and Monique Teillaud. Computing the maximum overlap of two convex polygons under translations. Theory Comput. Syst., 31(5):613–628, 1998. doi:10.1007/PL00005845.
  • [22] Martin E. Dyer. Linear time algorithms for two- and three-variable linear programs. SIAM J. Comput., 13(1):31–45, 1984. doi:10.1137/0213003.
  • [23] Martin E. Dyer. On a multidimensional search technique and its application to the euclidean one-centre problem. SIAM J. Comput., 15(3):725–738, 1986. doi:10.1137/0215052.
  • [24] Greg N. Frederickson and Donald B. Johnson. Generalized selection and ranking: Sorted matrices. SIAM J. Comput., 13(1):14–30, 1984. doi:10.1137/0213002.
  • [25] Sariel Har-Peled and Subhro Roy. Approximating the maximum overlap of polygons under translation. Algorithmica, 78(1):147–165, 2017. doi:10.1007/S00453-016-0152-9.
  • [26] Shreesh Jadhav and Asish Mukhopadhyay. Computing a centerpoint of a finite planar set of points in linear time. Discret. Comput. Geom., 12:291–312, 1994. doi:10.1007/BF02574382.
  • [27] Mook Kwon Jung, Seokyun Kang, and Hee-Kap Ahn. Minimum convex hull and maximum overlap of two convex polytopes. In Proc. 36th ACM-SIAM Symposium on Discrete Algorithms (SODA), 2025. To appear.
  • [28] Garam Kim, Jongmin Choi, and Hee-Kap Ahn. Maximum overlap of two convex polygons. KIISE Transactions on Computing Practices, 27(8):400–405, 2021. doi:10.5626/KTCP.2021.27.8.400.
  • [29] Jirí Matoušek. Approximations and optimal geometric divide-an-conquer. J. Comput. Syst. Sci., 50(2):203–208, 1995. doi:10.1006/JCSS.1995.1018.
  • [30] Nimrod Megiddo. Applying parallel computation algorithms in the design of serial algorithms. J. ACM, 30(4):852–865, 1983. doi:10.1145/2157.322410.
  • [31] Nimrod Megiddo. Linear-time algorithms for linear programming in R3 and related problems. SIAM J. Comput., 12(4):759–776, 1983. doi:10.1137/0212052.
  • [32] Nimrod Megiddo. Linear programming in linear time when the dimension is fixed. J. ACM, 31(1):114–127, 1984. doi:10.1145/2422.322418.
  • [33] Nimrod Megiddo. Partitioning with two lines in the plane. J. Algorithms, 6(3):430–433, 1985. doi:10.1016/0196-6774(85)90011-2.
  • [34] David M. Mount, Ruth Silverman, and Angela Y. Wu. On the area of overlap of translated polygons. Comput. Vis. Image Underst., 64(1):53–61, 1996. doi:10.1006/CVIU.1996.0045.
  • [35] Wlodzimierz Ogryczak and Arie Tamir. Minimizing the sum of the k largest functions in linear time. Inf. Process. Lett., 85(3):117–122, 2003. doi:10.1016/S0020-0190(02)00370-8.
  • [36] Joseph O’Rourke, Subhash Suri, and Csaba D. Tóth. Polygons. In Jacob E. Goodman, Joseph O’Rourke, and Csaba D. Tóth, editors, Handbook of Discrete and Computational Geometry, pages 787–810. Chapman and Hall/CRC, 3rd edition, 2017. URL: https://www.csun.edu/˜ctoth/Handbook/chap30.pdf.
  • [37] Mark H. Overmars and Jan van Leeuwen. Maintenance of configurations in the plane. J. Comput. Syst. Sci., 23(2):166–204, 1981. doi:10.1016/0022-0000(81)90012-X.
  • [38] Sivan Toledo. Maximizing non-linear concave functions in fixed dimension. In Proc. 33rd Annual Symposium on Foundations of Computer Science (FOCS), pages 676–685, 1992. doi:10.1109/SFCS.1992.267783.
  • [39] Eitan Zemel. An O(n) algorithm for the linear multiple choice knapsack problem and related problems. Inf. Process. Lett., 18(3):123–128, 1984. doi:10.1016/0020-0190(84)90014-0.
  • [40] Honglin Zhu and Hyuk Jun Kweon. Maximum overlap area of a convex polyhedron and a convex polygon under translation. In Proc. 39th International Symposium on Computational Geometry (SoCG), volume 258 of LIPIcs, pages 61:1–61:16, 2023. doi:10.4230/LIPICS.SOCG.2023.61.