0% found this document useful (0 votes)
7 views53 pages

Polygons

The document provides an extensive overview of polygons, including their definitions, properties, and various computational algorithms related to point inclusion, intersection, clipping, and polygonization. It discusses different types of polygons such as simple, convex, concave, and star polygons, along with methods for filling and clipping polygons. Additionally, it covers the computation of convex hulls and the formation of monotone polygons, emphasizing the algorithms' complexities and practical applications.

Uploaded by

kohdohdohdddd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
7 views53 pages

Polygons

The document provides an extensive overview of polygons, including their definitions, properties, and various computational algorithms related to point inclusion, intersection, clipping, and polygonization. It discusses different types of polygons such as simple, convex, concave, and star polygons, along with methods for filling and clipping polygons. Additionally, it covers the computation of convex hulls and the formation of monotone polygons, emphasizing the algorithms' complexities and practical applications.

Uploaded by

kohdohdohdddd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 53

Polygons

Jayanta Mukhopadhyay

Department of Computer Science & Engineering


Indian Institute of Technology Kharagpur
jay@cse.iitkgp.ac.in

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 1 / 53


Outline

Definitions and Representation.

Categories and properties.

Point inclusion and filling.

Intersection and clipping.

Polygonization and decomposition.

Polygonal mesh and triangulation.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 2 / 53


Definition and representation of a polygon
A polygon or n-gon is a sequence of points in R 2 (R 2 ), p1 , . . . pn such
that pi and pi+1 are connected by a line segment for 1 ≤ i ≤ (n − 1),
and pn is connected to p0 by a line segment.
p2

p5 p3

p4

p1

A n-gon is also a graph G(V , E ) with |V | = |E | = n.


A point is its vertex and a line segment forms an edge between two
vertices.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 3 / 53
Simple polygon
A polygon is simple if except at vertices two line segments do not
meet, and at every vertex there are exactly two edges.
p2
p3

p4
p5 p1
A simple polygon is a planar polygon if the vertices lie on a plane.
A 2-D simple polygon is always a planar polygon.
A planar polygon partitions the plane in two regions, namely, its
interior and exterior.
Euler’s theorem; |V | − |E | + |F | = 2 ⇒ |F | = 2..
The sequence of vertices are described in such an order, so that the
interior of the polygon lies at the left half plane of the direction of
traversal (on an edge).
The reverse order of sequence of vertices denote the exterior region.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 4 / 53
Concave and convex polygons
Convex polygon: A simple polygon for which a line segment between any
arbitrary two points within its interior including boundary edges completely
lie within the polygon.

Concave polygon: A non-convex simple polygon.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 5 / 53


Concave and convex polygons: Properties
Reflex vertex: A vertex is reflex if the internal angle > 180o .
A concave polygon has at least one reflex vertex, whereas a convex
polygon has no reflex vertex.

Traversal of a convex polygon is always counter-clockwise.


Three consecutive vertices forming a reflex angle in clockwise order.
Three consecutive vertices forming a non-reflex angle in
counter-clockwise order.
A triangle or a 3-gon is always convex.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 6 / 53
Test for a reflex angle
Problem statement: Given a sequence of vertices vi−1 , vi , and vi+1 , test
whether vi is reflex.

Figure: The interior lies at the left side of the traversal.


Compute the internal angle θ formed at vi .
If θ > 180o , the vertex is reflex.
Requires floating point computation for computing angle.
The algorithm with integer operations:
x1 y1 1
Compute twice the area of the triangle: A = x2 y2 1
x3 y3 1
If A < 0, the vertex is reflex.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 7 / 53
Point inclusion
Problem statement: Given a polygon P and a query point q, determine
whether q ∈ P.
To decide whether q lies in interior of P or not.
Use line intersection property.
Form a horizontal line segment from any exterior point towards left to
q and compute the number of intersections.

Degenerate case: Count once or twice at an odd or even vertex


intersection V. If adjacent vertices of V in the same half plane it is
even, else odd.
If the number of intersections is odd, q ∈ P.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 8 / 53
Test for intersection

Problem statement: Given a reference line segment between v1 = (x1 , y1 )


and v2 = (x2 , y2 ) and a query line segment p = (xp , yp ) and q = (xq , yq ),
test whether they intersect.

Compute the intersecting points of two straight lines v1 v2 and pq.

Check whether the intersecting point lies on both the line segments.

If the above is TRUE, the intersection is TRUE.

Else it is FALSE.
Needs floating point operation.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 9 / 53


Test for intersection
Problem statement: Given a reference line segment between v1 = (x1 , y1 )
and v2 = (x2 , y2 ) and a query line segment p = (xp , yp ) and q = (xq , yq ),
test whether they intersect.

