1 Introduction
A lineartime 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 lineartime 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. Lineartime 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 lineartime 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 lineartime 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.

A quadrilateral is Danchored to if the diagonal is parallel to .

A parallelogram is Sanchored 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

the diagonal is parallel to the sides and , and

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.
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.

Let be a parallelogram, Sanchored to some direction . Then a quadrilateral that is contained in and is Danchored to is a largest quadrilateral with these properties if and only if is a conjugate pair.

Let be a quadrilateral, Danchored to some direction . Then a parallelogram that contains and is Sanchored to is a smallest parallelogram with these properties if and only if is a conjugate pair.

If is a conjugate pair, the area of is twice the area of .
Proof.
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
(1) 
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
(2) 
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.

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

A parallelogram enclosing and Sanchored 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: .
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 :

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

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 rotatingcalipers technique. We assume that is a convex polygon, given by the ordered list of its vertices.
Lemma 4.

In time, one can find a sequence of direction angles , and a corresponding sequence of vertexedge 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.

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.

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

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 fastforward 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 .
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 Danchored 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. ∎
References
 [1] James E. Boyce, David P. Dobkin, Robert L. (Scot) Drysdale III, and Leo J. Guibas. Finding extremal polygons. SIAM J. Computing, 14(1):134–147, 1985. doi:10.1137/0214011.
 [2] Sharat Chandran and David M. Mount. A parallel algorithm for enclosed and enclosing triangles. International Journal of Computational Geometry & Applications, 2(2):191–214, 1992. doi:10.1142/S0218195992000123.
 [3] David P. Dobkin and Lawrence Snyder. On a general method for maximizing and minimizing among certain geometric problems. In 20th Annual Symposium on Foundations of Computer Science, pages 9–17. IEEE, 1979. doi:10.1109/SFCS.1979.28.
 [4] Vahideh Keikha, Maarten Löffler, Ali Mohades, Jérôme Urhausen, and Ivor van der Hoog. Maximumarea triangle in a convex polygon, revisited. Preprint, 2017. arXiv:1705.11035v2.
 [5] Franco P. Preparata and Michael Ian Shamos. Computational Geometry. An Introduction. Springer, 1985.
 [6] Günter Rote. The largest inscribed triangle and the smallest circumscribed triangle of a convex polygon: An overview of lineartime algorithms. Class notes, June 2019. URL: https://kvv.imp.fuberlin.de/x/w77mPE.
 [7] Christian Schwarz, Jürgen Teich, Alek Vainshtein, Emo Welzl, and Brian L. Evans. Minimal enclosing parallelogram with application. In Proceedings of the Eleventh Annual Symposium on Computational Geometry, SoCG’95, pages 434–435, New York, NY, USA, 1995. ACM. doi:10.1145/220279.220338.
 [8] Christian Schwarz, Jürgen Teich, Emo Welzl, and Brian L. Evans. On finding a minimal enclosing parallelogram. Technical Report TR94036, International Computer Science Institute (ICSI), August 1994. URL: http://www.icsi.berkeley.edu/ftp/global/pub/techreports/1994/tr94036.pdf.
 [9] Michael Ian Shamos. Problems in computational geometry. Manuscript, 1974–1977.
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

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

at least one of the sides and touches an edge of .
Proof.
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 Sanchored 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.)  
else:  
(The parallelogram side hits an edge of before does.)  
(the area of the largest contained quadrilateral)  
(the area of the smallest enclosing parallelogram)  
repeat  
if :  
(The parallelogram side or touches an edge of .)  
if :  
construct the point on the line such that is parallel to  
()  }  
else:  
construct the point on the line such that is parallel to  
()  }  
if :  
else:  
if :  
(The parallelogram side hits an edge of before does.)  
else:  
(The parallelogram side hits an edge of before does.)  
else: (The sliding corner or reaches a vertex of .)  
if :  
else:  
}  
if : (Which of and slides on an edge of ?)  
(The corner slides on the edge .)  
(the direction where hits the next vertex)  
else:  
(The corner slides on the edge .)  
(the direction where hits the next vertex)  
until 
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 4Gon
We give here the specialized algorithm for computing the area of the largest 4gon 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 rotatingcalipers 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 Sanchored parallelogram when the side is anchored, but it is not a largest Sanchored 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.
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)  
while  
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.
Comments
There are no comments yet.