Top Banner
Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930
53

Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Dec 17, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Computational Geometry

Piyush Kumar(Lecture 3: Convexity and Convex hulls)

Welcome to CIS5930

Page 2: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convexity

A set S is convex if for any pair of points p,q S we have pq S.

p

q

non-convex

q

p

convex

Page 3: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex Hulls : Equivalent definitions

The intersection of all covex sets that contains P The intersection of all halfspaces that contains P. The union of all triangles determined by points in P. All convex combinations of points in P.

P here is a set of input points

Page 4: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex Hulls

Applications Collision Detection Fitting shapes Shape Approximation NN-Searching Useful as a preprocessing step to many

other algorithms in computational geometry. The most ubiquitous structure in computational

geometry.

Page 5: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex hulls

p0

p1p2

p4

p5

p6

p7

p8

p9

p11

p12

Extreme pointInt angle < pi

Extreme edgeSupports the point set

Page 6: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex hull : Representation

We will represent the convex hull by an enumeration of the vertices of the CH(P) in counterclockwise order. Naïve Algorithm to compute convex hulls can be implemented in O(n3) in the plane (How?) Anyone with an O(n2) algorithm?

Page 7: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex hull

has a lower bound equivalent to sorting has many similar algorithms to sorting. We will see today Graham Scan Incremental (one point at a time) D&C Qhull ( similar to Quick Sort) Jarvis March Chan’s Algorithm

Page 8: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Assignments for next week

Notes of Dr. Mount: Lec 1-4, 6Assignment2.cpp and ch_2.cpp Will talk more about it towards the

end of class.

Page 9: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Today (Jan 16th)

Line Segment intersection Homeworks / Projects

Page 10: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment Intersection

Applications VLSI (Intel uses it a lot) Map Overlay Clipping in Graphics CSG

Problem : Given a set of line segments in the plane, compute all the intersection point.

Page 11: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment Intersection : GIS

Cities, rivers, railroads and their overlay in western Canada.

Page 12: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment Intersection

Lower Bound from EUEU : Given a list of n numbers, are all these numbers unique? [Y / N]? Lower bound is Ω(nlogn) How do we use this fact to prove a Ω(nlogn)

on Line segment intersection problem? Does this imply a lower bound of Ω(nlogn+k)?

Tell me a naïve algorithm to solve this problem.

Page 13: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment intersection

Naïve O(n^2) Bentley Ottman sweep O((n+k)log n): 1979.Edelsbrunner Chazelle 92 O(nlogn +k) : Supercomplicated O(nlogn) space

Clarkson and Shor O(nlogn +k) Randmized O(n) space

Balaban : Deterministic O(nlogn + k) in O(n space. Solved a long open problem.

Page 14: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Segment Intersection

How do we intersect two segments? How do we implement such a primitive? CG FAQ 1.3 Any special cases?

Page 15: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Do two segments intersect?

Page 16: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Intersection point?

Solve for s, t. Beware of degenerate cases.

Compute_intersection_point primitive is one of the most time consuming parts of segment intersection algorithms.For speed: Floating point filters on rational arithmetic is used.

Page 17: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Point inside Simplex?

Page 18: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Today ( Jan 20th)

Line Segment intersection Algorithm Project discussion Polygons

Page 19: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment intersection

Sweep line paradigm Main idea is to sweep the entire

plane with a line and compute what we want to , as we sweep past the input.

Event scheduling and updates Carefully schedule the computation

so that it does not take too much time to compute the output.

Page 20: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Line Segment Intersection

A Sorted sequence data structure Insert Delete Successor/Predecessor All in O(log n)

X-structure (or the event queue) Y-structure (or the sweep line)

Page 21: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep ParadigmInitialization: Add all segment endpoints to the X-structure or event queue

(O(n log n)). Sweep line status is empty.

Algorithm proceeds by inserting and deleting discrete events from the queue until it is empty.

Page 22: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep

Page 23: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Pretend these never happened!

No line segment is verticalIf two segments intersect, then they intersect in a single point (that is, they are not collinear).No three line segments intersect in a common point.

Page 24: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Useful lemma Given si,sj intersecting in p, there is a placement of the sweepline prior to this event such that si,sj are adjacent along the sweepline. Just before an intersection occurs, the two relevant segments are adjacent to each other in the sweep line status.

Page 25: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Proof of Lemma

Page 26: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep

Event A: Segment left endpoint Insert segment in sweep line or

the Y-structure. Test for intersection to the right of

the sweep line with the segments immediately above and below it. Insert intersection points (if found) into X-structure or event queue.

Complexity: ? Worst case?

Page 27: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep : Left Endpoint

Page 28: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep – Algorithm

Event B: Segment right endpoint Delete segment from

sweep line status. Test for intersection to

the right of the sweep line between the segments immediately above and below. (can you do any optimization for this case? ) Insert point (if found) into event queue.

Complexity: ?

Page 29: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweet: Right endpoint

Page 30: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

A simple optimization: Right endpoints

When s is deleted, p gets recomputed. Avoid it using a hash?

Page 31: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane Sweep – AlgorithmEvent C: Intersection point Report the point. Swap the two line relevant

segments in the sweep line status.

For the new upper segment – test it against its predecessor for an intersection. Insert point (if found) into event queue.

Similar for new lower segment (with successor).

Complexity: O(klogn)

Page 32: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Plane sweep : Degenerate cases.

Page 33: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

The Simplified Algorithm

Construct the X-structure scan thru the X-structure (or the event queue) from left to right processing: Segment Left endpoint Segment right endpoint Intersection points

Page 34: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Handling Degeneracies

Page 35: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Polygon: Definition

Page 36: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Point in polygon test?

Page 37: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Polygons

Point containment in simple polygon Area of a simple polygon Convex hull of a simple polygon Triangulation of a simple polygon Fast preprocessing of a convex polygon to do in/out queries.

Page 38: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Area of a convex polygon

Page 39: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Area of a polygon

Page 40: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Area of a polygon

Page 41: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

From a distance

Page 42: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Area of a polyon

Page 43: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Volume in higher dimensions

Page 44: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Volume in 3D

Page 45: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Convex hull of poygons

Melkman’s Algorithm.Uses a deque: head-tail linked list, for which elements can be added to or removed from the front (head) or back (tail). Considered to be the best CH algorithm for simple polygons.

Page 46: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Melkman’s algorithm

Start with CH of 3 vertices = Triangle

Page 47: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

Points in the deque are circled in blue. The point N is special point stored separately. F and B are front and back vertices of deque.

Page 48: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

Next point on the polygon can only lie in the colored regions.Invariant : N followed by the vertices in the deque (front to back) form a convex polygon.

Page 49: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

If p falls into region I, push N onto the front of the deque, then overwrite N by p. To restore the invariant, backtrack/delete vertices from the front of the deque until a convex turn is encountered.

Page 50: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

If p falls into region II, push N onto the back of the deque, then overwrite N by p. Restore the invariant by backtracking/deleting vertices from the back of the deque until a convex turn is encountered.

Page 51: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

If p falls into region III, simply overwrite N by p, and restore the invariants as in both cases I and II.

Page 52: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Partition plane in 4 colors

If p falls into region IV , ignore this and all following vertices until one emerges into another region.

Page 53: Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.

Melkman’s algorithm

An example of online algorithm: meaning that points can be added in a streaming fashion.Very simple to code. Practical. Implemented in CGAL.