Signs: +ve: in the right-half plane, and -ve: in the left-half plane.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 10 / 53


The Algorithm: Test for intersection
Problem statement: Given a reference line segment between v1 = (x1 , y1 )
and v2 = (x2 , y2 ) and a query line segment p = (xp , yp ) and q = (xq , yq ),
test whether they intersect.

The Algorithm with integer operations:

Determine signs of determinants of v1 pv2 , and v1 qv2 .


If they are of opposite signs,
Determine signs of determinants of pv1 q, and pv2 q.
If they are opposite, the intersection is TRUE.
Else the intersection is FALSE

Else the intersection is FALSE.

The above computation gets simplified if the intersection check is with a


horizontal or a vertical line segment. Why?
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 11 / 53
Polygon filling

Problem statement: Given a polygon P fill the interior of the polygon.


By vertically scanning from top to bottom and drawing horizontal line
segments within it.
Use line intersection property: Draw line segment between odd and even
intersecting points.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 12 / 53


The Algorithm for Polygon filling

For each y -coordinate within the vertical range from the topmost vertex to
the bottommost vertex do the following.

Compute intersections of edges with the horizontal line.

Sort the intersections in ascending order according to their


x-coordinates.

Degenerate case: Duplicate a vertex in the sorted order at an even


vertex intersection.

Draw line segments between each pair of odd and even intersections.
Time complexity: O((ymax − ymin ).nlog(n)) for an n-gon.
Can you improve it for a convex polygon?

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 13 / 53


Computing intersection of two line segments

Problem statement: Given an intersecting pair of line segments


L1 ≡ ((x1 , y1 ), (x2 , y2 )) and L2 ≡ ((x3 , y3 ), (x4 , y4 )), compute their
intersecting points q ≡ (x , y ).

Requires floating point computation.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 14 / 53


Integer computation of intersection of two line segments
Problem statement: Given an intersecting pair of line segments
L1 ≡ ((x1 , y1 ), (x2 , y2 )) and L2 ≡ ((x3 , y3 ), (x4 , y4 )), compute their
intersecting points q ≡ (x , y ).

Check the half-plane to which the midpoint of L2 belongs to.

Make the midpoint as the endpoint of L2 by keeping the other end


point on the opposite half plane.
Iterate above steps till the convergence.
Division by 2 done through a right shift operation.
Simple to compute with a horizontal or a vertical line. Why?
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 15 / 53
Intersection of a straight line and a simple polygon

Problem statement: Given a simple polygon P, and an infinite straight line


defined by a line segment p1 p2 , where p1 ≡ (x1 , y1 ) and p2 ≡ (x2 , y2 ),
compute the intersection of P with the LHP of the straight line.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 16 / 53


Intersection of a straight line and a simple polygon

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 17 / 53


An example

O(n) for n-gon.


Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 18 / 53
Polygon clipping
Problem statement: Given a simple polygon P, and an isothetic or
axis-parallel rectangle R defined by (p0 , p2 ), where p0 ≡ (xmin , ymin ) and
p2 ≡ (xmax , ymax ) are the leftmost-bottommost and the
rightmost-topmost corner points, compute the intersection of P with R.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 19 / 53


Polygon clipping: Algorithm

Compute intersection of P with the straight line defined by p0 p1 . Let


the resulting polygon be P1 .
Compute intersection of P1 with the straight line defined by p1 p2 .
Let the resulting polygon be P2 .
Compute intersection of P2 with the straight line defined by p2 p3 .
Let the resulting polygon be P3 .
Compute intersection of P3 with the straight line defined by p3 p0 .
Let the resulting polygon be P4 , which is the clipped polygon.
O(n) for n-gon.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 20 / 53


Polygon clipping: An Example

1. Clipping with the bottom horizontal line

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 21 / 53


Polygon clipping: An Example

2. Clipping with the right vertical line

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 22 / 53


Polygon clipping: An Example

3. Clipping with the upper horizontal line

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 23 / 53


Polygon clipping: An Example

4. Clipping with the left vertical line

Output polygon: s1 p1 s2 v3 v4 s3 p2 s4 v7 v8

Will it work for an intersection with a convex polygon?

O(mn) for intersection of a convex m-gon with any arbitrary n-gon.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 24 / 53


Star polygon
There exists a point in the interior from which all the vertices are visible.

Kernel:The set of such points. A convex polygon also a star polygon.

Vertices angularly sorted.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 25 / 53


Point inclusion in a Star polygon
Problem statement: Given a star polygon P and a query point q,
determine whether q ∈ P.
As vertices angularly sorted, find the single edge angular sector with
the edge containing the point using binary search .

