The Largest Contained Quadrilateral and the Smallest Enclosing Parallelogram of a Convex Polygon

by   Günter Rote, et al.

We present a linear-time algorithm for finding the quadrilateral of largest area contained in a convex polygon, and we show that it is closely related to an old algorithm for the smallest enclosing parallelogram of a convex polygon.



There are no comments yet.



The Largest Quadrilateral in a Convex Polygon

We present a simple linear-time algorithm for finding the quadrilateral ...

Maximum-Area Triangle in a Convex Polygon, Revisited

We revisit the following problem: Given a convex polygon P, find the lar...

Computing Convex Partitions for Point Sets in the Plane: The CG:SHOP Challenge 2020

We give an overview of the 2020 Computational Geometry Challenge, which ...

Largest and Smallest Area Triangles on a Given Set of Imprecise Points

In this paper we study the following problem: we are given a set of impr...

Maximum-Area Quadrilateral in a Convex Polygon, Revisited

In this note we show by example that the algorithm presented in 1979 by ...

k-Maximum Subarrays for Small k: Divide-and-Conquer made simpler

Given an array A of n real numbers, the maximum subarray problem is to f...

An Adaptive s-step Conjugate Gradient Algorithm with Dynamic Basis Updating

The adaptive s-step CG algorithm is a solver for sparse, symmetric posit...
This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

A linear-time algorithm for the largest quadrilateral contained in a convex polygon was proposed in 1979 by Dobkin and Snyder [3]. This algorithm stood until 2017, when Keikha, Löffler, Mohades, Urhausen, and van der Hoog [4] constructed a counterexample for which it fails.

A simple linear-time algorithm for the smallest parallelogram enclosing a convex polygon was published in a technical report by Schwarz, Teich, Welzl, and Evans [8] in 1994, see also [7].

We will show that the two problems are closely related, in particular when they are constrained by anchoring them to some specified direction. The solution of one problem provides an optimality certificate for the other problem. We present a conceptually simple algorithm that treats both problems in a symmetric way and solves them simultaneously in linear time. The algorithm is based on the “rotating calipers” technique from the early days of computational geometry. Proofs are included, so that there can be no doubts about its correctness.

The algorithm becomes very simple when specialized for solving only one of the two problems, see Appendices C and B. Linear-time algorithms for the largest quadrilateral were independently found in 2018 by Vahideh Keikha (personal communication, manuscript in preparation) and by Kai Jin (personal communication, manuscript previously submitted to a conference), and they are essentially the same as the algorithm given here. According to [1], a linear-time solution is given in unpublished notes of Michael Shamos from 1974 [9]. Given that the solution is so simple, this is plausible, but I have not been able to confirm it.

While the algorithms that we develop were known, the observation that the two problems are so closely connected (Lemma 2) appears to be new. A similar dual connection between the anchored versions of two problems exists between the largest contained and the smallest enclosing triangle. This connection was first noted and exploited in the linear-time algorithm of Chandran and Mount [2] for these problems, see also [6, Lemmas 4.i and 14] for a slightly more stringent treatment in the style of Lemma 2.

2 Conjugate Pairs

A direction

is given by a nonzero vector

. Parallel vectors represent the same direction, and opposite directions are considered equal. Directions are conveniently parameterized by the polar angle : .

We denote the quadrilateral contained in conventionally by its four corners . For the parallelogram that surrounds , it will be better to denote it by the four sides , leaving the corners anonymous, see Figure 1.

Definition 1.
  1. A quadrilateral is D-anchored to if the diagonal is parallel to .

  2. A parallelogram is S-anchored to if the two sides and are parallel to .

The letter D stands for “diagonal”, and S stands for “side”. We will sometimes just say “anchored” if it is clear from the context which version we mean.

Definition 2.

Let be a quadrilateral, and let be a parallelogram. We say that and are conjugate, or form a conjugate pair, if

  1. the diagonal is parallel to the sides and , and

  2. each corner of lies on the corresponding side of .

Because of the first condition, the two elements and of a conjugate pair are anchored to the same direction. Because of the second condition, is a convex quadrilateral contained in . It is possible that degenerates to a triangle because it is not necessarily strictly convex, and it may even happen that some corners coincide.

Figure 1: A conjugate pair . The quadrilateral is D-anchored and the parallelogram is S-anchored to the direction . The heights and of the two triangles into which is decomposed by the diagonal sum up to the distance between the lines through and .

