Finding Largest Rectangles in Convex Polygons

EuroCG 2014, Ein-Gedi, Israel, March 3–5, 2014
Finding Largest Rectangles in Convex Polygons∗
Sergio Cabello†
Otfried Cheong
Abstract
We consider the following geometric optimization
problem: find a maximum-area rectangle and a
maximum-perimeter rectangle contained in a given
convex polygon with n vertices. We give exact algorithms that solve these problems in time O(n3 ). We
also give (1 − ε)-approximation algorithms that take
time O(ε−3/2 + ε−1/2 log n) for maximizing the area
and O(ε−3 + ε−1 log n) for maximizing the perimeter.
Keywords: geometric optimization; approximation algorithm; convex polygons; inscribed rectangles.
1
Introduction
Computing a largest rectangle contained in a polygon
(with respect to some appropriate measure) is a well
studied problem. Previous results include computing
largest axis-aligned rectangles, either in convex polygons [2] or simple polygons (possibly with holes) [5],
and computing largest fat rectangles in simple polygons [6].
Here we study the problem of finding a maximumarea rectangle and a maximum-perimeter rectangle
contained in a given convex polygon with n vertices.
We give exact O(n3 )-time algorithms and (1 − ε)approximation algorithms that take time O(ε−3/2 +
ε−1/2 log n) for maximizing the area and O(ε−3 +
ε−1 log n) for maximizing the perimeter. (For maximizing the perimeter we allow the degenerate solution consisting of a single segment whose perimeter is
twice its length.) To the best of our knowledge, apart
from a straightforward O(n4 )-time algorithm, there is
no other exact algorithm known so far.
Our approximation algorithm to maximize the area
improves the previous results by Knauer et al. [7],
where they give a deterministic (1 − ε)-approximation
algorithm with running time O(ε−2 log n) and a
∗ Supported
by the Slovenian Research Agency, program P10297, projects J1-4106 and L7-5459; by the ESF EuroGIGA
project (project GReGAS) of the European Science Foundation; and by NRF grants 2011-0016434 and 2011-0030044
(SRC-GAIA), both funded by the government of Korea.
† Department of Mathematics, IMFM, and Department of
Mathematics, FMF, University of Ljubljana, Slovenia. Part of
the work was done while visiting KAIST, Korea.
‡ Department of Computer Science, KAIST, Daejeon, Korea.
§ Institute of Computer Science, Freie Universität Berlin,
Germany.
‡
Lena Schlipf
§
Monte Carlo (1 − ε)-approximation algorithm with
running time O(ε−1 log n). We are not aware of previous (1 − ε)-approximation algorithms to maximize
the perimeter.
Notation. We use C for arbitrary convex bodies and
P for convex polygons.
2
Preliminaries
Let U be the set of unit vectors in the plane. For each
u ∈ U and each convex body C, the directional width
of C in direction u, denoted by dwidth(u, C), is the
length of the orthogonal projection of C onto any line
parallel to u. Thus
dwidth(u, C) = maxhp, ui − minhp, ui,
p∈C
p∈C
where h·, ·i denotes the scalar product.
For a convex body C and a parameter ε ∈ (0, 1),
an ε-kernel for C is a convex body Cε ⊆ C such that
∀u ∈ U : (1 − ε) · dwidth(u, C) ≤ dwidth(u, Cε ).
The diameter of C is the distance between the two
furthest points of C. It is easy to see that it equals
max dwidth(u, C).
u∈U
Ahn et al. [1] show how to compute an ε-kernel.
Their algorithm uses the following type of primitive
operations for C:
• given a direction u ∈ U, find an extremal point
of C in the direction u;
• given a line `, find C ∩ `.
Let TC be the time needed to perform each of those
primitive operations. We will use TC as a parameter
in some of our running times. When C is a convex
n-gon whose boundary is given as a sorted array of
vertices or as a binary search tree, we have TC =
O(log n) [4, 10]. Ahn et al. show the following result.
Lemma 1 (Ahn et al. [1]) Given a convex body C
and a parameter ε ∈ (0, 1), we can compute in
O(ε−1/2 TC ) time an ε-kernel of C with O(ε−1/2 ) vertices.
Lemma 2 Let Cε be an ε-kernel for C. If ϕ is an
invertible affine mapping, then ϕ(Cε ) is an ε-kernel
for ϕ(C).
This is an extended abstract of a presentation given at EuroCG 2014. It has been made public for the benefit of the community and should be considered
a preprint rather than a formally reviewed paper. Thus, this work is expected to appear in a conference with formal proceedings and/or in a journal.
30th European Workshop on Computational Geometry, 2014
(1 − dε, 1 − dε)
(−1, 1)
(1, 1)
(1 − dε, 1 − dε)
(1, 1)
h
2
2 − 2dε
`
We parameterize the set of parallelograms in the
plane by points in R6 , as follows. We identify each 6dimensional point (x1 , x2 , u1 , u2 , v1 , v2 ) with the triple
(x, u, v) ∈ (R2 )3 , where x = (x1 , x2 ), u = (u1 , u2 ),
and v = (v1 , v2 ). The triple (x, u, v) ∈ R6 corresponds
to the parallelogram ♦(x, u, v) with vertices
`
x, x + u, x + v, x + u + v.
h
Figure 1: Proof of Lemma 3.
Proof. The ratio of directional widths for convex
bodies is invariant under invertible affine transformations. This means that
∀u ∈ U : 1 − ε ≤
dwidth(u, ϕ(Cε ))
dwidth(u, Cε )
=
dwidth(u, C)
dwidth(u, ϕ(C))
and thus ϕ(Cε ) is an ε-kernel for ϕ(C).
Proof. Assume, for the sake of contradiction, that S
is not contained in Cε . This means that one vertex
of S is not contained in Cε . Because of symmetry, we
can assume that s = (1 − dε, 1 − dε) is not contained
in Cε . Since Cε is convex and s ∈
/ Cε , there exists
a closed halfplane h that contains Cε but does not
contain s. Let ` be the boundary of h.
We next argue that [−1, 1]2 has some vertex at distance at least dε from h (and thus `); see Figure 1 for
a couple of cases. If ` has negative slope and h is its
lower halfplane, then the distance from (1, 1) to ` is
at least dε. If ` has negative slope and h is its upper
halfplane, then the distance from (−1, −1) to ` is at
least 2 − dε. If ` has positive slope, then (−1, 1) or
(1, −1) are at distance at least dε from h.
Since [−1, 1]2 ⊆ C, for the direction u of ` we have
dwidth(u, C) − dwidth(u, Cε ) > dε ≥ ε · dwidth(u, C),
that
3
Since P is convex, a parallelogram is contained in P
if and only if each vertex of the parallelogram is in P .
Therefore Π(P ) is
\
{(x, u, v) ∈ R6 | x, x + u, x + v, x + u + v ∈ hi }.
i
Since Π(P ) is trivially bounded, it follows that Π(P )
is a convex polytope in R6 defined by 4n linear constraints. The Upper Bound Theorem [9] implies that
Π(P ) has combinatorial complexity at most O(n3 ).
Furthermore, a triangulation of Π(P ) can be computed in O(n3 ) time: Chazelle’s algorithm [3] gives a
triangulation of the boundary of Π(P ), which can be
easily extended to a triangulation of Π(P ).
The set of rectangles is obtained by restricting our
attention to triples (x, u, v) with hu, vi = 0, where
h·, ·i = 0 denotes the scalar product of two vectors.
This constraint is non-linear. Because of this, it is
more convenient to treat each simplex of a triangulation of Π(P ) separately. When hu, vi = 0, the area of
♦(x, u, v) is |u| · |v|.
Consider any simplex 4 of the triangulation of
Π(P ). Finding the maximum area rectangle restricted
to 4 corresponds to the problem
opt(4) = max |u|2 · |v|2
s.t. (x, u, v) ∈ 4
hu, vi = 0
(1 − ε) · dwidth(u, C) > dwidth(u, Cε ),
which contradicts that Cε is an ε-kernel for C.
Π(P ) = {(x, u, v) ∈ R6 | ♦(x, u, v) ⊆ P }.
Lemma 3 Assume that C contains the square
[−1, 1]2 , that C has diameter d, and that Cε is an
ε-kernel for C. Then Cε contains the axis-parallel
square S = [−1 + dε, 1 − dε]2 .
where we have used the assumption
dwidth(u, C) ≤ d. This means that
Thus, x describes a vertex of the parallelogram
♦(x, u, v), while u and v are vectors describing the
edges of ♦(x, u, v). This correspondence is not bijective. Nevertheless, each parallelogram is ♦(x, u, v) for
some (x, u, v) ∈ R6 : the parallelogram given by the
vertices p1 p2 p3 p4 in clockwise (or counterclockwise)
order is ♦(p1 , p2 − p1 , p4 − p1 ).
We are interested in the parallelograms contained
in P . To this end we define
Exact algorithms
Let e1 , . . . , en be the edges of the convex polygon P .
For each edge ei of P , let hi be the closed halfplane defined by the line supportingTei that contains P . Since
P is convex, we have P = i hi .
This is a constant-size problem. It has 6 variables and
a constant number of constraints; all constraints but
one are linear. The optimization function has degree
four. In any case, each such problem can be solved in
constant time. When the problem is not feasible, we
set opt(4) = 0.
Taking the best rectangle over all simplices of a
triangulation of Π(P ), we find a maximum area rectangle. Thus, we return arg max4 opt(4). We have
shown the following.
EuroCG 2014, Ein-Gedi, Israel, March 3–5, 2014
Theorem 4 Let P be a convex polygon with n vertices. In time O(n3 ) we can find a maximum-area
rectangle contained in P .
Lemma 7 Let Cε be an ε-kernel for C. Then Cε
contains a rectangle with area at least (1 − 64ε) ·
area(Ropt ).
To maximize the perimeter, we apply the same approach. For each simplex 4 in a triangulation of Π(P )
we have to solve the following problem:
Proof. Because of Lemma 2, ϕ(Cε ) is an ε-kernel
for ϕ(C). Since ϕ(C) contains [−1, 1]2 and has diameter at most 32 due to Lemma 6, Lemma 3 implies that ϕ(Cε ) contains the square S = [−t, t]2 ,
where t = 1 − 32ε.
Since S is obtained by scaling [−1, 1]2 = ϕ(Ropt )
by 1 − 32ε, its preimage R = ϕ−1 (S) is obtained by
scaling Ropt by 1 − 32ε about its center. It follows
that R is a rectangle with area
opt(4) = max |u| + |v|
s.t. (x, u, v) ∈ 4
hu, vi = 0
Combining the solutions over all simplices of the triangulation we obtain the following.
Theorem 5 Let P be a convex polygon with n
vertices. In time O(n3 ) we can find a maximumperimeter rectangle contained in P .
4
Approximation Algorithm to Maximize the Area
The algorithm is very simple: we compute an (ε/64)kernel Cε/64 for the input convex body C, compute
a maximum-area rectangle contained in Cε/64 and return it. We next show that this algorithm indeed
returns a (1 − ε)-approximation.
Let Ropt be a maximum-area rectangle contained
in C, and let ϕ be an affine transformation such that
ϕ(Ropt ) is the square [−1, 1]2 .
Lemma 6 The diameter of ϕ(C) is at most 32.
Proof. We will show that ϕ(C) is contained in the
disk centered at (0, 0) of radius 16, which implies the
result.
Each convex body contains a rectangle with at
least one half of its area; see [8].
Therefore
area(Ropt )/ area(C) ≥ 1/2.
Any invertible affine transformation does not
change the ratio between areas of objects. Therefore
area(Ropt )
area(ϕ(Ropt ))
4
1
≤
=
=
2
area(C)
area(ϕ(C))
area(ϕ(C))
and thus area(ϕ(C)) ≤ 8.
Assume, for the sake of reaching a contradiction,
that ϕ(C) has a point p = (px , py ) at distance larger
than 16 from (0, 0). Because of symmetry, we can
assume that p lies in the cone defined by y ≤ x
and y ≥ −x. Then the triangle defined by vertices
(−1, −1), (−1, 1) and p is contained in ϕ(C) (by convexity of ϕ(C)) and has area
√
1
· 2 · (px + 1) ≥ 16/ 2 > 8,
2
so we get a contradiction. It follows that ϕ(C) is
contained in a disk centered at (0, 0) of radius 16. area(R) = (1 − 32ε)2 · area(Ropt )
≥ (1 − 64ε) · area(Ropt ),
and the lemma follows.
Combining Lemma 7, the construction of an (ε/64)kernel Cε/64 of C from Lemma 1, and the exact algorithm of Theorem 4 applied to Cε/64 , we obtain the
following
Theorem 8 Let C be a convex body in the plane.
For any given ε ∈ (0, 1), we can find a (1 − ε)approximation to the maximum-area rectangle contained in C in time O(ε−1/2 TC + ε−3/2 ).
Corollary 9 Let C be a convex polygon with n vertices given as a sorted array or a balanced binary
search tree. For any given ε ∈ (0, 1), we can find a
(1−ε)-approximation to the maximum-area rectangle
contained in C in time O(ε−1/2 log n + ε−3/2 ).
Proof. In this case TC = O(log n).
5
Approximation Algorithm to Maximize the
Perimeter
The approximation algorithm is the following: we
compute an (ε2 /8)-kernel Cε2 /8 for the input convex body C, compute a maximum-perimeter rectangle
Rε2 /8 contained in Cε2 /8 , and return it. We next show
that this indeed computes a (1 − ε)-approximation.
Let Ropt be a maximum-perimeter rectangle contained in C, and let a ≥ b be the side lengths of
Ropt . We distinguish two cases depending on the aspect ratio b/a ≤ 1 of Ropt . When b/a ≤ ε, then the
longest segment contained in C is a good approximation to Ropt . When b/a > ε, then Ropt is fat enough
that we can use a method similar to the one employed
for the area. We next proceed to the details.
Lemma 10 If b/a ≤ ε, then peri(Rε2 /8 ) ≥ (1 − ε) ·
peri(Ropt ).
30th European Workshop on Computational Geometry, 2014
Proof. For the direction u of the line supporting a
long edge of Ropt we have
peri(Rε2 /8 ) ≥ 2 dwidth(u, Cε2 /8 )
≥ 2(1 − ε2 /8) dwidth(u, C)
Corollary 14 Let C be a convex polygon with n vertices given as a sorted array or a balanced binary
search tree. For any given ε ∈ (0, 1), we can find
a (1 − ε)-approximation to the maximum-perimeter
rectangle contained in C in time O(ε−1 log n + ε−3 ).
≥ 2(1 − ε2 )a.
Using b ≤ εa, we thus have
peri(Rε2 /8 )
2(1 − ε2 )a
2(1 − ε2 )a
≥
≥
peri(Ropt )
2a + 2b
2a + 2εa
=
proving the lemma.
Theorem 13 Let C be a convex body in the plane.
For any given ε ∈ (0, 1), we can find a (1 − ε)approximation to the maximum-perimeter rectangle
contained in C in time O(ε−1 TC + ε−3 ).
1 − ε2
= 1 − ε,
1+ε
Proof. In this case TC = O(log n).
We now consider the case when b/a > ε. Let ϕ
be the affine transformation such that ϕ(Ropt ) is the
square [−1, 1]2 .
Lemma 11 If b/a > ε, then ϕ(C) has diameter at
most 8/ε.
Proof. Let D be the disk of radius 2a centered at
the center of Ropt . We have C ⊂ D, as otherwise C contains a segment of perimeter strictly larger
than 4a ≥ 2a + 2b = peri(Ropt ), contradicting the
optimality of Ropt .
The transformation ϕ has the following property:
for a segment s parallel to the sides of Ropt of
length x ∈ {a, b} we have len(ϕ(s)) = 2 len(s)/x.
It follows that ϕ(D) is an ellipse of aspect ratio
a/b ≤ 1/ε whose axes are parallel to the coordinate
axes. The diameter of D parallel to the sides of Ropt
of length a becomes, under ϕ, the smaller axis of ϕ(D)
and has length 8. Therefore the larger axis of ϕ(D)
has length at most 8a/b ≤ 8/ε. Since ϕ(C) ⊆ ϕ(D),
the result follows.
Lemma 12 If b/a > ε, then peri(Rε2 /8 ) ≥ (1 − ε) ·
peri(Ropt ).
Proof. Because of Lemma 2, ϕ(Cε2 /8 ) is an (ε2 /8)kernel for ϕ(C). Since ϕ(C) contains [−1, 1]2 and has
diameter at most 8/ε due to Lemma 11, Lemma 3
implies that ϕ(Cε2 /8 ) contains the square S = [−t, t]s ,
where
8 ε2
t=1− ·
= 1 − ε.
ε 8
Since S is obtained by scaling the square [−1, 1]2 by
1−ε, the rectangle R obtained by scaling Ropt by 1−ε
about its center is contained in Cε2 /8 . The rectangle R
has sides (1 − ε)a and (1 − ε)b, and so its perimeter
is 2(1 − ε)(a + b) = (1 − ε) peri(Ropt ), and the result
follows.
Combining Lemmas 10 and 12, the construction of
an (ε2 /8)-kernel Cε2 /8 of C from Lemma 1, and the
exact algorithm of Theorem 5 applied to Cε2 /8 , we
obtain the following
References
[1] H.-K. Ahn, P. Braß, O. Cheong, H.-S. Na, C.-S.
Shin, and A. Vigneron. Inscribing an axially symmetric polygon and other approximation algorithms
for planar convex sets. Comput. Geom., 33(3):152–
164, 2006.
[2] H. Alt, D. Hsu, and J. Snoeyink.
Computing
the largest inscribed isothetic rectangle. In Proc.
CCCG’95, pages 67–72, 1995.
[3] B. Chazelle. An optimal convex hull algorithm in any
fixed dimension. Discrete & Computational Geometry, 10:377–409, 1993.
[4] B. Chazelle and D. P. Dobkin. Intersection of convex objects in two and three dimensions. J. ACM,
34(1):1–27, 1987.
[5] K. Daniels, V. Milenkovic, and D. Roth. Finding
the largest area axis-parallel rectangle in a polygon.
Computational Geometry, 7(12):125–148, 1997.
[6] O. A. Hall-Holt, M. J. Katz, P. Kumar, J. S. B.
Mitchell, and A. Sityon. Finding large sticks and
potatoes in polygons. In Proc. SODA’06, pages 474–
483, 2006.
[7] C. Knauer, L. Schlipf, J. M. Schmidt, and H. R. Tiwary. Largest inscribed rectangles in convex polygons. J. Discrete Algorithms, 13:78–85, 2012.
[8] M. Lassak. Approximation of convex bodies by rectangles. Geometriae Dedicata, 47(1):111–117, 1993.
[9] P. McMullen. The maximum numbers of faces of a
convex polytope. Mathematika, 17:179–184, 1971.
[10] M. Reichling. On the detection of a common intersection of k convex polyhedra. In Computational Geometry and its Applications, volume 333 of LNCS, pages
180–186. Springer Berlin Heidelberg, 1988.