Title: UMass%20Lowell%20Computer%20Science%2091.503%20Graduate%20Algorithms%20Prof.%20Karen%20Daniels%20Spring,%202005
1 UMass Lowell Computer Science 91.503 Graduate
AlgorithmsProf. Karen Daniels Spring, 2005
- Computational Geometry
- Overview from Cormen, et al.
- Chapter 33
2Overview
- Computational Geometry Introduction
- Line Segment Intersection
- Convex Hull Algorithms
- Nearest Neighbors/Closest Points
3Introduction
- What is
- Computational Geometry?
4Computational Geometry
Computer Graphics
Visualization
Design
Analyze
Core Geometric Algorithms
CAD
Application-Based Algorithms
Apply
Telecommunications
5Sample Application Areas
Data Mining Visualization
Bioinformatics
Medical Imaging
Telecommunications
6Typical 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)
7Common Computational Geometry Structures
source ORourke, Computational Geometry in C
8Sample 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
9Computational Geometryin Context
10Sample of Supporting Algorithmic Math Areas
Techniques
- Algorithm Design Patterns
- search space subdivision
- binary search
- divide-and-conquer
- sweep-line
- discrete-event simulation
- Algorithm Analysis Techniques
- Complexity Theory
- NP-completeness, hardness
- Discrete Math
- Minkowski sum
- Monotone matrices
- Lattices
- Set operations union, intersection, difference
- Computational Geometry
- Convex hulls
- Visibility polygons
- Arrangements
- Mathematical Programming
- Linear programming
- Integer programming
- Lagrangian relaxation
- Upper, lower bounding
- Dynamic Data Structures
11Line Segment Intersections(2D)
- Intersection of 2 Line Segments
- Intersection of gt 2Line Segments
12Cross-Product-Based Geometric Primitives
Some fundamental geometric questions
source 91.503 textbook Cormen et al.
(1)
13Cross-Product-Based Geometric Primitives (1)
33.1
Advantage less sensitive to accumulated
round-off error
source 91.503 textbook Cormen et al.
14Cross-Product-Based Geometric Primitives (2)
33.2
source 91.503 textbook Cormen et al.
15Intersection of 2 Line Segments
Step 1 Bounding Box Test
p3 and p4 on opposite sides of p1p2
33.3
Step 2 Does each segment straddle the line
containing the other?
source 91.503 textbook Cormen et al.
16Segment-Segment Intersection
- Finding the actual intersection point
- Approach parametric vs. slope/intercept
- parametric generalizes to more complex
intersections - e.g. segment/triangle
- Parameterize each segment
Intersection values of s, t such that p(s) q(t)
asActC
2 equations in unknowns s, t 1 for x, 1 for y
source ORourke, Computational Geometry in C
17Demo
- Segment/Segment Intersection
- http//cs.smith.edu/orourke/books/CompGeom/CompGe
om.html
18Intersection of gt2 Line Segments
Sweep-Line Algorithmic Paradigm
33.4
source 91.503 textbook Cormen et al.
19Intersection of gt2 Line Segments
Sweep-Line Algorithmic Paradigm
source 91.503 textbook Cormen et al.
20Intersection of gt2 Line Segments
Time to detect if any 2 segments intersectO(n lg
n)
Balanced BST stores segments in order of
intersection with sweep line. Associated
operations take O(lgn) time.
Note that it exits as soon as one intersection is
detected.
33.5
source 91.503 textbook Cormen et al.
source 91.503 textbook Cormen et al.
21Intersection of Segments
- Goal Output-size sensitive line segment
intersection algorithm that actually computes all
intersection points - Bentley-Ottmann plane sweep O((nk)log(nk))
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 adjacent segments
- insert intersection event into sweep-line
structure - event types
- top endpoint of a segment
- bottom endpoint of a segment
- intersection between 2 segments
- swap order
Improved to O(nlognk) Chazelle/Edelsbrunner
source ORourke, Computational Geometry in C
22Convex Hull Algorithms
- Definitions
- Gift Wrapping
- Graham Scan
- QuickHull
- Incremental
- Divide-and-Conquer
- Lower Bound in W(nlgn)
23Convexity 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.
24Naive Algorithms for Extreme Points
O(n4)
source ORourke, Computational Geometry in C
25Algorithms 2D Gift Wrapping
- Use one extreme edge as an anchor for finding the
next
Algorithm GIFT WRAPPING i0 index of the
lowest point i i0 repeat for each j
i Compute counterclockwise angle q
from previous hull edge k index of
point with smallest q Output (pi , pk) as
a hull edge i k until i i0
O(n2)
source ORourke, Computational Geometry in C
26Gift Wrapping
source 91.503 textbook Cormen et al.
33.9
Output Sensitivity O(n2) run-time is actually
O(nh) where h is the number of vertices of the
convex hull.
27Algorithms 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
28Algorithms 2D QuickHull
- Concentrate on points close to hull boundary
- Named for similarity to Quicksort
a
b
A
c
finds one of upper or lower hull
source ORourke, Computational Geometry in C
29Algorithms 3D QuickHull
CxHull Animations http//www.cse.unsw.edu.au/lam
bert/java/3d/hull.html
30Algorithms gt 2D
Convex Hull boundary is intersection of
hyperplanes, so worst-case combinatorial size
(not necessarily running time) complexity is in
Qhull http//www.geom.umn.edu/software/qhull/
31Grahams Algorithm
source ORourke, Computational Geometry in C
- Points sorted angularly provide star-shaped
starting point - Prevent dents as you go via convexity testing
p0
multipop
32Graham Scan
source 91.503 textbook Cormen et al.
33Graham Scan
33.7
source 91.503 textbook Cormen et al.
34Graham Scan
33.7
source 91.503 textbook Cormen et al.
35Graham Scan
source 91.503 textbook Cormen et al.
36Graham Scan
source 91.503 textbook Cormen et al.
37Algorithms 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. - Find 2 tangents
- Results of 2 consecutive LEFT tests differ
- Idea can be extended to 3D.
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)
38Algorithms 3D Incremental
O(n2) time
CxHull Animations http//www.cse.unsw.edu.au/lam
bert/java/3d/hull.html
39Algorithms 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 can be extended to 3D.
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)
40Algorithms 3D Divide and Conquer
O(n log n) time !
CxHull Animations http//www.cse.unsw.edu.au/lam
bert/java/3d/hull.html
41Lower 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 in 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
42Nearest Neighbor/Closest Pair of Points
43Closest 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 with only 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.
44Closest Pair
Correctness
33.11
source 91.503 textbook Cormen et al.
45Closest Pair
Running Time
Key Point Presort points, then at each step form
sorted subset of sorted array in linear time
Like opposite of MERGE step in MERGESORT
46Additional Computational Geometry Resources
- Computational Geometry in C
- second edition
- by Joseph ORourke
- Cambridge University Press
- 1998
Web Site http//cs.smith.edu/orourke/books/compg
eom.html
See also 91.504 Course Web Site
http//www.cs.uml.edu/kdaniels/courses/ALG_504.ht
ml