The following basic geometric lemma considers a conjugate pair in isolation and proves some optimality properties of and with respect to each other.

Lemma 1.
  1. Let be a parallelogram, S-anchored to some direction . Then a quadrilateral  that is contained in and is D-anchored to is a largest quadrilateral with these properties if and only if is a conjugate pair.

  2. Let be a quadrilateral, D-anchored to some direction . Then a parallelogram  that contains and is S-anchored to is a smallest parallelogram with these properties if and only if is a conjugate pair.

  3. If is a conjugate pair, the area of is twice the area of .


See Figure 1. Since and are required to be anchored to the same direction, the first condition for a conjugate pair is always satisfied. The question is whether the four sides of are incident to the four corresponding corners of .

Let denote the length of the two sides of that are parallel to . Then, given that the diagonal should be parallel to and contained in , it is clear that

with equality if and only if the sides and touch and .

Moreover, if is contained in , the distance between and , when projected to the direction perpendicular to , is at most the distance between the lines through and :

with equality if and only if the sides and touch and .

(a) The quadrilateral  is composed of the triangles and , which share the common base . Therefore, the area of is expressed in terms of the heights and of these triangles as


and we have just seen that equality holds if and only if the four sides of touch the corresponding corners of . This proves (a). The area of the parallelogram is


which equals twice the area of in (1), and this proves (c).

To prove (b), we use (1) in the other direction, giving a lower bound on the area (2) of any anchored parallelogram containing . Again, since equality in (1) holds if and only if and are conjugate, (b) has been proved. ∎

Figure 2: A conjugate pair anchored to the direction and sandwiching a convex polygon .

The following crucial lemma gives the optimality condition for the anchored versions of the two problems.

Lemma 2 (Characterization of Optimality by Conjugate Pairs).

Let be a convex polygon in the plane, and let be a direction.

  1. A quadrilateral that is D-anchored to and contained in is a largest quadrilateral with these properties if and only if there is a parallelogram containing that is conjugate to .

  2. A parallelogram enclosing and S-anchored to is a smallest parallelogram with these properties if and only if there is a quadrilateral contained in that is conjugate to .

Proof of sufficiency..

In both cases, there is a conjugate pair such that the convex region is sandwiched between them: .

a) By Lemma 1a, is even the largest D-anchored quadrilateral inside the larger region . Thus, there cannot be a larger anchored quadrilateral in .

b) By Lemma 1b, is even the smallest S-anchored parallelogram that encloses the smaller region . Thus, there cannot be a smaller anchored parallelogram enclosing . ∎

Necessity of the conditionsis not needed for the correctness of our algorithm, and it will only be proved later as an easy consequence of Lemma 4, see page 5. Alternatively, there are easy direct proofs (cf. [8, Lemma 2]), even for arbitrary convex regions.

The lemma is also a manifestation of linear programming duality, since the problem of finding the longest chord

with a given direction can be formulated as a linear program.

3 Constructing all Conjugate Pairs in Linear Time

The idea is to construct conjugate pairs with for all directions in the range . By the sufficient criterion of Lemma 2, these are largest anchored contained quadrilaterals and smallest anchored enclosing parallelograms. Hence, the overall largest contained quadrilaterals and smallest enclosing parallelograms will be among them.

The following straightforward observation separates the task of finding an anchored conjugate pair into two subtasks. The first involves , , , and , and it is concerned with the direction of the diagonal . The other task involves , , , and , and it is concerned with the direction of the sides and . A pair of points on the boundary of a convex region that admits parallel supporting lines is called antipodal.

Lemma 3.

Let be a convex region in the plane and be a direction. A conjugate pair with and anchored to is found as follows, see Figure 2. Here, the parallelogram  is defined by two pairs of parallel lines and :

  1. is an antipodal pair of parallel to , with supporting lines and ,

  2. and are the two opposite lines of support parallel to , and and are points where these lines touch . (Thus, is also an antipodal pair.)

As stated in the following lemma, whose proof will be given in Section 5, both tasks can easily be carried out with the classical rotating-calipers technique. We assume that is a convex polygon, given by the ordered list of its vertices.

