39
Computational Geometry Algorithmische Geometrie Panos Giannopoulos, Wolfgang Mulzer, Lena Schlipf AG TI SS 2013

Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Embed Size (px)

Citation preview

Page 1: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Computational GeometryAlgorithmische Geometrie

Panos Giannopoulos, Wolfgang Mulzer, Lena SchlipfAG TI

SS 2013

Page 2: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

!! Register in Campus Management !!

Page 3: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Outline

What you need to know (before taking this course)

What is the course about?

Course information

Basics

Convex Hulls I

Assignment 1

,FU Berlin, Computational Geometry, SS 2013 3

Page 4: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

You need to know (or learn quickly)

É Basic geometryÉ O,Ω,Θ-notation; how to analyze algorithmsÉ Basic discrete maths: manipulating summations,

solving recurrences, working with logarithms, etc.É Basic probability theory: events, probability distributions,

random variables, expected values etc.É Basic data structures: linked lists, stacks, queuesÉ Balanced binary search trees (AVL trees, etc.)É Sorting algorithmsÉ Basic graph theory (terminology, algorithms etc.)É Basic algorithmic paradigms: divide & conquer,

greedy algorithms, dynamic programming etc.

,FU Berlin, Computational Geometry, SS 2013 4

Page 5: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

This course is about

Computational geometry (theory):Study of geometric problems on geometric data,and how efficient algorithms that solve them can be

Computational geometry (practice):Study of geometric problems that arise in various applications,and how algorithms can help to solve well-defined versions ofsuch problems

,FU Berlin, Computational Geometry, SS 2013 5

Page 6: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

This course is about

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Computational geometry theory

Computational geometry (theory):Classify abstract geometric problemsinto classes depending on howefficiently they can be solved

smallest enclosing circle

closest pair

any intersection?

find all intersectionsComputational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 6

Page 7: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

This course is about: Example I

Intersections, Arrangements, Point location

intersection point

Arrangement face

query point

Tasks:É compute all object intersectionsÉ compute and maintain

the induced arrangement(points, edges, faces)

É do point location:find the face that a query pointlies in

Efficiency is important!

,FU Berlin, Computational Geometry, SS 2013 7

Page 8: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

This course is about: Example II

Robot motion planning, Finding a shortest path amidst obstacles

15 Visibility GraphsFinding the Shortest Route

In Chapter 13 we saw how to plan a path for a robot from a given start positionto a given goal position. The algorithm we gave always finds a path if it exists,but we made no claims about the quality of the path: it could make a largedetour, or make lots of unnecessary turns. In practical situations we wouldprefer to find not just any path, but a good path.

Figure 15.1A shortest path

What constitutes a good path depends on the robot. In general, the longer apath, the more time it will take the robot to reach its goal position. For a mobilerobot on a factory floor this means it can transport less goods per time unit,resulting in a loss of productivity. Therefore we would prefer a short path. Oftenthere are other issues that play a role as well. For example, some robots can onlymove in a straight line; they have to slow down, stop, and rotate, before theycan start moving into a different direction, so any turn along the path causessome delay. For this type of robot not only the path length but also the numberof turns on the path has to be taken into account. In this chapter we ignorethis aspect; we only show how to compute the Euclidean shortest path for atranslating planar robot. 323

Tasks:É find a collision-free path for the

robot from start-position totarget-position

É collision-free: the robot does notintersect any ostacle

É find a shortest such pathÉ several versions: 2d, 3d,

translating/rotating robots etc.

Efficiency is important!

,FU Berlin, Computational Geometry, SS 2013 8

Page 9: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Computational geometry applicationsIntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Computational geometry practice

Application areas that require geometric algorithms are computergraphics, motion planning and robotics, geographic informationsystems, CAD/CAM, statistics, physics simulations, databases,games, multimedia retrieval, . . .

Computing shadows from virtual light sources

Spatial interpolation from groundwater pollutionmeasurements

Computing a collision-free path between obstacles

Computing similarity of two shapes for shape databaseretrieval

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 9

Page 10: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Course informationÉ Lectures: Panos Giannopoulos

(April, half of May, July, English),Wolfgang Mulzer (half of May, June, July, English/Deutsch)

É Be present in the lectures!É Tutorials: Lena SchlipfÉ Be present in the tutorials! (Especially if you have difficulties

solving the exercises)É Homework assignements: you may solve them in groups of

two (Programming?)É Homework assignements: you can hand in the solutions in

English/DeutschÉ Homework assignements due: Monday before the Tutorial

starts (10 days)É There will be a written exam!É In order to pass the course:

É 60% of the assignments in totalÉ 20% of each assignment (you can skip at most one)É present two exercises in the tutorials (dance as well ?)É pass the exam

,FU Berlin, Computational Geometry, SS 2013 10

Page 11: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Course information (cont.)

Course webpage:http://page.mi.fu-berlin.de/panos/cg13/index.html

Book:M. de Berg, O. Cheong, M. van Kreveld, M. Overmars.Computational Geometry: Algorithms and Applications. Springer,2008. (3rd ed.).

,FU Berlin, Computational Geometry, SS 2013 11

Page 12: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Geometry: Points, lines, . . .

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Geometry: points, lines, ...

Plane (two-dimensional), R2

Space (three-dimensional), R3

Space (higher-dimensional), Rd

A point in the plane, 3-dimensional space, higher-dimensionalspace.p = (px,py), p = (px,py,pz), p = (p1,p2, . . . ,pd)

A line in the plane: y = m · x+ c; representation by m and c

A half-plane in the plane: y≤ m · x+ c or y≥ m · x+ c

Represent vertical lines? Not by m and c . . .

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 12

Page 13: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Geometry: line segments

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Geometry: line segments

A line segment pq is defined by itstwo endpoints p and q:(λ ·px +(1−λ ) ·qx,

λ ·py +(1−λ ) ·qy)where 0≤ λ ≤ 1

Line segments are assumed to beclosed = with endpoints, not open

Two line segments intersect if theyhave some point in common. It is aproper intersection if it is exactly oneinterior point of each line segment

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 13

Page 14: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Polygons: simple or not

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Polygons: simple or not

A polygon is a connected region ofthe plane bounded by a sequence ofline segments

simple polygon

polygon with holes

convex polygon

non-simple polygon

The line segments of a polygon arecalled its edges, the endpoints ofthose edges are the vertices

Some abuse: polygon is onlyboundary, or interior plus boundary

interior

exterior

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 14

Page 15: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Rectangles, circles, disks,. . .

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Other shapes: rectangles, circles, disks

A circle is only the boundary, a diskis the boundary plus the interior

Rectangles, squares, quadrants,slabs, half-lines, wedges, . . .

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 15

Page 16: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

The distance between two points isgenerally the Euclidean distance:√(px−qx)2 +(py−qy)2

Another option: the Manhattandistance:

|px−qx|+ |py−qy|

Question: What is the set of pointsat equal Manhattan distance to somepoint?

√(px − qx)2 + (py − qy)2)

|px − qx|

|py − qy|

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 17: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

The distance between two geometric objects other than pointsusually refers to the minimum distance between two points thatare part of these objects

Question: How can the distance between two line segments berealized?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 18: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

The intersection of two geometricobjects is the set of points (part ofthe plane, space) they have incommon

Question 1: How many intersectionpoints can a line and a circle have?

Question 2: What are the possibleoutcomes of the intersection of arectangle and a quadrant?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 19: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

Question 3: What is the maximumnumber of intersection points of aline and a simple polygon with 10vertices (trick question)?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 20: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

Question 4: What is the maximumnumber of intersection points of aline and a simple polygon boundarywith 10 vertices (still a trickquestion)?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 21: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Relations: distance, intersection, angle

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Relations: distance, intersection, angle

Question 5: What is the maximumnumber of edges of a simple polygonboundary with 10 vertices that a linecan intersect?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 16

Page 22: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Description size

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Description size

A point in the plane can berepresented using two reals

A line in the plane can berepresented using two reals and aBoolean (for example)

A line segment can be represented bytwo points, so four reals

A circle (or disk) requires three realsto store it (center, radius)

A rectangle requires four reals tostore it

false, m, c

true, .., c

y = m · x + c

x = c

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 17

Page 23: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Description size

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Description size

A simple polygon in the plane can be represented using 2n reals ifit has n vertices (and necessarily, n edges)

A set of n points requires 2n reals

A set of n line segments requires 4n reals

A point, line, circle, . . . requires O(1), or constant, storage.A simple polygon with n vertices requires O(n), or linear, storage

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 17

Page 24: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Computation time

Any computation (distance, intersection) on two objects of O(1)description size takes O(1) time!

(Practice: detecting intersections and computing intersections canbe different)

Theory: Real RAM, i.e., all usual arithmetic operations can be donein constant time (+,−,×, / , sin, log, . . .)

,FU Berlin, Computational Geometry, SS 2013 18

Page 25: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Algorithms, efficiency

IntroductionConvex hulls

More on convex hulls

Geometric objectsGeometric relationsCombinatorial complexityComputational geometry

Algorithms, efficiency