If the point lies in the LHP of the edge, q ∈ P, else the point outside
the polygon. O(log(n))
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 26 / 53
Point inclusion in an angular sector

Problem statement: Given an angular sector ∠doe where d and e are


points in counter-clockwise order about o, and a query point q to decide
q ∈ ∠doe.

If odq in counter-clockwise and oeq in clockwise order, q ∈ ∠doe.

Narrow down the angular sector containing q from a wide angular sector of
a polygon using the above rule.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 27 / 53


Monotone polygon
Monotone chain: A sequence of points form a monotone chain with
respect to a line L, if their projections on it preserve the same order.

Monotone polygon: Consists of two monotone chains.

A convex polygon too monotone!


Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 28 / 53
Exploiting intersection property of monotone polygon
At most two intersections with horizontal lines for Y-monotone.
Point inclusion problem:

Polygon filling:

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 29 / 53


Polygonization

Problem statement: Given a set of 2-D points V form a simple polygon P


so that all the points in the set become its vertices.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 30 / 53


Star Polygon Formation
Problem statement: Given a set of 2-D points V form a star polygon P so
that all the points in the set become its vertices.
Compute the centroid of V .

Angularly and radially sort the vertices about the centroid to get the
star polygon.

O(nlog(n))
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 31 / 53
y-Monotone Polygon Formation
Problem statement: Given a set of 2-D points V form a y-monotone
polygon P so that all the points in the set become its vertices.
Compute the top=most and bottom-most points vt ∈ V and vb ∈ V .

Create two lists of points L and R, where L and R contains the points
in the RHP and the LFP of vb vt .
Sort L and R in descending and ascending orders of y − coordinates.
Merge these two sorted lists to form the y -monotone polygon.

O(nlog(n))
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 32 / 53
Convex hull of a set of 2-D points

Convex hull (CH): The minimum area convex polygon enclosing the set of
points.

Properties
The vertices of the CH are from the set of 2-D points.
Extreme points (left,right,top and bottom) are vertices of the CH.
The centroid of the point set lies within the CH.
Degenerate case: If all the points are collinear, the CH is a line
segment with its two extreme points.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 33 / 53


Computation of Convex Hull
Problem statement: Given a set of 2-D points V compute its convex hull.

Computing for a simple polygon.


Start from an extreme vertex. Assured to be a vertex of the CH.
Do the following at every vertex in the sequence till the end.
Look ahead the next vertex whether it is reflex.
If reflex, remove it and go back to the previous vertex.
Else go to the next vertex.
No backtracking at the start vertex.

O(n) Mostly works!


Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 34 / 53
A failure case!
A simple polygon with a mouth: With a non-monotone chain of reflex
vertices.

Removal of a reflex vertex turns polygon non-simple.

The convex hull algorithm works for any star or monotone polygon.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 35 / 53
Computation of Convex Hull of a set of 2-D points
Problem statement: Given a set of 2-D points V compute its convex hull.
Graham’s scan (1972)
Form a star polygon Pstar from V .
Apply the algorithm for computing the CH of Pstar .

Andrew’s modification (1979)


Form a y-monotone polygon Pym from V .
Apply the algorithm for computing the CH of Pym .

O(n.log(n))
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 36 / 53
Polygon triangulation
Problem statement: Given a simple polygon P, decompose it into a set of
non-overlapping triangles, whose vertices are from the set of vertices of P.

Every simple polygon admits a triangulation.


A triangulation of an n-gon has exactly n − 2 triangles.
Triangulation of a simple polygon may not be unique.
Triangulation of a triangle is unique and trivial.
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 37 / 53
A diagonal or chord of a simple polygon
A diagonal or chord: A line segment formed by any pair of vertices of a SP
lying totally in its interior except its two end points (vertices lying on the
boundary).

v0 v6 is a diagonal, but v1 v5 is NOT a diagonal.


Number of diagonals (|D|) for a triangulation of n-gon:
|V | = n, |E | = n + |D|, and |F | = (n − 2) + 1 (Triangles + Exterior)
From Euler’s theorem:
|V | − |E | + |F | = 2 ⇒ n − (n + |D|) + (n − 1) = 2 ⇒ |D| = n − 3.
Edges of a SP are not diagonals!
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 38 / 53
Triangulation of a simple polygon: Algorithm

Input: A n-gon P ≡ v0 v1 . . . vn−1 . Without the loss of generality let us


assume v0 is the leftmost vertex, hence it is a convex vertex.
Output: A set of non-overlapping triangles.

Consider the triangle △v0 v1 vn−1 formed by the adjacent vertices of