Lemma 4.
  1. In time, one can find a sequence of direction angles , and a corresponding sequence of vertex-edge pairs , such that for any  in each closed interval , an antipodal segment parallel to can be found by intersecting the line through parallel to with the edge . The lines parallel to through and are the corresponding supporting lines.

  2. In time, one can find a sequence of direction angles , and a corresponding sequence of antipodal pairs of vertices , with , such that for any in each closed interval , the lines through and parallel to the direction are supporting lines.

We remark that the sequence does not necessarily include every pair of antipodal vertices: For each pair of opposite parallel edges of , there are two pairs of antipodal vertices which admit parallel supporting lines of only one direction. These pairs don’t appear in the list.

It is now clear how to proceed with the help of Lemma 4. Since the areas of a conjugate pair are related by Lemma 1c, let us ignore the enclosing parallelograms and concentrate on the inner quadrilaterals . We merge the lists of breakpoints and and obtain a list of intervals such that in each interval, there are largest anchored quadrilaterals with a fixed structure: The points and are fixed vertices. On the diagonal , one point, say , is fixed to a vertex , while the other point moves on a fixed edge .

In a quadrilateral with one moving point , the area is a linear function of . As increases, the corner moves monotonically on some edge , and therefore, the extremes are attained at the endpoints of the interval. We thus just need to evaluate the area at all interval endpoints and of the merged sequence and pick the largest or smallest one. Since each endpoint belongs to two intervals, the quadrilateral  prescribed by Lemma 4 may be ambiguous, but this does not matter. All these quadrilaterals have the same area.

Theorem 5.
  1. The quadrilateral of largest area contained in a convex polygon can be found in linear time.

  2. The parallelogram of smallest area enclosing a convex polygon can be found in linear time. ∎

Pseudocode for the algorithm is given in Appendix A, and prototype implementations of the algorithms in Appendices C, B and A in Python are contained in the source files of this preprint.

4 Discussion

It is perhaps instructive to reflect on some features of this algorithm and compare it to other approaches. An easy property of largest quadrilaterals (in fact, largest -gons for any ) contained in a polygon  is the vertex property: Their corners must be vertices of . Our algorithm does not use this property at all. It considers an infinite family of quadrilaterals. Even after reducing them to a discrete set of directions (the interval endpoints and ), many of these candidates don’t fulfill the vertex property. Most previous algorithms for largest contained -gons, and in particular, the algorithms of Dobkin and Snyder [3], consider only -gons with the vertex property. By concentrating on the vertex property too early, one may miss useful avenues to finding good and simple algorithms.

We may of course still use the vertex property as an “afterthought” to introduce shortcuts and simplify the algorithm. For example, once the point lies in the middle of an edge, one can skip the area computations and fast-forward until arrives at a vertex. (For the problem of the largest contained triangle, the analogous step is described in [6, Section 8].)

There are other possible simplifications. The two lists of breakpoints and need not be computed separately in advance. They can be generated on the fly as they are processed, after an appropriate initialization. We have described the algorithm in terms of angles for convenience. When implementing the algorithm on a computer, it is better to avoid angle calculations and use direct comparisons of vector directions or signed areas, see Section A.1. (Anyway, since the problem is invariant under affine transformations, angular quantities are not really suited to the problem.)

In Appendix B, we show the whole simplified algorithm for the largest contained quadrilateral. This algorithm is actually so simple that one can as well derive it directly from the property that must form an antipodal vertex pair, without going through the continuous family . The same remark holds for the smallest enclosing parallelogram. Appendix C shows a variation of the algorithm following [8] that is just as simple.

5 Rotating Calipers

Proof of Lemma 4.

For part (a), we need antipodal points for all directions. An algorithm for listing all antipodal pairs of vertices of a convex polygon is given in [5, Section 4.2.3]. We just need to “fill the gaps” in order to get antipodal pairs for a continuous range of directions

Let and be two opposite lines of support in direction , see Figure 3. We will increase from to and maintain the points and where they touch . Since we want these points to move continuously, we parameterize the process by a new parameter , where it the combined distance moved by and along the boundary of since the beginning. We start with and as the lowest and highest points of . In case of ties, we take the leftmost lowest and the rightmost highest point. Figure 3a shows and the distances and moved by and , from which is computed as .

Figure 3: Four successive stages of the circular sweep: (a) The antipodal points and together with the parallel support lines and , for the parameter . The angle increases until or hits an edge. (b) The line has hit an edge. is stationary and slides along this edge. (c)  increases further, and hits an edge. (d)  is stationary and moves.

