introduction to computational...

106
Introduction Area Inclusion Line Hull Art Gallery Introduction to Computational Geometry Arijit Bishnu ([email protected]) (http://www.isical.ac.in/˜arijit) Advanced Computing and Microelectronics Unit Indian Statistical Institute 203, B. T. Road, Kolkata - 700108, West Bengal, India.

Upload: others

Post on 24-Jan-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction to Computational Geometry

Arijit Bishnu([email protected])

(http://www.isical.ac.in/˜arijit)

Advanced Computing and Microelectronics UnitIndian Statistical Institute

203, B. T. Road, Kolkata - 700108, West Bengal, India.

Page 2: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 3: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Computational Geometry (CG) involves study of algorithmsfor solving geometric problems on a computer. The emphasisis more on discrete and combinatorial geometry.

There are many fields of computer science like computergraphics, computer vision and image processing, robotics,computer-aided designing, geographic information systems,etc. that give rise to geometric problems.

In CG, the focus is more on discrete nature of geometricproblems as opposed to continuous issues. Simply put, wewould deal more with straight or flat objects (lines, linesegments, polygons) or simple curved objects as circles, thanwith high degree algebraic curves.

This branch of study is around thirty years old if one assumesMichael Ian Shamos’s thesis [1] as the starting point.

Page 4: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Computational Geometry (CG) involves study of algorithmsfor solving geometric problems on a computer. The emphasisis more on discrete and combinatorial geometry.

There are many fields of computer science like computergraphics, computer vision and image processing, robotics,computer-aided designing, geographic information systems,etc. that give rise to geometric problems.

In CG, the focus is more on discrete nature of geometricproblems as opposed to continuous issues. Simply put, wewould deal more with straight or flat objects (lines, linesegments, polygons) or simple curved objects as circles, thanwith high degree algebraic curves.

This branch of study is around thirty years old if one assumesMichael Ian Shamos’s thesis [1] as the starting point.

Page 5: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Computational Geometry (CG) involves study of algorithmsfor solving geometric problems on a computer. The emphasisis more on discrete and combinatorial geometry.

There are many fields of computer science like computergraphics, computer vision and image processing, robotics,computer-aided designing, geographic information systems,etc. that give rise to geometric problems.

In CG, the focus is more on discrete nature of geometricproblems as opposed to continuous issues. Simply put, wewould deal more with straight or flat objects (lines, linesegments, polygons) or simple curved objects as circles, thanwith high degree algebraic curves.

This branch of study is around thirty years old if one assumesMichael Ian Shamos’s thesis [1] as the starting point.

Page 6: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Computational Geometry (CG) involves study of algorithmsfor solving geometric problems on a computer. The emphasisis more on discrete and combinatorial geometry.

There are many fields of computer science like computergraphics, computer vision and image processing, robotics,computer-aided designing, geographic information systems,etc. that give rise to geometric problems.

In CG, the focus is more on discrete nature of geometricproblems as opposed to continuous issues. Simply put, wewould deal more with straight or flat objects (lines, linesegments, polygons) or simple curved objects as circles, thanwith high degree algebraic curves.

This branch of study is around thirty years old if one assumesMichael Ian Shamos’s thesis [1] as the starting point.

Page 7: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Any problem that is to be solved using a digital computer hasto be discrete in form. It is the same with CG.

For CG to be applied to areas that deal with continuousissues, discrete approximations to continuous curves orsurfaces are needed.

Programming in CG is also a little difficult. Libraries likeLEDA [5] and CGAL [6] are now available.

CG algorithms suffer from the curse of degeneracies. So, wewould make certain assumptions at times like no three pointsare collinear, no four points are cocircular, etc.

Page 8: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Any problem that is to be solved using a digital computer hasto be discrete in form. It is the same with CG.

For CG to be applied to areas that deal with continuousissues, discrete approximations to continuous curves orsurfaces are needed.

Programming in CG is also a little difficult. Libraries likeLEDA [5] and CGAL [6] are now available.

CG algorithms suffer from the curse of degeneracies. So, wewould make certain assumptions at times like no three pointsare collinear, no four points are cocircular, etc.

Page 9: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Any problem that is to be solved using a digital computer hasto be discrete in form. It is the same with CG.

For CG to be applied to areas that deal with continuousissues, discrete approximations to continuous curves orsurfaces are needed.

Programming in CG is also a little difficult. Libraries likeLEDA [5] and CGAL [6] are now available.

CG algorithms suffer from the curse of degeneracies. So, wewould make certain assumptions at times like no three pointsare collinear, no four points are cocircular, etc.

Page 10: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Introduction

Any problem that is to be solved using a digital computer hasto be discrete in form. It is the same with CG.

For CG to be applied to areas that deal with continuousissues, discrete approximations to continuous curves orsurfaces are needed.

Programming in CG is also a little difficult. Libraries likeLEDA [5] and CGAL [6] are now available.

CG algorithms suffer from the curse of degeneracies. So, wewould make certain assumptions at times like no three pointsare collinear, no four points are cocircular, etc.

Page 11: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 12: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation

Problem

Given a simple polygon P of npoints, compute its area.

Area of a convex polygon

Find a point inside P, draw ntriangles and compute the area.

A better idea for convex polygon

We can triangulate P bynon-crossing diagonals into n − 2triangles and then find the area.

A better idea for simple polygon

We can do likewise.

p1

p2pn

pn−1

Page 13: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation

Problem

Given a simple polygon P of npoints, compute its area.

Area of a convex polygon

Find a point inside P, draw ntriangles and compute the area.

A better idea for convex polygon

We can triangulate P bynon-crossing diagonals into n − 2triangles and then find the area.

A better idea for simple polygon

We can do likewise.

Page 14: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation

Problem

Given a simple polygon P of npoints, compute its area.

Area of a convex polygon

Find a point inside P, draw ntriangles and compute the area.

A better idea for convex polygon

We can triangulate P bynon-crossing diagonals into n − 2triangles and then find the area.

A better idea for simple polygon

We can do likewise.

(n− 3) diagonals and (n− 2) triangles

Page 15: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation

Problem

Given a simple polygon P of npoints, compute its area.

Area of a convex polygon

Find a point inside P, draw ntriangles and compute the area.

A better idea for convex polygon

We can triangulate P bynon-crossing diagonals into n − 2triangles and then find the area.

A better idea for simple polygon

We can do likewise.

p1

p2pn

pn−1

(n− 3) diagonals and (n− 2) triangles

Page 16: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation and Polygon Triangulation

Moral of the story

A simple polygon can be triangulated into (n − 2) triangles by(n − 3) non-crossing diagonals.

Proof

The proof is by induction on n.

Time complexity

We can triangulate P by a very complicated O(n) algorithm [7]OR by a more or less simple O(n log n) time algorithm [4].

Page 17: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation and Polygon Triangulation

Moral of the story

A simple polygon can be triangulated into (n − 2) triangles by(n − 3) non-crossing diagonals.

Proof

The proof is by induction on n.

Time complexity

We can triangulate P by a very complicated O(n) algorithm [7]OR by a more or less simple O(n log n) time algorithm [4].

Page 18: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Area Computation and Polygon Triangulation

Moral of the story

A simple polygon can be triangulated into (n − 2) triangles by(n − 3) non-crossing diagonals.

Proof

The proof is by induction on n.

Time complexity

We can triangulate P by a very complicated O(n) algorithm [7]OR by a more or less simple O(n log n) time algorithm [4].

Page 19: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 20: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Point Inclusion

Problem

Given a simple polygon P of npoints, and a query point q, isq ∈ P?

What if P is convex?

Easy in O(n). Takes a little effortto do it in O(log n).

Another idea for convex polygon

Stand at q and look aroundthe polygon.

We can show the sameresult for a simple polygonalso.

Pq

Page 21: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Point Inclusion

Problem

Given a simple polygon P of npoints, and a query point q, isq ∈ P?

What if P is convex?

Easy in O(n). Takes a little effortto do it in O(log n).

Another idea for convex polygon

Stand at q and look aroundthe polygon.

We can show the sameresult for a simple polygonalso.

p1 p2

p3

p4

p5

p6

p7

p8

p9

q q

q is always to the left if q ∈ P , else, it varies.

Page 22: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Point Inclusion

Problem

Given a simple polygon P of npoints, and a query point q, isq ∈ P?

What if P is convex?

Easy in O(n). Takes a little effortto do it in O(log n).

Another idea for convex polygon

Stand at q and look aroundthe polygon.

We can show the sameresult for a simple polygonalso.

p1 p2

p3

p4

p5

p6

p7

p8

p9

q q

Total angular turn aroundq is 2π if q ∈ P, else, 0

Page 23: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Point Inclusion

Another technique: Ray Shooting

Shoot a ray and count thenumber of crossings with edgesof P. If it is odd, then q ∈ P. Ifit is even, then q 6∈ P. Somedegenerate cases need to behandled. Time taken is O(n).

P

q

q

Page 24: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 25: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Line Segment Intersection

Input

A set of line segments L ingeneral position in the plane.|L| = n.

Output

Report the intersections.

Output Sensitive Algorithm

Number of intersections mightvary from 0 to

(n2

)= O(n2). So,

the lower bound of the problem isΩ(n2). The idea is now to lookfor an output sensitive algorithm.

Page 26: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Line Segment Intersection

Input

A set of line segments L ingeneral position in the plane.|L| = n.

Output

Report the intersections.

Output Sensitive Algorithm

Number of intersections mightvary from 0 to

(n2

)= O(n2). So,

the lower bound of the problem isΩ(n2). The idea is now to lookfor an output sensitive algorithm.

Page 27: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Line Segment Intersection

Input

A set of line segments L ingeneral position in the plane.|L| = n.

Output

Report the intersections.

Output Sensitive Algorithm

Number of intersections mightvary from 0 to

(n2

)= O(n2). So,

the lower bound of the problem isΩ(n2). The idea is now to lookfor an output sensitive algorithm.

Page 28: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 29: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 30: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 31: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 32: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 33: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

An Output Sensitive Algorithm

The idea

Avoid testing pairs of segments that arefar apart.

To find such pairs, imagine sweeping ahorizontal line ` downwards from aboveall segments.

Keep track of all segments that intersect`.

` is the sweep line and the algorithmparadigm is plane sweep.

The status of the sweep line is the linesegments intersecting it.

Only at particular points known as eventpoints, the status needs to be updated.

Page 34: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Event Points and the Event Queue

The start and end points of each linesegment. They are static.

The intersection points. They aredynamic and are generated as the sweepline ` sweeps down.

The event points are to be arranged in adata structure in a way in which thesweep line sees them.

The data structure should supportextracting the minimum y -coordinate,insertion and deletion.

A heap or a balanced binary search treecan support these operations in O(log n)time.

Page 35: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Event Points and the Event Queue

The start and end points of each linesegment. They are static.

The intersection points. They aredynamic and are generated as the sweepline ` sweeps down.

The event points are to be arranged in adata structure in a way in which thesweep line sees them.

The data structure should supportextracting the minimum y -coordinate,insertion and deletion.

A heap or a balanced binary search treecan support these operations in O(log n)time.

Page 36: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Event Points and the Event Queue

The start and end points of each linesegment. They are static.

The intersection points. They aredynamic and are generated as the sweepline ` sweeps down.

The event points are to be arranged in adata structure in a way in which thesweep line sees them.

The data structure should supportextracting the minimum y -coordinate,insertion and deletion.

A heap or a balanced binary search treecan support these operations in O(log n)time.

Page 37: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Event Points and the Event Queue

The start and end points of each linesegment. They are static.

The intersection points. They aredynamic and are generated as the sweepline ` sweeps down.

The event points are to be arranged in adata structure in a way in which thesweep line sees them.

The data structure should supportextracting the minimum y -coordinate,insertion and deletion.

A heap or a balanced binary search treecan support these operations in O(log n)time.

Page 38: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Event Points and the Event Queue

The start and end points of each linesegment. They are static.

The intersection points. They aredynamic and are generated as the sweepline ` sweeps down.

The event points are to be arranged in adata structure in a way in which thesweep line sees them.

The data structure should supportextracting the minimum y -coordinate,insertion and deletion.

A heap or a balanced binary search treecan support these operations in O(log n)time.

Page 39: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

We need to store the left to rightorder in which the line segmentsintersect `. This data structure hasto be dynamic.

A line segment might come in(insertion) or go off (deletion) thesweep line. We need to search forits position.

A balanced binary search tree cansupport these operations inO(log n) time.

Page 40: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

We need to store the left to rightorder in which the line segmentsintersect `. This data structure hasto be dynamic.

A line segment might come in(insertion) or go off (deletion) thesweep line. We need to search forits position.

A balanced binary search tree cansupport these operations inO(log n) time.

Page 41: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

We need to store the left to rightorder in which the line segmentsintersect `. This data structure hasto be dynamic.

A line segment might come in(insertion) or go off (deletion) thesweep line. We need to search forits position.

A balanced binary search tree cansupport these operations inO(log n) time.

Page 42: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

The sweep line status changesduring three events: start and endpoints and intersection points andnowhere else.

sk and sl are two segmentsintersecting at a point.

There is an event point above theintersecting point where sk and slare adjacent and are tested forintersection. So, no intersectionpoint is ever missed.

Page 43: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

The sweep line status changesduring three events: start and endpoints and intersection points andnowhere else.

sk and sl are two segmentsintersecting at a point.

There is an event point above theintersecting point where sk and slare adjacent and are tested forintersection. So, no intersectionpoint is ever missed.

Page 44: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Event Points and Sweep Line Status

Sweep Line Status

The sweep line status changesduring three events: start and endpoints and intersection points andnowhere else.

sk and sl are two segmentsintersecting at a point.

There is an event point above theintersecting point where sk and slare adjacent and are tested forintersection. So, no intersectionpoint is ever missed.

Page 45: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm

Create a heap H with they -coordinates of end points of L.Create sweep status data structureT on x-coordinates of the points.Initially T is empty.

Keep on extracting points from Htill it is non-empty.

Based on the three cases: segmenttop end point, segment bottomend point and intersection point,take necessary actions on T .

Page 46: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm

Create a heap H with they -coordinates of end points of L.Create sweep status data structureT on x-coordinates of the points.Initially T is empty.

Keep on extracting points from Htill it is non-empty.

Based on the three cases: segmenttop end point, segment bottomend point and intersection point,take necessary actions on T .

Page 47: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm

Create a heap H with they -coordinates of end points of L.Create sweep status data structureT on x-coordinates of the points.Initially T is empty.

Keep on extracting points from Htill it is non-empty.

Based on the three cases: segmenttop end point, segment bottomend point and intersection point,take necessary actions on T .

Page 48: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm: The three cases

[Top end point] Insert the line segmentinto T based on x- coordinates.

Test for intersections with line segmentsto the left and right. Insert intersectionpoint, if any, into H.

[Bottom end point] Delete this linesegment from T . Test for intersectionsbetween preceding and succeeding entriesin T .

[Intersection point] Swap the linesegments’ status in T . Check forintersections of preceding and succeedingentries.

Page 49: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm: The three cases

[Top end point] Insert the line segmentinto T based on x- coordinates.

Test for intersections with line segmentsto the left and right. Insert intersectionpoint, if any, into H.

[Bottom end point] Delete this linesegment from T . Test for intersectionsbetween preceding and succeeding entriesin T .

[Intersection point] Swap the linesegments’ status in T . Check forintersections of preceding and succeedingentries.

Page 50: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm: The three cases

[Top end point] Insert the line segmentinto T based on x- coordinates.

Test for intersections with line segmentsto the left and right. Insert intersectionpoint, if any, into H.

[Bottom end point] Delete this linesegment from T . Test for intersectionsbetween preceding and succeeding entriesin T .

[Intersection point] Swap the linesegments’ status in T . Check forintersections of preceding and succeedingentries.

Page 51: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Algorithm: The three cases

[Top end point] Insert the line segmentinto T based on x- coordinates.

Test for intersections with line segmentsto the left and right. Insert intersectionpoint, if any, into H.

[Bottom end point] Delete this linesegment from T . Test for intersectionsbetween preceding and succeeding entriesin T .

[Intersection point] Swap the linesegments’ status in T . Check forintersections of preceding and succeedingentries.

Page 52: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Analysis

Analysis

Total number of event points is 2n + I , where I is the numberof intersections.

The heap H grows to a size at most 2n + I . Each operationtakes O(log(2n + I )). As I < n2, so O(log(2n + I )) =O(log n).

The balanced binary search tree T grows also to a size atmost 2n + I . So, each operation takes O(log n).

So, the total time taken is O((2n + I ) log n) =O(n log n + I log n).

Page 53: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Analysis

Analysis

Total number of event points is 2n + I , where I is the numberof intersections.

The heap H grows to a size at most 2n + I . Each operationtakes O(log(2n + I )). As I < n2, so O(log(2n + I )) =O(log n).

The balanced binary search tree T grows also to a size atmost 2n + I . So, each operation takes O(log n).

So, the total time taken is O((2n + I ) log n) =O(n log n + I log n).

Page 54: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Analysis

Analysis

Total number of event points is 2n + I , where I is the numberof intersections.

The heap H grows to a size at most 2n + I . Each operationtakes O(log(2n + I )). As I < n2, so O(log(2n + I )) =O(log n).

The balanced binary search tree T grows also to a size atmost 2n + I . So, each operation takes O(log n).

So, the total time taken is O((2n + I ) log n) =O(n log n + I log n).

Page 55: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Analysis

Analysis

Total number of event points is 2n + I , where I is the numberof intersections.

The heap H grows to a size at most 2n + I . Each operationtakes O(log(2n + I )). As I < n2, so O(log(2n + I )) =O(log n).

The balanced binary search tree T grows also to a size atmost 2n + I . So, each operation takes O(log n).

So, the total time taken is O((2n + I ) log n) =O(n log n + I log n).

Page 56: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 57: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Convex Hull

Definition

A set S ⊂ R2 is convex if for anytwo points p, q ∈ S , pq ∈ S .

Definition

Let P be a set of points in R2.Convex hull of P, denoted byCH(P), is the smallest convexset containing P.

Page 58: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Convex Hull

Definition

A set S ⊂ R2 is convex if for anytwo points p, q ∈ S , pq ∈ S .

Definition

Let P be a set of points in R2.Convex hull of P, denoted byCH(P), is the smallest convexset containing P.

Page 59: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Convex Hull Problem

Problem

Given a set of points P in theplane, compute the convex hullCH(P) of the set P.

A Naive Algorithm

Consider all line segmentsdetermined by

(n2

)= O(n2)

pairs of points.

If a line segment has all theother n − 2 points on oneside of it, then it is a hulledge.

We need(n2

)(n − 2) =

O(n3) time.

Page 60: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Convex Hull Problem

Problem

Given a set of points P in theplane, compute the convex hullCH(P) of the set P.

A Naive Algorithm

Consider all line segmentsdetermined by

(n2

)= O(n2)

pairs of points.

If a line segment has all theother n − 2 points on oneside of it, then it is a hulledge.

We need(n2

)(n − 2) =

O(n3) time.

Page 61: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Convex Hull Problem

Problem

Given a set of points P in theplane, compute the convex hullCH(P) of the set P.

A Naive Algorithm

Consider all line segmentsdetermined by

(n2

)= O(n2)

pairs of points.

If a line segment has all theother n − 2 points on oneside of it, then it is a hulledge.

We need(n2

)(n − 2) =

O(n3) time.

Page 62: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Towards a Better Algorithm

Way forward, but how much?

Better characterizations lead to better algorithms.

How much better can we make?

Leads to the notion of lower bound of a problem.

The problem of Convex Hull has a lower bound of Ω(n log n).This can be shown by a reduction from the problem of sortingwhich also has a lower bound of Ω(n log n).

Page 63: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Towards a Better Algorithm

Way forward, but how much?

Better characterizations lead to better algorithms.

How much better can we make?

Leads to the notion of lower bound of a problem.

The problem of Convex Hull has a lower bound of Ω(n log n).This can be shown by a reduction from the problem of sortingwhich also has a lower bound of Ω(n log n).

Page 64: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Towards a Better Algorithm

Way forward, but how much?

Better characterizations lead to better algorithms.

How much better can we make?

Leads to the notion of lower bound of a problem.

The problem of Convex Hull has a lower bound of Ω(n log n).This can be shown by a reduction from the problem of sortingwhich also has a lower bound of Ω(n log n).

Page 65: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Towards a Better Algorithm

Way forward, but how much?

Better characterizations lead to better algorithms.

How much better can we make?

Leads to the notion of lower bound of a problem.

The problem of Convex Hull has a lower bound of Ω(n log n).This can be shown by a reduction from the problem of sortingwhich also has a lower bound of Ω(n log n).

Page 66: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 67: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 68: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 69: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 70: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 71: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Graham’s Scan: An optimal algorithm for Convex Hull

A better characterization

Consider a walk in clockwise direction onthe vertices of a closed polygon.

Only for a convex polygon, we will make aright turn always.

The incremental paradigm

Insert points in P one by one and updatethe solution at each step.

We compute the upper hull first. Theupper hull contains the convex hull edgesthat bound the convex hull from above.

Sort the points in P from left to right.

Page 72: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points P

Output: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 73: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of P

Sort P according to x-coordinate to generatea sequence of points p[1], p[2], ..., p[n];

Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 74: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];

Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 75: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;

for i = 3 to n Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 76: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 77: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;

while(L_U contains more than two points ANDthe last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 78: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 79: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Algorithm

Input: A set of points POutput: Convex Hull of PSort P according to x-coordinate to generate

a sequence of points p[1], p[2], ..., p[n];Put p[1] first and then p[2] in a list L_U;for i = 3 to n

Append p[i] to L_U;while(L_U contains more than two points AND

the last three points in L_Udo not make a right turn)

Delete the middle of the lastthree points from L_U;

Page 80: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm in Action

The algorithm in action

Page 81: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 82: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 83: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 84: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 85: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 86: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 87: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

The Algorithm

Time Complexity

Sorting takes time O(n log n).

The for loop is executed O(n) times.

For each execution of the for loop, the while loop isencountered once.

For each extra execution of the while loop, a point getsdeleted.

A point once deleted, is never deleted again.

So, the total number of extra executions is bounded by O(n).

Hence, the total time complexity is O(n log n).

Page 88: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Proof of Correctness

The Proof of Correctness

Page 89: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Outline

1 Introduction

2 Area Computation of a Simple Polygon

3 Point Inclusion in a Simple Polygon

4 Line Segment Intersection: An application of plane sweep

5 Convex Hull: An application of an incremental algorithm

6 Art Gallery Problem: A study of combinatorial geometry

Page 90: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Problem

Given a simple polygon P of n vertices,find the minimum number of camerasthat can guard P.

Hardness

The above problem is NP-Hard.

Any solution?

Can we find as a function of n thenumber of cameras that suffices toguard P?

Recall P can be triangulated inton − 2 triangles. Place a guard ineach triangle.

Page 91: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Problem

Given a simple polygon P of n vertices,find the minimum number of camerasthat can guard P.

Hardness

The above problem is NP-Hard.

Any solution?

Can we find as a function of n thenumber of cameras that suffices toguard P?

Recall P can be triangulated inton − 2 triangles. Place a guard ineach triangle.

Page 92: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Problem

Given a simple polygon P of n vertices,find the minimum number of camerasthat can guard P.

Hardness

The above problem is NP-Hard.

Any solution?

Can we find as a function of n thenumber of cameras that suffices toguard P?

Recall P can be triangulated inton − 2 triangles. Place a guard ineach triangle.

Page 93: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Problem

Given a simple polygon P of n vertices,find the minimum number of camerasthat can guard P.

Hardness

The above problem is NP-Hard.

Any solution?

Can we find as a function of n thenumber of cameras that suffices toguard P?

Recall P can be triangulated inton − 2 triangles. Place a guard ineach triangle.

Page 94: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Problem

Given a simple polygon P of n vertices,find the minimum number of camerasthat can guard P.

Hardness

The above problem is NP-Hard.

Any solution?

Can we find as a function of n thenumber of cameras that suffices toguard P?

Recall P can be triangulated inton − 2 triangles. Place a guard ineach triangle.

Page 95: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Can we bring the bound down?

Place guards at vertices of thetriangulation T of P.

We do a 3-coloring of the verticesof T . Each triangle of T has ablack, gray and white vertex.

Choose the smallest color class toguard P.

Hence, bn3c guards suffice.

But, does a 3-coloring always exist?

Page 96: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Can we bring the bound down?

Place guards at vertices of thetriangulation T of P.

We do a 3-coloring of the verticesof T . Each triangle of T has ablack, gray and white vertex.

Choose the smallest color class toguard P.

Hence, bn3c guards suffice.

But, does a 3-coloring always exist?

Page 97: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Can we bring the bound down?

Place guards at vertices of thetriangulation T of P.

We do a 3-coloring of the verticesof T . Each triangle of T has ablack, gray and white vertex.

Choose the smallest color class toguard P.

Hence, bn3c guards suffice.

But, does a 3-coloring always exist?

Page 98: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Can we bring the bound down?

Place guards at vertices of thetriangulation T of P.

We do a 3-coloring of the verticesof T . Each triangle of T has ablack, gray and white vertex.

Choose the smallest color class toguard P.

Hence, bn3c guards suffice.

But, does a 3-coloring always exist?

Page 99: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

Can we bring the bound down?

Place guards at vertices of thetriangulation T of P.

We do a 3-coloring of the verticesof T . Each triangle of T has ablack, gray and white vertex.

Choose the smallest color class toguard P.

Hence, bn3c guards suffice.

But, does a 3-coloring always exist?

Page 100: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

A 3-coloring always exists

Consider the dual graph GT of Tof P.

GT is a tree as P has no holes.

Do a DFS on GT to obtain thecoloring.

Place guards at those vertices thathave color of the minimum colorclass. Hence, bn3c guards aresufficient to guard P.

Necessity?

Are bn3c guards sometimes necessary?

Page 101: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

A 3-coloring always exists

Consider the dual graph GT of Tof P.

GT is a tree as P has no holes.

Do a DFS on GT to obtain thecoloring.

Place guards at those vertices thathave color of the minimum colorclass. Hence, bn3c guards aresufficient to guard P.

Necessity?

Are bn3c guards sometimes necessary?

Page 102: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

A 3-coloring always exists

Consider the dual graph GT of Tof P.

GT is a tree as P has no holes.

Do a DFS on GT to obtain thecoloring.

Place guards at those vertices thathave color of the minimum colorclass. Hence, bn3c guards aresufficient to guard P.

Necessity?

Are bn3c guards sometimes necessary?

Page 103: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

A 3-coloring always exists

Consider the dual graph GT of Tof P.

GT is a tree as P has no holes.

Do a DFS on GT to obtain thecoloring.

Place guards at those vertices thathave color of the minimum colorclass. Hence, bn3c guards aresufficient to guard P.

Necessity?

Are bn3c guards sometimes necessary?

Page 104: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Problem

A 3-coloring always exists

Consider the dual graph GT of Tof P.

GT is a tree as P has no holes.

Do a DFS on GT to obtain thecoloring.

Place guards at those vertices thathave color of the minimum colorclass. Hence, bn3c guards aresufficient to guard P.

Necessity?

Are bn3c guards sometimes necessary?

Page 105: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Art Gallery Theorem

The Final Theorem

For a simple polygon with n vertices, bn3c cameras are alwayssufficient and occasionally necessary to have every point in thepolygon visible from at least one of the cameras.

Page 106: Introduction to Computational Geometrycs.rkmvu.ac.in/~sghosh/public_html/bhu_igga/arbintrocgt...Introduction Computational Geometry (CG) involves study of algorithms for solving geometric

Introduction Area Inclusion Line Hull Art Gallery

Bibliography

Michael Ian Shamos, Computational Geometry, PhD thesis,Yale University, New Haven.

Franco P. Preparata and Michael Ian Shamos, ComputationalGeometry: An Introduction, Springer-Verlag, New York, 1985.

Joseph O’Rourke, Computational Geometry in C, CambridgeUniversity Press, 1998.

Mark de Berg, Marc van Kreveld, Mark Overmars and OtfriedSchwarzkof, Computational Geometry: Algorithms andApplications, Springer, 1997.

http://www.algorithmic-solutions.com

http://www.cgal.org

B. Chazelle, Triangulating a simple polygon in linear time,Discrete Comput. Geom., 6:485524, 1991.