Elsevier

Computers & Graphics

Volume 23, Issue 3, 1 June 1999, Pages 353-363
Computers & Graphics

Technical Section
A universal trapezoidation algorithm for planar polygons

https://doi.org/10.1016/S0097-8493(99)00044-8Get rights and content

Abstract

A new algorithm for decomposing non-monotone planar polygons, which may contain holes, into trapezoids is described. The holes may be nested and may have common edges. In the first part of the paper, the main idea is explained for non-monotone polygons without holes, and the algorithm is then extended to polygons containing holes; the holes can also be decomposed into trapezoids, if desired. Finally, it is shown that the algorithm performs trapezoidation of general polygons in O(n2log2n) time, where n is the common number of polygon vertices.

Introduction

Techniques for decomposing complex geometric shapes into simpler components are of great importance in computational geometry and its applications. Depending upon the particular problem, there are different ideas about how this should be performed and the choice of element into which the shape should be decomposed. For example, planar polygons can be decomposed into triangles, trapezoids, or even star-shaped polygons [1].

While triangulation is, without doubt, the most popular and the most investigated technique, splitting a complex polygon into trapezoids is an alternative, and a generalised method for performing trapezoidation on an arbitrary polygon with any number of holes, nested to any level, is considered in the paper.

The motivation for the current work arose from the display of land use within a given geographical area. The available software could colour triangles or trapezoids to display different uses but was more efficient with trapezoids because of the reduced number of primitives involved. The individual areas to be displayed could be nested, and their boundaries could coincide with each other or the boundary of the overall area. However, there is no reason why the application should not be used more broadly, particularly to display planar variation of physical quantities. It can also be applied to find, efficiently, the intersection and/or union of polygons.

Trapezoidation was first considered by Chazelle and Incerpi [2] and Fournier and Montuno [3]. A randomised algorithm for trapezoidation was later suggested by Seidel [4] as the key for triangulation and this was recently used by Narkhede and Manocha [5] for the same purpose. However, none of these authors considered general planar polygons containing holes; indeed, to the authors’ knowledge, no previously published method for trapezoidation has successfully addressed polygons with holes, nor the trapezoidation within holes.

A trapezoid is a four-sided polygon in which two of the edges are parallel. Note that a triangle can be considered as a degenerate trapezoid in which one of the parallel edges has zero length; hence, some triangles might result from applying any trapezoidation algorithm.

A horizontal trapezoidation of an n-sided polygon involves drawing horizontal lines (we shall call them scan lines) through every vertex of the polygon (see Fig. 1). The whole operation can be completed in O(nlog2n) time if the polygon is monotone [4] – in the context of horizontal trapezoidation, a monotone polygon is one in which the boundary consists of two vertically monotone chains.

In practice, polygons are frequently non-monotone and may enclose a number of holes. This paper describes a universal algorithm to perform the trapezoidation of a non-monotone planar polygon containing holes. In the first part of the paper, the main idea of the algorithm is explained for non-monotone polygons without holes. In the following section, the algorithm is extended to polygons containing holes; the holes can themselves be trapezoided by the algorithm, if required. A straightforward application of the algorithm results in more trapezoids than strictly necessary, and Section 4 indicates how this number can be reduced. Section 5 provides suggestions for an efficient implementation, Section 6 contains an estimation of the time complexity of the algorithm, and Section 7 describes tests made with both artificially constructed polygons and real data from the geographical application.

Section snippets

Polygons without holes

The algorithm uses the well-known greedy approach [6], [7]. In the first step, the algorithm prepares the input data such that in the second step the problem can be solved in one pass. Adopting vocabulary from topology [8], the sequence of vertices forming the border of a polygon is named a loop, and a sequence of vertices forming the border of an inner closed polygonal region is called a ring.

Initially, the polygon vertices are sorted by y-coordinate. A “plane sweep” is employed, which is a

Polygons with holes

This section considers the generalisation of the trapezoidation algorithm for all planar polygons which do not self-intersect. For simplicity, we deal initially with a situation in which the loop and all rings are totally disjoint and all areas within the loop are to be trapezoided, including the interiors of the rings. This is later generalised to allow parts of the rings to coincide with each other and with the loop, and to allow different areas to be omitted from the trapezoidation.