Now we start to increase . Whenever is parallel to an edge of , we continuously advance or to the other endpoint of this edge, increasing while leaving constant. If has two sides parallel to , we arbitrarily use the convention that we first advance and then . Now, and are ready to tilt around the vertices and , increasing while remains constant, until or hits the next edge.

We continue this process in a loop until . At this point, and have swapped places, and equals the perimeter of . The segment has completed a rotation by .

The points and move continuously in counterclockwise direction as a function of , and for every , the points and are antipodal, as witnessed by supporting lines and . Thus we have achieved our primary goal of finding an antipodal pair for every direction.

The parameter range of is decomposed into intervals where remains stationary, remains stationary, or both points remain stationary. We cut out those intervals where none of the points move. For the remaining intervals, we choose yet another parameterization, namely by the direction pointing from to .

Each of the remaining intervals is characterized by one stationary point, , while the other point moves on a fixed edge, . If is the direction pointing from to , The breakpoints and are the directions at the end of the intervals, when both and are at vertices. It only remains to rearrange the interval breakpoints cyclically modulo in order to start with . Since each interval advances either or by one vertex and and together make a full tour around , the number of interval breakpoints is .

Part (b) of the lemma is straightforward. In fact, it can be obtained by the same circular sweep as above, with the straightforward parameterization by the angle , concentrating only on the points and where the supporting lines in direction touch . (These points will take the roles of and in the lemma.)

The breakpoint directions are therefore the directions where or jumps. These are the directions for which is parallel to some edge of . There are at most such angles. The sequence is obtained by merging the two lists of edge directions obtained from traversing the left boundary of and the right boundary of counterclockwise, between the extreme points in vertical direction. ∎

Proof of necessity in Lemma 2..

a) Assume that is a largest quadrilateral that is D-anchored to and contained in . Lemma 4 together with Lemma 3 implies that, for this direction , there exists an anchored conjugate pair with . By the sufficiency part of Lemma 2, which has already been proved, is a largest anchored quadrilateral contained in , and therefore of the same area as . By Lemma 1a, is even a largest anchored quadrilateral contained in the larger area . By the necessity statement in the same lemma, since is also contained in , can only have the same area as if it forms a conjugate pair with . This proves the necessity for Part (a). The proof of Part (b) is completely analogous. ∎


Appendix A The Algorithm in Pseudocode

For completeness, we give the pseudocode for our algorithm. We assume that the convex polygon is given by the ordered list of its vertices in counterclockwise order. We assume that , and we look for a largest contained quadrilateral  in counterclockwise order, and a smallest enclosing parallelogram, also in counterclockwise order. Indices of polygon vertices are considered modulo .

In contrast to the algorithm that is sketched in Section 3, we don’t start with , but we start more conveniently with the antipodal pair defined by and the point opposite to the edge .

a.1 Primitive Operations

The basic predicate of this algorithm is a comparison between two directions and , which can be calculated with only two multiplications as the sign of a determinant that expresses the signed area of the parallelogram spanned by and :

This is positive if lies counterclockwise from . The area of a quadrilateral is .

Frequently, the algorithm makes comparisons between triangle areas over a common basis. This should also be calculated as a determinant. For example, if the two triangles are oriented counterclockwise. Since we find the formulation involving triangle areas geometrically more appealing, we have not replaced it in our pseudocode.

a.2 Largest and smallest anchored quadrilaterals

Lemma 6 ([8, Lemma 1]).

There is a smallest enclosing parallelogram  such that

  1. at least one of the sides and touches an edge of , and

  2. at least one of the sides and touches an edge of .


A smallest enclosing parallelogram  must be a smallest enclosing parallelogram anchored to the direction of and , and hence there must be a conjugate pair , see Figure 2. If the side or doesn’t already touch an edge of , these sides can be tilted around and without changing the area, until one of the sides hits an edge of .

Afterwards, we can apply the same argument to the direction of and and ensure that or touches an edge of . ∎

As a consequence of part 2, when looking for the smallest enclosing parallelogram, it is sufficient to look at parallelograms that are S-anchored to the directions of the edges of . We have already mentioned that a largest contained quadrilateral can be found among those quadrilaterals that use only vertices of . Thus it is sufficient to look at anchored quadrilaterals for which and lie at vertices. This explains the places where areas are compared against the current minimum or maximum in the following program.

a.3 Pseudocode

