Computational Geometry Lecture 1: Introduction and convex hulls 1 - - PowerPoint PPT Presentation

computational geometry
SMART_READER_LITE
LIVE PREVIEW

Computational Geometry Lecture 1: Introduction and convex hulls 1 - - PowerPoint PPT Presentation

Computational Geometry Lecture 1: Introduction and convex hulls 1 Computational Geometry Lecture 1: Introduction and Convex Hulls Geometry: points, lines, ... Plane (two-dimensional), R 2 Space (three-dimensional), R 3 Space


slide-1
SLIDE 1

Computational Geometry

Lecture 1: Introduction and convex hulls

Computational Geometry Lecture 1: Introduction and Convex Hulls

1

slide-2
SLIDE 2

Geometry: points, lines, ...

Plane (two-dimensional), R2 Space (three-dimensional), R3 Space (higher-dimensional), Rd A point in the plane, 3-dimensional space, higher-dimensional space. 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

2

slide-3
SLIDE 3

Geometry: line segments

A line segment pq is defined by its two endpoints p and q: (λ ·px +(1−λ)·qx, λ ·py +(1−λ)·qy) where 0 ≤ λ ≤ 1 Line segments are assumed to be closed = with endpoints, not open Two line segments intersect if they have some point in common. It is a proper intersection if it is exactly one interior point of each line segment

Computational Geometry Lecture 1: Introduction and Convex Hulls

3

slide-4
SLIDE 4

Polygons: simple or not

A polygon is a connected region of the plane bounded by a sequence of line segments simple polygon polygon with holes convex polygon non-simple polygon The line segments of a polygon are called its edges, the endpoints of those edges are the vertices Some abuse: polygon is only boundary, or interior plus boundary

interior exterior

Computational Geometry Lecture 1: Introduction and Convex Hulls

4

slide-5
SLIDE 5

Other shapes: rectangles, circles, disks

A circle is only the boundary, a disk is the boundary plus the interior Rectangles, squares, quadrants, slabs, half-lines, wedges, ...

Computational Geometry Lecture 1: Introduction and Convex Hulls

5

slide-6
SLIDE 6

Relations: distance, intersection, angle

The distance between two points is generally the Euclidean distance:

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

Another option: the Manhattan distance: |px −qx|+|py −qy| Question: What is the set of points at equal Manhattan distance to some point?

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

|px − qx| |py − qy|

Computational Geometry Lecture 1: Introduction and Convex Hulls

6

slide-7
SLIDE 7

Relations: distance, intersection, angle

The distance between two geometric objects other than points usually refers to the minimum distance between two points that are part of these objects Question: How can the distance between two line segments be realized?

Computational Geometry Lecture 1: Introduction and Convex Hulls

7

slide-8
SLIDE 8

Relations: distance, intersection, angle

The intersection of two geometric

  • bjects is the set of points (part of

the plane, space) they have in common Question 1: How many intersection points can a line and a circle have? Question 2: What are the possible

  • utcomes of the intersection of a

rectangle and a quadrant?

Computational Geometry Lecture 1: Introduction and Convex Hulls

8

slide-9
SLIDE 9

Relations: distance, intersection, angle

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

Computational Geometry Lecture 1: Introduction and Convex Hulls

9

slide-10
SLIDE 10

Relations: distance, intersection, angle

Question 4: What is the maximum number of intersection points of a line and a simple polygon boundary with 10 vertices (still a trick question)?

Computational Geometry Lecture 1: Introduction and Convex Hulls

10

slide-11
SLIDE 11

Relations: distance, intersection, angle

Question 5: What is the maximum number of edges of a simple polygon boundary with 10 vertices that a line can intersect?

Computational Geometry Lecture 1: Introduction and Convex Hulls

11

slide-12
SLIDE 12

Description size

A point in the plane can be represented using two reals A line in the plane can be represented using two reals and a Boolean (for example) A line segment can be represented by two points, so four reals A circle (or disk) requires three reals to store it (center, radius) A rectangle requires four reals to store it

false, m, c true, .., c y = m · x + c x = c

Computational Geometry Lecture 1: Introduction and Convex Hulls

12

slide-13
SLIDE 13

Description size

A simple polygon in the plane can be represented using 2n reals if it 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

