44
UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Computational Geometry Overview from Cormen, et al. Overview from Cormen, et al. Chapter 33 Chapter 33

UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

UMass Lowell Computer Science 91.503 Graduate Algorithms

Prof. Karen Daniels Spring, 2009

UMass Lowell Computer Science 91.503 Graduate Algorithms

Prof. Karen Daniels Spring, 2009

Computational GeometryComputational GeometryOverview from Cormen, et al.Overview from Cormen, et al.

Chapter 33Chapter 33

Page 2: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

OverviewOverview

Computational Geometry IntroductionComputational Geometry Introduction

Line Segment Intersection Line Segment Intersection

Convex Hull AlgorithmsConvex Hull Algorithms

Nearest Neighbors/Closest PointsNearest Neighbors/Closest Points

Page 3: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

IntroductionIntroduction

What is What is

Computational Geometry?Computational Geometry?

Page 4: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Applied Computational Geometry ResearchAssoc. Prof. Karen Daniels & CollaboratorsApplied Computational Geometry ResearchAssoc. Prof. Karen Daniels & Collaborators

Clustering, Clustering, for for Data Data MiningMining

Packing for Packing for ManufacturingManufacturing

Design Analyze

Apply

for for covering, clustering, packing, layout, geometric covering, clustering, packing, layout, geometric

modelingmodeling

feasibility, estimation, optimization problemsfeasibility, estimation, optimization problemsCovering for Covering for Geometric Geometric ModelingModeling

Meshing Meshing for for Geometric Geometric Modeling Modeling

Courtesy of Cadence Design SystemsCourtesy of Cadence Design Systems

Topological Invariant Topological Invariant Estimation for Estimation for Geometric Modeling Geometric Modeling

Page 5: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Typical ProblemsTypical Problems

bin packingbin packing

Voronoi diagramVoronoi diagram simplifying simplifying

polygonspolygons

shape similarityshape similarity

convex hullconvex hull

maintaining line maintaining line arrangementsarrangements

polygon partitioningpolygon partitioning nearest neighbor nearest neighbor

searchsearch

kd-treeskd-trees

SOURCESOURCE: Steve Skiena’s Algorithm Design Manual : Steve Skiena’s Algorithm Design Manual