while :
(find the point with supporting line parallel to .)
(The corner slides on the edge .)
(the direction where hits the next vertex)
while :
(find the point with supporting line parallel to .)
while :
(find the other point with supporting line parallel to .)
if :
(The parallelogram side hits an edge of before does.)
(The parallelogram side hits an edge of before does.)
(the area of the largest contained quadrilateral)
(the area of the smallest enclosing parallelogram)
if :
(The parallelogram side or touches an edge of .)
if :
construct the point on the line such that is parallel to
() }
construct the point on the line such that is parallel to
() }
if :
if :
(The parallelogram side hits an edge of before does.)
(The parallelogram side hits an edge of before does.)
else: (The sliding corner or reaches a vertex of .)
if :
if : (Which of and slides on an edge of ?)
(The corner slides on the edge .)
(the direction where hits the next vertex)
(The corner slides on the edge .)
(the direction where hits the next vertex)

The area of in line () can be computed by the formula

and for the area of in (), we replace by in two places.

Appendix B The Largest Contained 4-Gon

We give here the specialized algorithm for computing the area of the largest 4-gon contained in a convex polygon .

In contrast to the algorithm that is sketched in Section 3, and also differently from Section A.3, we start as in Section 5 with the points and that have horizontal supporting lines, see Figure 3. Let be the leftmost vertex among the lowest vertices of Let be the rightmost vertex among the highest vertices of repeat while : (find the point with supporting line parallel to .) while : (find the other point with supporting line parallel to .) } if : (advance to the next antipodal pair) else: until The main loop is driven by the antipodal pair . In each iteration, either or is advanced to the next vertex. This is essentially the program for reporting all antipodal pairs of vertices from [5, Section 4.2.3], except that we need not be careful about getting all such pairs if has parallel edges. In the two inner loops, the points and that are farthest from the line are updated.

Appendix C The Smallest Enclosing Parallelogram According to Schwarz, Teich, Welzl, and Evans [8]

The algorithm of Schwarz et al. [8] is similar in spirit to our algorithm in constructing a sequence of parallelograms by advancing the direction to which and are parallel, following the rotating-calipers technique. They also sketch an application of smallest enclosing parallelograms to signal compression [8, Section 4], and the appendix gives details about a C++ implementation.

There is one difference in the setup. We explain it with our notation: By Lemma 6 ([8, Lemma 1]), it suffices to look for parallelograms where at least one of the sides and touches a whole edge of , and at least one of the sides and touches a whole edge of . This means that two adjacent parallelogram sides must touch edges of . Now, the algorithm of [8] only considers those anchored parallelograms where these two sides are and , like in Figure 4a. This restriction is compensated by sweeping over an angular range of instead of .

Figure 4 illustrates a few steps of the algorithm. After finding the parallelogram of Figure 4a and computing its area, the algorithm of Section A.3, when specialized for the smallest containing parallelogram, would next look at the parallelogram of Figure 4b. This parallelogram is skipped in Schwarz et al. [8] at this point, but this omission is no mistake: This parallelogram was already considered before with rotated labels, when touched and touched . The next parallelogram is not shown: touches the edge and touches . This parallelogram is also skipped by Schwarz et al. [8] at this point, but it is considered later when touches and touches . Figure 4b shows the next parallelogram. It is a largest S-anchored parallelogram when the side is anchored, but it is not a largest S-anchored parallelogram when the side is anchored, because the dashed antipodal pair is not parallel to and . Hence it cannot be a largest enclosing parallelogram. The algorithm of Schwarz et al. [8] skips this parallelogram and does not consider it at all.

Figure 4: Three snapshots of the algorithm

This setup makes the algorithm simple and elegant: Most case distinctions of Section A.3 can be eliminated, together with the flags next_AC and next_BD. Like in Section B, the algorithm can be structured into two nested loops. The outer loop iterates over the edges of through which goes, and the inner loop updates the antipodal pair parallel to the direction of .

; ; ;
while : (initialization)
(find the opposite point with supporting line parallel to )
for :
while :
(update the point opposite to )
while :
(search for antipodal pair parallel to , with on an edge)
or ( and ):
(update the point opposite to )
if :
construct the point on the line such that is parallel to

The algorithm of [8] actually uses a precomputed list that stores for each edge of an antipodal vertex that is farthest away from the line through . By contrast, the algorithm above updates the vertex opposite to and the vertex opposite to on the fly. The treatment of degenerate cases is also different.