13

slide-14
SLIDE 14

Computation time

Any computation (distance, intersection) on two objects of O(1) description size takes O(1) time! Question: Suppose that a simple polygon with n vertices is given; the vertices are given in counterclockwise order along the

  • boundary. Give an efficient algorithm to determine all edges that

are intersected by a given line. How efficient is your algorithm? Why is your algorithm efficient?

Computational Geometry Lecture 1: Introduction and Convex Hulls

14

slide-15
SLIDE 15

Algorithms, efficiency

Recall from your algorithms and data structures course: A set of n real numbers can be sorted in O(nlogn) time A set of n real numbers can be stored in a data structure that uses O(n) storage and that allows searching, insertion, and deletion in O(logn) time per operation These are fundamental results in 1-dimensional computational geometry!

Computational Geometry Lecture 1: Introduction and Convex Hulls

15

slide-16
SLIDE 16

Computational geometry scope

In computational geometry, problems on input with more than constant description size are the ones of interest Computational geometry (theory): Study of geometric problems on geometric data, and how efficient geometric algorithms that solve them can be Computational geometry (practice): Study of geometric problems that arise in various applications and how geometric algorithms can help to solve well-defined versions of such problems

Computational Geometry Lecture 1: Introduction and Convex Hulls

16

slide-17
SLIDE 17

Computational geometry theory

Computational geometry (theory): Classify abstract geometric problems into classes depending on how efficiently they can be solved

smallest enclosing circle closest pair any intersection? find all intersections

Computational Geometry Lecture 1: Introduction and Convex Hulls

17

slide-18
SLIDE 18

Computational geometry practice

Application areas that require geometric algorithms are computer graphics, motion planning and robotics, geographic information systems, CAD/CAM, statistics, physics simulations, databases, games, multimedia retrieval, ... Computing shadows from virtual light sources Spatial interpolation from groundwater pollution measurements Computing a collision-free path between obstacles Computing similarity of two shapes for shape database retrieval

Computational Geometry Lecture 1: Introduction and Convex Hulls

18

slide-19
SLIDE 19

Computational geometry history

Early 70s: First attention for geometric problems from algorithms researchers 1976: First PhD thesis in computational geometry (Michael Shamos) 1985: First Annual ACM Symposium on Computational Geometry. Also: first textbook 1996: CGAL: first serious implementation effort for robust geometric algorithms 1997: First handbook on computational geometry (second one in 2000)

Computational Geometry Lecture 1: Introduction and Convex Hulls

19

slide-20
SLIDE 20

Convexity

A shape or set is convex if for any two points that are part of the shape, the whole connecting line segment is also part of the shape Question: Which of the following shapes are convex? Point, line segment, line, circle, disk, quadrant?

Computational Geometry Lecture 1: Introduction and Convex Hulls

20

slide-21
SLIDE 21

Convex hull

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

Computational Geometry Lecture 1: Introduction and Convex Hulls

21

slide-22
SLIDE 22

Convex hull problem

Give an algorithm that computes the convex hull of any given set of n points in the plane efficiently The input has 2n coordinates, so O(n) size Question: Why can’t we expect to do any better than O(n) time?

Computational Geometry Lecture 1: Introduction and Convex Hulls

22

slide-23
SLIDE 23

Convex hull problem

Assume the n points are distinct The output has at least 4 and at most 2n coordinates, so it has size between O(1) and O(n) The output is a convex polygon so it should be returned as a sorted sequence of the points, clockwise (CW) along the boundary Question: Is there any hope of finding an O(n) time algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

23

slide-24
SLIDE 24

Developing an algorithm

To develop an algorithm, find useful properties, make various

  • bservations, draw many sketches to

gain insight Property: The vertices of the convex hull are always points from the input Consequently, the edges of the convex hull connect two points of the input Property: The supporting line of any convex hull edge has all input points to one side

p q all points lie right of the directed line from p to q, if the edge from p to q is a CW convex hull edge

Computational Geometry Lecture 1: Introduction and Convex Hulls

24

slide-25
SLIDE 25

Developing an algorithm

To develop an algorithm, find useful properties, make various

  • bservations, draw many sketches to