Recall from your algorithms and data structures course:

A set of n real numbers can be sorted in O(n logn) time

A set of n real numbers can be stored in a data structure that usesO(n) storage and that allows searching, insertion, and deletion inO(logn) time per operation

These are fundamental results in 1-dimensional computationalgeometry!

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 19

Page 26: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convexity

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convexity

A shape or set is convex if for anytwo points that are part of theshape, the whole connecting linesegment is also part of the shape

Question: Which of the followingshapes are convex? Point, linesegment, line, circle, disk, quadrant?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 20

Page 27: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convex hull

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull

For any subset of the plane (set ofpoints, rectangle, simple polygon),its convex hull is the smallest convexset that contains that subset

Computational Geometry Lecture 1: Introduction and Convex HullsDemo

,FU Berlin, Computational Geometry, SS 2013 21

Page 28: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convex hull problem

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull problem

Give an algorithm that computes theconvex hull of any given set of npoints in the plane efficiently

The input has 2n coordinates, soO(n) size

Question: Why can’t we expect todo any better than O(n) time?

Computational Geometry Lecture 1: Introduction and Convex Hulls

Lower bound: Any convex hull algorithm requires Ω(n logn)operations in the quadratic decision treemodel [Yao, 1981]

However: Perhaps we can get an output sensitivealgorithm that runs in O(n logh) time,where h is the size of the hull !

,FU Berlin, Computational Geometry, SS 2013 22

Page 29: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convex hull problem

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull problem

Assume the n points are distinct

The output has at least 4 and at most 2n coordinates, so it hassize between O(1) and O(n)

The output is a convex polygon so it should be returned as a sortedsequence of the points, counterclockwise along the boundary

Question: Is there any hope of finding an O(n) time algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

Lower bound: Any convex hull algorithm requires Ω(n logn)operations in the quadratic decision treemodel [Yao, 1981]

However: Perhaps we can get an output sensitivealgorithm that runs in O(n logh) time,where h is the size of the hull !

,FU Berlin, Computational Geometry, SS 2013 22

Page 30: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convex hull problem

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull problem

Assume the n points are distinct

The output has at least 4 and at most 2n coordinates, so it hassize between O(1) and O(n)

The output is a convex polygon so it should be returned as a sortedsequence of the points, counterclockwise along the boundary

Question: Is there any hope of finding an O(n) time algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

Lower bound: Any convex hull algorithm requires Ω(n logn)operations in the quadratic decision treemodel [Yao, 1981]

However: Perhaps we can get an output sensitivealgorithm that runs in O(n logh) time,where h is the size of the hull !

,FU Berlin, Computational Geometry, SS 2013 22

Page 31: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Convex hull problem

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Convex hull problem

Assume the n points are distinct

The output has at least 4 and at most 2n coordinates, so it hassize between O(1) and O(n)

The output is a convex polygon so it should be returned as a sortedsequence of the points, counterclockwise along the boundary

Question: Is there any hope of finding an O(n) time algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

Lower bound: Any convex hull algorithm requires Ω(n logn)operations in the quadratic decision treemodel [Yao, 1981]

However: Perhaps we can get an output sensitivealgorithm that runs in O(n logh) time,where h is the size of the hull !

,FU Berlin, Computational Geometry, SS 2013 22

Page 32: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Developing an algorithm

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

To develop an algorithm, find usefulproperties, make variousobservations, draw many sketches togain insight

Property: The vertices of the convexhull are always points from the input

Consequently, the edges of theconvex hull connect two points ofthe input

Property: The supporting line of anyconvex hull edge has all input pointsto one side

p

q

all points lie left of the di-rected line from p to q, ifthe edge from p to q is aCCW convex hull edge

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 23

Page 33: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Developing an algorithm

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

Algorithm SlowConvexHull(P)Input. A set P of points in the plane.Output. A list L containing the vertices of CH(P) in clockwise

order.1. E← /0.2. for all ordered pairs (p,q) ∈ P×P with p not equal to q3. do valid← true4. for all points r ∈ P not equal to p or q5. do if r lies left of the directed line from p to q6. then valid← false7. if valid then Add the directed edge ~pq to E8. From the set E of edges construct a list L of vertices of

CH(P), sorted in clockwise order.

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 23

Page 34: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Developing an algorithm

IntroductionConvex hulls

More on convex hulls

ConvexityConvex hullAlgorithm developmentAlgorithm analysis

Developing an algorithm

Question: How must line 5 be interpreted to make the algorithmcorrect?

Question: How efficient is the algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

,FU Berlin, Computational Geometry, SS 2013 23

Page 35: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