Reducing the number of trapezoids

In general, the algorithm presented generates a greater number of trapezoids than necessary. This is because, in common with all other scan-line algorithms, it works on a line-by-line basis and does not look ahead to identify simplifications. Applications which subsequently use the trapezoidation created (for example, to find the intersection of two planar polygons) will work more efficiently if the number of trapezoids is minimised. This can be achieved by the use of a simple post-processing

Which polygon edges intersect a scan line?

The critical part of the algorithm described in Section 3 is the determination of which polygon edges intersect the current scan line, and this can be performed economically by using appropriate data structures – see Narkhede and Manocha [5]. In our implementation, associated with each vertex in the array SortedVerticesY are two pointers, i1 and i2, to the neighbouring vertices and a flag Used which is initially FALSE and then set to TRUE when the sweep reaches the scan line on which the vertex

Evaluation of the time complexity of the algorithm

We now present an analysis of the time complexity of the algorithm. We consider the worst case throughout; an analysis of an average case is difficult because, while computation time obviously depends upon the physical form of the polygon, it can also be highly dependent upon the orientation of the polygon with respect to the sweep direction. For example, consider the simple E-shape in Fig. 10.

In (a), there are 6 scan lines and 5 trapezoids, but the rotation to case (b) increases these numbers

Tests

A number of tests were run on a Pentium 133 MHz, using Visual C++5.0, to determine the performance of the algorithm, both with artificially constructed data and data from the geographical application.

Table 1, Table 2 show data for two polygons without holes; the first is almost monotone and the second has many concavities. Times are presented for a single run, although because of the short duration, the times were actually measured over 100 runs. The times for the trapezoidation phase are, by

Conclusions

The paper describes an algorithm which decomposes planar polygons into trapezoids. The polygons can be non-monotone and may contain a number of holes, including nested holes. The holes can be trapezoided, if desired.

The algorithm works in three steps: the initial data is prepared, the trapezoids are generated, and the trapezoids produced are optimised. Evaluation of the time complexity shows that the algorithm completes the task in, at worst, O(n2log2n) time.

The classification of the local role

References (9)

  • M Etzion et al.

    On compatible start decompositions of simple polygons

    IEEE Transactions on Visualization and Computer Graphics

    (1997)
  • B Chazelle et al.

    Triangulation and shape complexity

    ACM Transactions on Graphics

    (1984)
  • A Fournier et al.

    Triangulating simple polygons and equivalent problems

    ACM Transactions on Graphics

    (1984)
  • R Seidel

    A simple and fast incremental randomized algorithm for computing trapezoidal decompositions and for triangulating polygons

    Computational GeometryTheory and Applications

    (1991)
There are more references available in the full text version of this article.

Cited by (29)

  • An efficient algorithm for clipping operation based on trapezoidal meshes and sweep-line technique

    2012, Advances in Engineering Software
    Citation Excerpt :

    In this paper we proposed a systematic algorithm for repetitively performing clipping operation on points, arcs, and polygons. It is based on trapezoidal meshes [14,18]. By adopting the sweep-line technique [13], the involved polygons are organized and processed in the form of trapezoidal meshes.

  • 2D point-in-polygon test by classifying edges into layers

    2005, Computers and Graphics (Pergamon)
  • Polygon trapezoidation by sets of open trapezoids

    2003, Computers and Graphics (Pergamon)
  • Construction of a non-symmetric geometric buffer from a set of line segments

    2003, Computers and Geosciences
    Citation Excerpt :

    Note that we do not need to test an intersection of an edge of a BGB with the other edges of the same BGB as they can never intersect. The sweep-line technique is well known and has been successfully applied to many different tasks, for example, filling polygons (Foley et al., 1990), constructing Voronoi diagrams (de Berg et al., 1997), finding intersection points amongst a set of line segments (Preparata and Shamos, 1988), or trapezoiding polygons (Žalik and Clapworthy, 1999). Let us observe an example in Fig. 3.

View all citing articles on Scopus
View full text