gain insight Property: The vertices of the convex hull are always points from the input Consequently, the edges of the convex hull connect two points of the input Property: The supporting line of any convex hull edge has all input points to one side

p q all points lie right of the directed line from p to q, if the edge from p to q is a CW convex hull edge

Computational Geometry Lecture 1: Introduction and Convex Hulls

25

slide-26
SLIDE 26

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
  • rder.

1. E ← / 0. 2. for all ordered pairs (p,q) ∈ P×P with p not equal to q 3. do valid ← true 4. for all points r ∈ P not equal to p or q 5. do if r lies left of the directed line from p to q 6. then valid ← false 7. if valid then Add the directed edge pq to E 8. 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

26

slide-27
SLIDE 27

Developing an algorithm

Question: How must line 5 be interpreted to make the algorithm correct? Question: How efficient is the algorithm?

Computational Geometry Lecture 1: Introduction and Convex Hulls

27

slide-28
SLIDE 28

Developing an algorithm

Another approach: incremental, from left to right Let’s first compute the upper boundary of the convex hull this way (property: on the upper hull, points appear in x-order) Main idea: Sort the points from left to right (= by x-coordinate). Then insert the points in this order, and maintain the upper hull so far

Computational Geometry Lecture 1: Introduction and Convex Hulls

28

slide-29
SLIDE 29

Developing an algorithm

Observation: from left to right, there are only right turns

  • n the upper hull

Computational Geometry Lecture 1: Introduction and Convex Hulls

29

slide-30
SLIDE 30

Developing an algorithm

Initialize by inserting the leftmost two points

Computational Geometry Lecture 1: Introduction and Convex Hulls

30

slide-31
SLIDE 31

Developing an algorithm

If we add the third point there will be a right turn at the previous point, so we add it

Computational Geometry Lecture 1: Introduction and Convex Hulls

31

slide-32
SLIDE 32

Developing an algorithm

If we add the fourth point we get a left turn at the third point

Computational Geometry Lecture 1: Introduction and Convex Hulls

32

slide-33
SLIDE 33

Developing an algorithm

... so we remove the third point from the upper hull when we add the fourth

Computational Geometry Lecture 1: Introduction and Convex Hulls

33

slide-34
SLIDE 34

Developing an algorithm

If we add the fifth point we get a left turn at the fourth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

34

slide-35
SLIDE 35

Developing an algorithm

... so we remove the fourth point when we add the fifth

Computational Geometry Lecture 1: Introduction and Convex Hulls

35

slide-36
SLIDE 36

Developing an algorithm

If we add the sixth point we get a right turn at the fifth point, so we just add it

Computational Geometry Lecture 1: Introduction and Convex Hulls

36

slide-37
SLIDE 37

Developing an algorithm

We also just add the seventh point

Computational Geometry Lecture 1: Introduction and Convex Hulls

37

slide-38
SLIDE 38

Developing an algorithm

When adding the eight point ... we must remove the seventh point

Computational Geometry Lecture 1: Introduction and Convex Hulls

38

slide-39
SLIDE 39

Developing an algorithm

... we must remove the seventh point

Computational Geometry Lecture 1: Introduction and Convex Hulls

39

slide-40
SLIDE 40

Developing an algorithm

... and also the sixth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

40

slide-41
SLIDE 41

Developing an algorithm

... and also the fifth point

Computational Geometry Lecture 1: Introduction and Convex Hulls

41

slide-42
SLIDE 42

Developing an algorithm

After two more steps we get:

Computational Geometry Lecture 1: Introduction and Convex Hulls

42

slide-43
SLIDE 43

The pseudo-code

Algorithm ConvexHull(P)

  • Input. A set P of points in the plane.
  • Output. A list containing the vertices of CH(P) in clockwise order.

1. Sort the points by x-coordinate, resulting in a sequence p1,...,pn. 2. Put the points p1 and p2 in a list Lupper, with p1 as the first point. 3. for i ← 3 to n 4. do Append pi to Lupper. 5. while Lupper contains more than two points and the last three points in Lupper do not make a right turn 6. do Delete the middle of the last three points from Lupper.

Computational Geometry Lecture 1: Introduction and Convex Hulls

43

slide-44
SLIDE 44

The pseudo-code