(for problem descriptions, see graphics gallery at (for problem descriptions, see graphics gallery at http://www.cs.sunysb.edu/~algorith))

Page 6: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Common Computational Geometry StructuresCommon Computational Geometry Structures

Voronoi DiagramVoronoi DiagramConvex HullConvex Hull

New PointNew Point

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Delaunay TriangulationDelaunay Triangulation

Page 7: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Sample Tools of the TradeSample Tools of the Trade

Algorithm Design Patterns/Techniques:Algorithm Design Patterns/Techniques:binary searchbinary search divide-and-conquerdivide-and-conquer dualitydualityrandomizationrandomization sweep-linesweep-line incremental incrementalderandomizationderandomization parallelismparallelism

Algorithm Analysis Techniques:Algorithm Analysis Techniques:asymptotic analysis, amortized analysisasymptotic analysis, amortized analysis

Data Structures:Data Structures:winged-edge, quad-edge, winged-edge, quad-edge, range tree, kd-treerange tree, kd-tree

Theoretical Computer ScienceTheoretical Computer Science principles:principles:NP-completeness, hardnessNP-completeness, hardness

Growth of FunctionsGrowth of Functions

SummationsSummations

RecurrencesRecurrences

SetsSets

ProbabilityProbability

MATHMATH ProofsProofs GeometryGeometry

Graph TheoryGraph TheoryCombinatoricsCombinatorics

Linear AlgebraLinear Algebra

Page 8: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Computational Geometryin Context

Computational Geometryin Context

TheoreticalTheoreticalComputerComputer

ScienceScience

Applied Computer ScienceApplied Computer Science

AppliedAppliedMathMath

GeometryGeometry

ComputationalComputationalGeometryGeometry

Efficient Efficient Geometric AlgorithmsGeometric Algorithms

Design Analyze

Apply

Page 9: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Line Segment Intersections(2D)

Line Segment Intersections(2D)

Intersection of 2 Line SegmentsIntersection of 2 Line SegmentsIntersection of > 2Line SegmentsIntersection of > 2Line Segments

Page 10: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Cross-Product-Based Geometric PrimitivesCross-Product-Based Geometric Primitives

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp00

pp22

pp11

(1)(1)

pp11

pp33

pp22

(2)(2)

pp22

pp11

pp33

pp44

(3)(3)

Some fundamental geometric questions:Some fundamental geometric questions:

Page 11: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Cross-Product-Based Geometric Primitives: (1)Cross-Product-Based Geometric Primitives: (1)

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.AdvantageAdvantage: less sensitive to accumulated round-off error: less sensitive to accumulated round-off error

122121

2121 det yxyx

yy

xxpp

pp00

pp22

pp11

(1)(1)

33.1

Page 12: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Cross-Product-Based Geometric Primitives: (2)Cross-Product-Based Geometric Primitives: (2)

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp00

pp22

pp11

(2)(2)

33.2

Page 13: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Intersection of 2 Line SegmentsIntersection of 2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

pp22

pp11

pp33

pp44

(3)(3)

Step 1Step 1: : Bounding Box Bounding Box TestTest

Step 2Step 2: Does each : Does each segment straddle segment straddle the line containing the line containing the other?the other?

33.3

p3 and p4 on opposite sides of p1p2p3 and p4 on opposite sides of p1p2

Page 14: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Segment-Segment IntersectionSegment-Segment Intersection

Finding the Finding the actual intersection pointactual intersection point Approach: parametric vs. slope/interceptApproach: parametric vs. slope/intercept

parametric generalizes to more complex intersectionsparametric generalizes to more complex intersections e.g. segment/trianglee.g. segment/triangle

Parameterize each segmentParameterize each segment

Intersection: values of Intersection: values of ss, , tt such that such that p(s)p(s) = =q(t)q(t) : : a+sAa+sA==c+tCc+tC

aa

bbcc

dd

LLababLLcdcd

aa

bbcc

dd

LLababLLcdcd

A=b-aA=b-a

p(s)=a+sAp(s)=a+sA

q(t)=c+tCq(t)=c+tCC=d-cC=d-c

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

2 equations in unknowns 2 equations in unknowns ss, , tt : 1 for x, 1 for y : 1 for x, 1 for y

Page 15: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Segment/Segment IntersectionSegment/Segment Intersectionhttp://cs.smith.edu/~orourke/books/CompGeom/http://cs.smith.edu/~orourke/books/CompGeom/

CompGeom.htmlCompGeom.html

Page 16: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Sweep-Line Algorithmic Paradigm:Sweep-Line Algorithmic Paradigm:

33.4

Page 17: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Sweep-Line Algorithmic Paradigm:Sweep-Line Algorithmic Paradigm:

Page 18: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Intersection of >2 Line SegmentsIntersection of >2 Line Segments

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Time to Time to detectdetect if any 2 if any 2

segments intersect:segments intersect:O(n lg n)O(n lg n)

source: 91.503 textbook Cormen et al.

33.5

Note that it exits as soon as Note that it exits as soon as oneone intersection is detected. intersection is detected.

Balanced BST stores segments in order Balanced BST stores segments in order of intersection with sweep line. of intersection with sweep line. Associated operations take O(lgn) time.Associated operations take O(lgn) time.

Page 19: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Intersection of SegmentsIntersection of Segments

GoalGoal: “Output-size sensitive” line segment intersection algorithm : “Output-size sensitive” line segment intersection algorithm that actually computes that actually computes allall intersection points intersection points

Bentley-Ottmann plane sweep: Bentley-Ottmann plane sweep: O((n+k)log(n+k))= O((n+k)logn) O((n+k)log(n+k))= O((n+k)logn) timetime k = number of intersection points in outputk = number of intersection points in output Intuition: sweep horizontal line downwardsIntuition: sweep horizontal line downwards

just before intersection, 2 segments are adjacent in sweep-line intersection structurejust before intersection, 2 segments are adjacent in sweep-line intersection structure check for intersection check for intersection onlyonly adjacent segments adjacent segments insert intersection event into sweep-line structureinsert intersection event into sweep-line structure event types:event types:

top endpoint of a segmenttop endpoint of a segment bottom endpoint of a segmentbottom endpoint of a segment intersection between 2 segmentsintersection between 2 segments

swap order swap order

Improved to O(nlogn+k) [Chazelle/Edelsbrunner]Improved to O(nlogn+k) [Chazelle/Edelsbrunner]source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 20: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Convex Hull AlgorithmsConvex Hull Algorithms

DefinitionsDefinitionsGift WrappingGift WrappingGraham ScanGraham Scan

QuickHullQuickHullIncrementalIncremental

Divide-and-ConquerDivide-and-ConquerLower Bound in Lower Bound in (nlgn)(nlgn)

Page 21: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Convexity & Convex HullsConvexity & Convex Hulls

A convex combination of points A convex combination of points xx11, ..., , ..., xxkk is a sum of the form is a sum of the form

11xx11+...++...+ kkxxkk where where

Convex hull of a set of points is the Convex hull of a set of points is the set of all convex combinations of set of all convex combinations of points in the set.points in the set.

nonconvex polygonnonconvex polygon

convex hull of a point setconvex hull of a point set

10 1 ki andi

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 22: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Naive Algorithms for Extreme PointsNaive Algorithms for Extreme Points

AlgorithmAlgorithm: INTERIOR POINTS: INTERIOR POINTSfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do

for each L = k = j = i do for each L = k = j = i do if pif pL L in triangle(pin triangle(pii, p, pjj, p, pkk))

then pthen pLL is nonextreme is nonextreme O(nO(n44))

AlgorithmAlgorithm: EXTREME EDGES: EXTREME EDGESfor each i dofor each i do for each j = i dofor each j = i do for each k = j = i dofor each k = j = i do

if pif pk k is not left or on (pis not left or on (pii, p, pjj))

then (pthen (pi i , p, pjj) is not extreme) is not extreme O(nO(n33))source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 23: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 2D Gift WrappingAlgorithms: 2D Gift Wrapping

Use one extreme edge as an Use one extreme edge as an anchor for finding the nextanchor for finding the next

O(nO(n22))

AlgorithmAlgorithm: GIFT WRAPPING: GIFT WRAPPING

ii00 index of the lowest point index of the lowest point

i ii i00repeatrepeat for each j = ifor each j = i Compute counterclockwise angle Compute counterclockwise angle from previous hull edge from previous hull edge k index of point with smallest k index of point with smallest Output (pOutput (pi i , p, pkk) as a hull edge) as a hull edge i ki kuntil i = iuntil i = i00

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 24: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Gift WrappingGift Wrapping source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.9

Output SensitivityOutput Sensitivity: O(n: O(n22) run-time is actually O(nh) ) run-time is actually O(nh) where h is the number of vertices of the convex hull.where h is the number of vertices of the convex hull.

Page 25: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 3D Gift Wrapping Algorithms: 3D Gift Wrapping

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(nO(n22)) time time

[output sensitive: O(nF) for F faces on hull][output sensitive: O(nF) for F faces on hull]

Page 26: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 2D QuickHullAlgorithms: 2D QuickHull

Concentrate on points close to Concentrate on points close to hull boundaryhull boundary

Named for similarity to Named for similarity to Quicksort Quicksort

aa

bb

O(nO(n22))

AlgorithmAlgorithm: QUICK HULL: QUICK HULL

function QuickHull(a,b,S)function QuickHull(a,b,S)

if S = 0 return()if S = 0 return() elseelse c index of point with max distance from abc index of point with max distance from ab A points strictly right of (a,c)A points strictly right of (a,c) B points strictly right of (c,b)B points strictly right of (c,b) return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)return QuickHull(a,c,A) + (c) + QuickHull(c,b,B)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

finds one of upper or lower hullfinds one of upper or lower hull

cc

AA

Page 27: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 3D QuickHullAlgorithms: 3D QuickHull

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

Page 28: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: >= 2D Algorithms: >= 2D

Qhull: http://www.qhull.org/Qhull: http://www.qhull.org/

Convex Hull Convex Hull boundary is boundary is intersection of intersection of hyperplanes, so hyperplanes, so worst-case worst-case combinatorial size combinatorial size (not necessarily running (not necessarily running

time)time) complexity is complexity is in:in: )( 2/dn

Page 29: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham’s AlgorithmGraham’s Algorithm

Points sorted angularly provide Points sorted angularly provide “star-shaped” starting point“star-shaped” starting point

Prevent “dents” as you go via Prevent “dents” as you go via convexity testingconvexity testing

O(nlgn)O(nlgn)

AlgorithmAlgorithm: GRAHAM SCAN: GRAHAM SCAN

Find rightmost lowest point; label it pFind rightmost lowest point; label it p00..

Sort all other points angularly about pSort all other points angularly about p00.. In case of tie, delete point(s) closer to pIn case of tie, delete point(s) closer to p00..Stack S (pStack S (p11, p, p00) = (p) = (ptt, p, pt-1t-1); t indexes top); t indexes topi 2i 2while i < n dowhile i < n do

if pif pii is strictly left of p is strictly left of pt-1t-1pptt

then Push(pthen Push(pii, S) and set i i +1, S) and set i i +1else Pop(S)else Pop(S)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

““multipop”multipop”

pp00

Page 30: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 31: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.7

Page 32: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

33.7

Page 33: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 34: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Graham ScanGraham Scan

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Page 35: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 2D IncrementalAlgorithms: 2D Incremental

Add points, one at a timeAdd points, one at a time update hull for each new pointupdate hull for each new point

Key step becomes adding a single point Key step becomes adding a single point to an existing hull.to an existing hull. Find 2 tangentsFind 2 tangents

Results of 2 consecutive LEFT tests differResults of 2 consecutive LEFT tests differ

Idea can be extended to 3D.Idea can be extended to 3D.

O(nO(n22))

AlgorithmAlgorithm: INCREMENTAL ALGORITHM: INCREMENTAL ALGORITHM

Let HLet H22 ConvexHull{p ConvexHull{p0 0 , p, p1 1 , p, p2 2 }}

for k 3 to n - 1 dofor k 3 to n - 1 do HHkk ConvexHull{ H ConvexHull{ Hk-1 k-1 U pU pk k }}

can be improved to O(nlgn)can be improved to O(nlgn)

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 36: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 3D Incremental Algorithms: 3D Incremental

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(nO(n22)) time time

Page 37: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 2D Divide-and-ConquerAlgorithms: 2D Divide-and-Conquer

Divide-and-Conquer in a geometric settingDivide-and-Conquer in a geometric setting O(n) merge step is the challengeO(n) merge step is the challenge

Find upper and lower tangentsFind upper and lower tangents Lower tangent: find rightmost pt of A & Lower tangent: find rightmost pt of A &

leftmost pt of B; then “walk it downwards”leftmost pt of B; then “walk it downwards” Idea can be extended to 3D.Idea can be extended to 3D.

AlgorithmAlgorithm: DIVIDE-and-CONQUER: DIVIDE-and-CONQUER

Sort points by x coordinateSort points by x coordinate

Divide points into 2 sets A and B:Divide points into 2 sets A and B:

A contains left n/2 pointsA contains left n/2 points

B contains right n/2 pointsB contains right n/2 points

Compute ConvexHull(A) and ConvexHull(B) recursivelyCompute ConvexHull(A) and ConvexHull(B) recursively

Merge ConvexHull(A) and ConvexHull(B) Merge ConvexHull(A) and ConvexHull(B) O(nlgn)O(nlgn)

AABB

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 38: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Algorithms: 3D Divide and Conquer Algorithms: 3D Divide and Conquer

CxHull AnimationsCxHull Animations: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html: http://www.cse.unsw.edu.au/~lambert/java/3d/hull.html

O(n log n)O(n log n) time ! time !

Page 39: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Lower Bound of O(nlgn)Lower Bound of O(nlgn)

Worst-case time to find convex hull of n points Worst-case time to find convex hull of n points in algebraic decision tree model is in in algebraic decision tree model is in (nlgn)(nlgn)

Proof uses sorting reduction:Proof uses sorting reduction: Given unsorted list of n numbers: (xGiven unsorted list of n numbers: (x11,x,x2 2 ,…, x,…, xnn)) Form unsorted set of points: (xForm unsorted set of points: (xii, x, xii

22) for each x) for each xii

Convex hull of points produces Convex hull of points produces sorted listsorted list!! Parabola: every point is on convex hullParabola: every point is on convex hull

Reduction is O(n) (which is in o(nlgn))Reduction is O(n) (which is in o(nlgn)) Finding convex hull of n points is therefore at least Finding convex hull of n points is therefore at least

as hard as sorting n points, so worst-case time is in as hard as sorting n points, so worst-case time is in (nlgn)(nlgn)

Parabola for sorting 2,1,3Parabola for sorting 2,1,3

source: O’Rourke, Computational Geometry in Csource: O’Rourke, Computational Geometry in C

Page 40: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Nearest Neighbor/Closest Pair of Points

Nearest Neighbor/Closest Pair of Points

Page 41: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Closest PairClosest Pair

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

GoalGoal: Given n (2D) points in a set Q, find the closest pair : Given n (2D) points in a set Q, find the closest pair under the Euclidean metric in under the Euclidean metric in O(n lgn)O(n lgn) time. 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

- L, R are closest-pair distances- min( L, R )-Combine: closest-pair is either or pair straddles partition line L- Check for pair straddling partition line L- both points must be within of L- create array Y’ = Y with only points in 2 strip- for each point p in Y’- find (<= 7) points in Y’ within of p

Page 42: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Closest PairClosest Pair

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.

Correctness

33.11

Page 43: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Closest PairClosest Pair

Running Time:

Key PointKey Point: Presort points, then at each step form : Presort points, then at each step form sorted subset of sorted array in linear timesorted subset of sorted array in linear time

)lg(3 if)1(

3 if)()2/(2)( nnO

nO

nnOnTnT

Like opposite of MERGE step in MERGESORT…Like opposite of MERGE step in MERGESORT…

source: 91.503 textbook Cormen et al.source: 91.503 textbook Cormen et al.RR

LL

Page 44: UMass Lowell Computer Science 91.503 Graduate Algorithms Prof. Karen Daniels Spring, 2009 Computational Geometry Overview from Cormen, et al. Chapter 33

Additional Computational Geometry ResourcesAdditional Computational Geometry Resources

Computational Geometry in C, 2nd editionComputational Geometry in C, 2nd edition by Joseph O’Rourkeby Joseph O’Rourke Cambridge University PressCambridge University Press 19981998

Computational Geometry: Algorithms & ApplicationsComputational Geometry: Algorithms & Applications by deBerg by deBerg et alet al.. SpringerSpringer 19981998

web site: http://cs.smith.edu/~orourke/books/compgeom.html

See also 91.504 Course Web Site (and its additional resources): http://www.cs.uml.edu/~kdaniels/courses/ALG_504.html