UMass Lowell Computer Science 91.503 Analysis

of Algorithms Prof. Karen Daniels Spring, 2002

- Tuesday, 5/7/02
- Computational Geometry
- Chapter 33

Relevant Sections of Chapter 35

Youre responsible for material in this chapter

that we discuss in lecture. (Note that this

includes all sections.)

Ch33 Computational Geometry

Overview

- Computational Geometry Introduction
- Line Segment Intersection
- Convex Hull Algorithms
- Nearest Neighbors/Closest Points

Computational Geometry

Computer Graphics

Visualization Bioinformatics

Design

Analyze

Core Geometric Algorithms

Application-Based Algorithms

Apply

Telecommunications

Typical Problems

- maintaining line arrangements
- polygon partitioning
- nearest neighbor search
- kd-trees

- bin packing
- Voronoi diagram
- simplifying polygons
- shape similarity
- convex hull

SOURCE Steve Skienas Algorithm Design Manual

(for problem descriptions, see graphics gallery

at http//www.cs.sunysb.edu/algorith)

Common Computational Geometry Structures

source ORourke, Computational Geometry in C

Sample Tools of the Trade

Algorithm Design Patterns/Techniques binary

search divide-and-conquer duality randomization sw

eep-line derandomization parallelism Algorithm

Analysis Techniques asymptotic analysis,

amortized analysis Data Structures winged-edge,

quad-edge, range tree, kd-tree Theoretical

Computer Science principles NP-completeness,

hardness

MATH

Sets

Proofs

Geometry

Summations

Linear Algebra

Probability

Growth of Functions

Recurrences

Graph Theory

Combinatorics

Computational Geometry in Context

Line Segment Intersections (2D)

- Intersection of 2 Line Segments
- Intersection of gt 2Line Segments

Cross-Product-Based Geometric Primitives

Some fundamental geometric questions

source 91.503 textbook Cormen et al.

(1)

Cross-Product-Based Geometric Primitives (1)

33.1

Advantage less sensitive to accumulated

round-off error

source 91.503 textbook Cormen et al.

Cross-Product-Based Geometric Primitives (2)

33.2

source 91.503 textbook Cormen et al.

Intersection of 2 Line Segments

Step 1 Bounding Box Test

33.3

Step 2 Does each segment straddle the line

containing the other?

source 91.503 textbook Cormen et al.

Segment-Segment Intersection

- Finding the actual intersection point
- Approach parametric vs. slope/intercept
- parametric generalizes to more complex

intersections - Parameterize each segment

Lab

c

Lcd

Cd-c

b

q(t)ctC

d

Ab-a

a

p(s)asA

Intersection values of s, t such that p(s) q(t)

asActC

source ORourke, Computational Geometry in C

Demo

- Segment/Segment Intersection
- http/cs.smith.edu/orourke/books/CompGeom/CompGeo

m.html

Intersection of gt2 Line Segments

Sweep-Line Algorithmic Paradigm

33.4

source 91.503 textbook Cormen et al.

Intersection of gt2 Line Segments

Sweep-Line Algorithmic Paradigm

source 91.503 textbook Cormen et al.

Intersection of gt2 Line Segments

Time to detect if any 2 segments intersect

O(n lg n)

33.5

source 91.503 textbook Cormen et al.

source 91.503 textbook Cormen et al.

Intersection of Segments

- Goal Output-size sensitive line segment

intersection algorithm that actually computes

intersection points - Bentley-Ottmann plane sweep O((nk)logn) time
- k number of intersection points in output
- Intuition sweep horizontal line downwards
- just before intersection, 2 segments are adjacent

in sweep-line intersection structure - check for intersection only segments that

adjacent - event types
- top endpoint of a segment
- bottom endpoint of a segment
- intersection between 2 segments

Improved to O(nlognk) Chazelle/Edelsbrunner

source ORourke, Computational Geometry in C

Convex Hull Algorithms

- Definitions
- Gift Wrapping
- Graham Scan
- QuickHull
- Incremental
- Divide-and-Conquer
- Lower Bound in W(nlgn)

Convexity Convex Hulls

source ORourke, Computational Geometry in C

- A convex combination of points x1, ..., xk is a

sum of the form a1x1... akxk where - Convex hull of a set of points is the set of all

convex combinations of points in the set.

source 91.503 textbook Cormen et al.

Naive Algorithms for Extreme Points

O(n4)

source ORourke, Computational Geometry in C

Algorithms 2D Gift Wrapping

- Use one extreme edge as an anchor for finding the

next

source ORourke, Computational Geometry in C

Gift Wrapping

33.9

source 91.503 textbook Cormen et al.

Algorithms 3D Gift Wrapping

O(n2) time output sensitive O(nF) for F faces

on hull

CxHull Animations http//www.cse.unsw.edu.au/lam

bert/java/3d/hull.html

Algorithms 2D QuickHull

- Concentrate on points close to hull boundary
- Named for similarity to Quicksort

source ORourke, Computational Geometry in C

Algorithms 3D QuickHull

CxHull Animations http//www.cse.unsw.edu.au/lam

bert/java/3d/hull.html

Algorithms Qhull (gt 2D )

http//www.geom.umn.edu/software/qhull/

Grahams Algorithm

source ORourke, Computational Geometry in C

- Points sorted angularly provide star-shaped

starting point - Prevent dents as you go via convexity testing

Graham Scan

source 91.503 textbook Cormen et al.

Graham Scan

33.7

source 91.503 textbook Cormen et al.

Graham Scan

33.7

source 91.503 textbook Cormen et al.

Graham Scan

source 91.503 textbook Cormen et al.

Graham Scan

source 91.503 textbook Cormen et al.

Algorithms 2D Incremental

source ORourke, Computational Geometry in C

- Add points, one at a time
- update hull for each new point
- Key step becomes adding a single point to an

existing hull. - Idea is extended to 3D in Chapter 4.

Algorithm INCREMENTAL ALGORITHM Let H2

ConvexHullp0 , p1 , p2 for k 3 to n - 1

do Hk ConvexHull Hk-1 U pk

O(n2)

can be improved to O(nlgn)

Algorithms 3D Incremental

O(n2) time

CxHull Animations http//www.cse.unsw.edu.au/lam

bert/java/3d/hull.html

Algorithms 2D Divide-and-Conquer

source ORourke, Computational Geometry in C

- Divide-and-Conquer in a geometric setting
- O(n) merge step is the challenge
- Find upper and lower tangents
- Lower tangent find rightmost pt of A leftmost

pt of B then walk it downwards - Idea is extended to 3D in Chapter 4.

B

A

Algorithm DIVIDE-and-CONQUER Sort points by x

coordinate Divide points into 2 sets A and B A

contains left n/2 points B contains right n/2

points Compute ConvexHull(A) and ConvexHull(B)

recursively Merge ConvexHull(A) and ConvexHull(B)

O(nlgn)

Algorithms 3D Divide and Conquer

O(n log n) time !

CxHull Animations http//www.cse.unsw.edu.au/lam

bert/java/3d/hull.html

Lower Bound of O(nlgn)

source ORourke, Computational Geometry in C

- Worst-case time to find convex hull of n points

in algebraic decision tree model is in W(nlgn) - Proof uses sorting reduction
- Given unsorted list of n numbers (x1,x2 ,, xn)
- Form unsorted set of points (xi, xi2) for each

xi - Convex hull of points produces sorted list!
- Parabola every point is on convex hull
- Reduction is O(n) (which is o(nlgn))
- Finding convex hull of n points is therefore at

least as hard as sorting n points, so worst-case

time is in W(nlgn)

Parabola for sorting 2,1,3

Nearest Neighbor/ Closest Pair of Points

Closest Pair

Goal Given n (2D) points in a set Q, find the

closest pair under the Euclidean metric in O(n

lgn) time.

- Divide-and-Conquer Strategy
- X points sorted by increasing x
- Y points sorted by increasing y
- Divide partition with vertical line L into PL,

PR - Conquer recursively find closest pair in PL, PR
- dL, dR are closest-pair distances
- d min( dL, dR )
- Combine closest-pair is either d or pair

straddles partition line L - Check for pair straddling partition line L
- both points must be within d of L
- create array Y Y without points in 2d

strip - for each point p in Y
- find (lt 7) points in Y within d of p

source 91.503 textbook Cormen et al.

Closest Pair

Correctness

33.11

source 91.503 textbook Cormen et al.

Closest Pair

Running Time

Key Point Presort points, then at each step form

sorted subset of sorted array in linear time

source 91.503 textbook Cormen et al.