Then we do the same for the lower convex hull, from right to left We remove the first and last points of the lower convex hull ... and concatenate the two lists into one

p1, p2, p10, p13, p14 p14, p12, p8, p4, p1

Computational Geometry Lecture 1: Introduction and Convex Hulls

44

slide-45
SLIDE 45

Algorithm analysis

Algorithm analysis generally has two components: proof of correctness efficiency analysis, proof of running time

Computational Geometry Lecture 1: Introduction and Convex Hulls

45

slide-46
SLIDE 46

Correctness

Are the general observations on which the algorithm is based correct? Does the algorithm handle degenerate cases correctly? Here: Does the sorted order matter if two or more points have the same x-coordinate? What happens if there are three or more collinear points, in particular on the convex hull?

Computational Geometry Lecture 1: Introduction and Convex Hulls

46

slide-47
SLIDE 47

Efficiency

Identify of each line of pseudo-code how much time it takes, if it is executed once (note: operations on a constant number of constant-size objects take constant time) Consider the loop-structure and examine how often each line of pseudo-code is executed Sometimes there are global arguments why an algorithm is more efficient than it seems, at first

Computational Geometry Lecture 1: Introduction and Convex Hulls

47

slide-48
SLIDE 48

The pseudo-code

Algorithm ConvexHull(P)

  • Input. A set P of points in the plane.
  • Output. A list containing the vertices of CH(P) in clockwise order.

1. Sort the points by x-coordinate, resulting in a sequence p1,...,pn. 2. Put the points p1 and p2 in a list Lupper, with p1 as the first point. 3. for i ← 3 to n 4. do Append pi to Lupper. 5. while Lupper contains more than two points and the last three points in Lupper do not make a right turn 6. do Delete the middle of the last three points from Lupper.

Computational Geometry Lecture 1: Introduction and Convex Hulls

48

slide-49
SLIDE 49

Efficiency

The sorting step takes O(nlogn) time Adding a point takes O(1) time for the adding-part. Removing points takes constant time for each removed point. If due to an addition, k points are removed, the step takes O(1+k) time Total time: O(nlogn)+

n

i=3

O(1+ki) if ki points are removed when adding pi Since ki = O(n), we get O(nlogn)+

n

i=3

O(n) = O(n2)

Computational Geometry Lecture 1: Introduction and Convex Hulls

49

slide-50
SLIDE 50

Efficiency

Global argument: each point can be removed only once from the upper hull This gives us the fact:

n

i=3

ki ≤ n Hence, O(nlogn)+

n

i=3

O(1+ki) = O(nlogn)+O(n) = O(nlogn)

Computational Geometry Lecture 1: Introduction and Convex Hulls

50

slide-51
SLIDE 51

Final result

The convex hull of a set of n points in the plane can be computed in O(nlogn) time, and this is optimal

Computational Geometry Lecture 1: Introduction and Convex Hulls

51

slide-52
SLIDE 52

Other approaches: divide-and-conquer

Divide-and-conquer: split the point set in two halves, compute the convex hulls recursively, and merge A merge involves finding “extreme vertices” in every direction

Computational Geometry Lecture 1: Introduction and Convex Hulls

52

slide-53
SLIDE 53

Other approaches: divide-and-conquer

Alternatively: split the point set in two halves on x-coordinate, compute the convex hulls recursively, and merge A merge now comes down to finding two common tangent lines

Computational Geometry Lecture 1: Introduction and Convex Hulls

53

slide-54
SLIDE 54

Convex hulls in 3D

For a 3-dimensional point set, the convex hull is a convex polyhedron It has vertices (0-dim.), edges (1-dim.), and facets (2-dim.) in its boundary, and a 3-dimensional interior The boundary is a planar graph, so it has O(n) vertices, edges and facets

Computational Geometry Lecture 1: Introduction and Convex Hulls

54

slide-55
SLIDE 55

Convex hulls in 4D

For a 4-dimensional point set, the convex hull is a convex polyhedron It has vertices (0-dim.), edges (1-dim.), 2-facets (2-dim.), and 3-facets (3-dim.) in its boundary, and a 4-dimensional interior Its boundary can have Θ(n2) facets in the worst case!

Computational Geometry Lecture 1: Introduction and Convex Hulls

55