DegeneraciesSection 1.1AN EXAMPLE: CONVEX HULLS

left of the line through p and q, it can also happen that it lies on this line. Whatshould we do then? This is what we call a degenerate case, or a degeneracy forshort. We prefer to ignore such situations when we first think about a problem,so that we don’t get confused when we try to figure out the geometric propertiesof a problem. However, these situations do arise in practice. For instance, ifwe create the points by clicking on a screen with a mouse, all points will havesmall integer coordinates, and it is quite likely that we will create three pointson a line.

To make the algorithm correct in the presence of degeneracies we mustreformulate the criterion above as follows: a directed edge

!pq is an edge of

CH(P) if and only if all other points r " P lie either strictly to the right of thedirected line through p and q, or they lie on the open line segment pq. (Weassume that there are no coinciding points in P.) So we have to replace line 5 ofthe algorithm by this more complicated test.

We have been ignoring another important issue that can influence the correctnessof the result of our algorithm. We implicitly assumed that we can somehowtest exactly whether a point lies to the right or to the left of a given line. Thisis not necessarily true: if the points are given in floating point coordinates andthe computations are done using floating point arithmetic, then there will berounding errors that may distort the outcome of tests.

p

q

r

p

q

r

Imagine that there are three points p, q, and r, that are nearly collinear, andthat all other points lie far to the right of them. Our algorithm tests the pairs(p,q), (r,q), and (p,r). Since these points are nearly collinear, it is possible thatthe rounding errors lead us to decide that r lies to the right of the line from p toq, that p lies to the right of the line from r to q, and that q lies to the right of theline from p to r. Of course this is geometrically impossible—but the floatingpoint arithmetic doesn’t know that! In this case the algorithm will accept allthree edges. Even worse, all three tests could give the opposite answer, in whichcase the algorithm rejects all three edges, leading to a gap in the boundary ofthe convex hull. And this leads to a serious problem when we try to constructthe sorted list of convex hull vertices in the last step of our algorithm. This stepassumes that there is exactly one edge starting in every convex hull vertex, andexactly one edge ending there. Due to the rounding errors there can suddenly betwo, or no, edges starting in vertex p. This can cause the program implementingour simple algorithm to crash, since the last step has not been designed to dealwith such inconsistent data.

Although we have proven the algorithm to be correct and to handle allspecial cases, it is not robust: small errors in the computations can make itfail in completely unexpected ways. The problem is that we have proven thecorrectness assuming that we can compute exactly with real numbers.

We have designed our first geometric algorithm. It computes the convex hullof a set of points in the plane. However, it is quite slow—its running time isO(n3)—, it deals with degenerate cases in an awkward way, and it is not robust.We should try to do better. 5

3 points of P could lie on a line

Correct criterion for convex hull edge:‘edge

→pq is an edge of CH(P) iff all other points r ∈ P lie either

strictly to the right of the directed line through p,q or on the openline segment pq’ (assuming no coinciding points in P)

At first when developing an algorithm you can assume generalposition...

,FU Berlin, Computational Geometry, SS 2013 24

Page 36: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Left of, Right of,. . ., RobustnessGeometry in Theory

orientation(p, q, r) = sign

det

px py 1qx qy 1rx ry 1

=

< 0 cw(p, q, r)= 0 colinear(p, q, r)> 0 ccw(p, q, r)

= sign((qx − px)(ry − py )− (qy − py )(rx − px))

ccw(p, q, s) ∩ ccw(s, q, r) ∩ ccw(p, s, r)⇒ ccw(p, q, r)

s

rp

q

Computational Geometry Algorithm Library 6Practice: rounding errors in floating point arithmetic can givewrong result of the predicate. We won’t care about this here!

,FU Berlin, Computational Geometry, SS 2013 25

Page 37: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Running time?

O(n3)

We didn’t use any clever ideas!

Friday:O(n logn) and O(n logh) algorithms(h: size of the output)

,FU Berlin, Computational Geometry, SS 2013 26

Page 38: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Running time?

O(n3)

We didn’t use any clever ideas!

Friday:O(n logn) and O(n logh) algorithms(h: size of the output)

,FU Berlin, Computational Geometry, SS 2013 26

Page 39: Computational Geometry - Algorithmische Geometriepage.mi.fu-berlin.de/panos/cg13/l01.pdf · Computational Geometry ... (Programming?) É Homework ... or linear, storage Computational

Assignment 1

http://page.mi.fu-berlin.de/panos/cg13/exercises/u01.pdf

Due: 15/04, before the Tutorial starts!

,FU Berlin, Computational Geometry, SS 2013 27