v0 .
If the triangle does not contain any vertex of P, output △v0 v1 vn−1
and perform triangulation of the remaining part P ′ ≡ v2 v3 . . . vn−2
recursively.
Else
Find the vertex vi of P closest to v0 , qnd form the diagonal v0 vi .
Split the polygons in two parts P1 ≡ v0 v1 . . . vi and
P2 ≡ v0 vi vi+1 . . . vn−1 .
Perform triangulation of P1 and P2 , recursively.

Time complexity: O(n2 )

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 39 / 53


Triangulation of a simple polygon: An Example

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 40 / 53


An Example (contd.)

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 41 / 53


Triangulation of a convex polygon: Algorithm
Input: A convex n-gon P ≡ v0 v1 . . . vn−1 .
Output: A set of non-overlapping triangles.
Overview: Choose any arbitrary vertex and form diagonals with every non
adjacent vertex to obtain the triangulation.

Without the loss of generality let us assume v0 is the chosen vertex.


Output △v0 v1 v2 , △v0 v2 v3 . . . △v0 vi vi+1 . . . △v0 vn−2 vn−1 .

Time complexity: O(n)


A monotone polygon also can be triangulated in O(n).
Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 42 / 53
Triangulation of a point set

Problem statement: Given a set n 2-D points V in the plane join them by
non-intersecting straight line segments so that every region internal to the
convex hull CH(V ).

No unique solution.
O(n) number of triangulation.
3-D point set lying on a surface triangulated in 2-D though projection
and inverse projection. Useful for polygonal mesh representation.
Can you get lower and upper bounds on the number of triangles?

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 43 / 53


Triangulation of a point set: A greedy algorithm

Overview: Build a graph incrementally adding edges or line segments


between a pair of points so that no newly added edge intersects any of the
prevailing edges or line segments of the graph. Continue till all possible
pairs of points are considered.

Time complexity: O(n3 )

Greedy choice: Choose edges in ascending order of their lengths.

Preprocessing task: Sort the edges in O(n2 log(n)).

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 44 / 53


Greedy Triangulation of a point set: An example

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 45 / 53


Triangulation of a point set via polygonization

Overview:
Form a simple polygon from the point set.
Triangulate the simple polygon.
Compute the convex hull.
Triangulate polygons enclosed by an edge of the convex hull and a
chain of edges of the simple polygon in its exterior.

Time complexity: O(nlog(n))

Polygon formation: Form a x-monotone or a star polygon.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 46 / 53


Triangulation of a point set via polygonization: An example

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 47 / 53


Delaunay Triangulation of a point set
Definition: A triangulation such that the circumcircle of each triangle does
not contain any other point.

Mostly unique!

Degenerate cases: Four vertices of edge adjacent triangles are co-circular.

Both the above admissible!

Optimal Time complexity: O(nlog(n))


Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 48 / 53
Delaunay Triangulation of a point set: A greedy approach

Obtain an initial triangulation.


Check the delaunay condition of every edge, common to two adjacent
triangles say for △ABC and △BDC , with the common edge BC .

If the condition fails flip the edge by choosing the other diagonal of
the quadrilateral ABDC , to replace the pair by △ABD and △DAC .

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 49 / 53


Delaunay Triangulation of a point set: A greedy approach

△ABC and △BDC replaced by △ABD and △DAC

If all the edges are delaunay, the triangulation is Delaunay.

No edge rechecked.

No removed edge reappears!

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 50 / 53


Delaunay Triangulation: a greedy algorithm

The Lawson’s Algorithm:


Let Γ be any triangulation of the point set.
Determine all non-delaunay edges of Γ and put them in a queue Q.
While {Q empty }
Take an edge e from Q. Let e = BC , and △ABC and △BDC be
the two incident triangles with e.
Flip e.
Check AB, AC , DB, and DC have become non-delaunay. If anyone
of them has become so, enqueue it.
End

O(n2 )

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 51 / 53


Test for encircling

D < 0 → D(x4 , y4 ) inside.


D = 0 → D(x4 , y4 ) on the circumcircle.
D > 0 → D(x4 , y4 ) outside.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 52 / 53


Summary

A simple polygon is a closed polygonal curve without self-intersection.


Various computational problems discussed.
Point inclusion, filling, intersection, clipping, convex hull formation and
triangulation.
Discussion extended for point set for computing convex hull and
triangulation.
Efficient computation possible for certain categories of SP exploiting
their properties, such as for convex, star and monotone polygons.
All these algorithms are also applicable for vector graphics.

Jayanta Mukhopadhyay (CSE, IIT Kharagpur) Polygons 53 / 53

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy