CS16: Introduction to Data Structures & Algorithms

Slides:



Advertisements
Similar presentations
Introduction to Algorithms
Advertisements

Polygon Triangulation
Computational Geometry
Computational Geometry - Part II Mohammed Nadeem Ahmed Raghavendra Kyatham.
2/9/06CS 3343 Analysis of Algorithms1 Convex Hull  Given a set of pins on a pinboard  And a rubber band around them  How does the rubber band look when.
Jarvis March Graham Scan Chan’s Algorithm
1/13/15CMPS 3130/6130: Computational Geometry1 CMPS 3130/6130: Computational Geometry Spring 2015 Convex Hulls Carola Wenk.
algorithms and data structures
Brute-Force Triangulation
Computing Convex Hulls CLRS 33.3
Convex Hull obstacle start end Convex Hull Convex Hull
C o m p u t i n g C O N V E X H U L L S by Kok Lim Low 10 Nov 1998 COMP Presentation.
Convex Hulls in Two Dimensions Definitions Basic algorithms Gift Wrapping (algorithm of Jarvis ) Graham scan Divide and conquer Convex Hull for line intersections.
CS4413 Divide-and-Conquer
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 6 Ack : Carola Wenk nad Dr. Thomas Ottmann tutorials.
By Groysman Maxim. Let S be a set of sites in the plane. Each point in the plane is influenced by each point of S. We would like to decompose the plane.
Advanced Topics in Algorithms and Data Structures Lecture 7.1, page 1 An overview of lecture 7 An optimal parallel algorithm for the 2D convex hull problem,
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
1 Convex Hull in Two Dimensions Jyun-Ming Chen Refs: deBerg et al. (Chap. 1) O’Rourke (Chap. 3)
Computational Geometry
8/29/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk.
Convex Hull Problem Presented By Erion Lin. Outline Convex Hull Problem Voronoi Diagram Fermat Point.
Computational Geometry for the Tablet PC
1 Today’s Material Computational Geometry Problems –Closest Pair Problem –Convex Hull Jarvis’s March, Graham’s scan –Farthest Point Problem.
Algorithms and Data Structures Lecture 13. Agenda: Plane Geometry: algorithms on polygons - Verification if point belongs to a polygon - Convex hull.
5/17/2015 1:32 AMConvex Hull1 obstacle start end.
What does that mean? To get the taste we will just look only at some sample problems... [Adapted from S.Suri]
ADA: 16. CG Topics1 Objective o an examination of four important CG topics o just a taster of a very large research area Algorithm Design and Analysis.
9/5/06CS 6463: AT Computational Geometry1 CS 6463: AT Computational Geometry Fall 2006 Plane Sweep Algorithms and Segment Intersection Carola Wenk.
November 4, Algorithms and Data Structures Lecture XIV Simonas Šaltenis Nykredit Center for Database Research Aalborg University
Computational Geometry Piyush Kumar (Lecture 3: Convexity and Convex hulls) Welcome to CIS5930.
6/2/ :35 AMIncremental Convex Hull1 q w u e zt.
Algorithm 1. (Convex Hull) - Pseudo code - Input. A set of points in the plane. Output. A list containing the vertices of Conv ( P). 1. Sort the points.
5 - 1 § 5 The Divide-and-Conquer Strategy e.g. find the maximum of a set S of n numbers.
Voronoi Diagrams.
Lection 1: Introduction Computational Geometry Prof.Dr.Th.Ottmann 1 History: Proof-based, algorithmic, axiomatic geometry, computational geometry today.
Advanced Algorithm Design and Analysis (Lecture 9) SW5 fall 2004 Simonas Šaltenis E1-215b
CSE53111 Computational Geometry TOPICS q Preliminaries q Point in a Polygon q Polygon Construction q Convex Hulls Further Reading.
Convex Hull. What is the Convex Hull? Imagine a set of points on a board with a nail hammered into each point. Now stretch a rubber band over all the.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
C o m p u t i n g C O N V E X H U L L S. Presentation Outline 2D Convex Hulls –Definitions and Properties –Approaches: Brute Force Gift Wrapping QuickHull.
Fundamental Data Structures and Algorithms Klaus Sutner April 27, 2004 Computational Geometry.
Fundamental Data Structures and Algorithms Margaret Reid-Miller 27 April 2004 Computational Geometry.
CMPS 3120: Computational Geometry Spring 2013
Convex Hull. University of Manchester biologists used lasers to measure the minimum amount of skin required to wrap around the skeletons of modern-day.
1 / 41 Convex Hulls in 3-space Jason C. Yang. 2 / 41 Problem Statement Given P: set of n points in 3-space Return: –Convex hull of P: CH (P) –Smallest.
Computer Graphics Filling. Filling Polygons So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental.
A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R. Otherwise, it is called concave.
COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.
Convex Hull 2012/10/23. Convex vs. Concave A polygon P is convex if for every pair of points x and y in P, the line xy is also in P; otherwise, it is.
CS6234 Advanced Algorithms - Convex hull. Terminologies – ◦ Convex hull of a set Q of points is the smallest convex polygon P for which each point in.
CLASSIFYING POLYGONS UNIT 1 LESSON 6. Classifying Polygons In geometry, a figure that lies in a plane is called a plane figure. A polygon is a closed.
Convex Sets & Concave Sets A planar region R is called convex if and only if for any pair of points p, q in R, the line segment pq lies completely in R.
Robert Pless, CS 546: Computational Geometry Lecture #3 Last time Several convex hull algorithms. Lower bound of O(n log n) –O(n log h) for output sensitive.
Convex Hulls Guo Qi, Chen Zhenghai, Wang Guanhua, Shen Shiqi, Himeshi De Silva.
Convex Hull R.L. Graham’s Algorithm Computer Graphics.
CMPS 3130/6130 Computational Geometry Spring 2017
Convex Hull.
Convex Hull obstacle start end 11/21/2018 4:05 AM Convex Hull
Computational Geometry Capter:1-2.1
Geometry.
Convex Sets & Concave Sets
Computational Geometry for the Tablet PC
Convex Hull 1/1/ :28 AM Convex Hull obstacle start end.
CMPS 3130/6130: Computational Geometry Spring 2017
Convex Hull obstacle start end 4/30/2019 5:21 PM Convex Hull
Introduction to Algorithms
Computational Geometry Algorithms
Geometry.
Algorithms and Data Structures Lecture XIV
Presentation transcript:

CS16: Introduction to Data Structures & Algorithms Thursday March 12, 2015 Convex Hull CS16: Introduction to Data Structures & Algorithms

Outline Overview Convex Hull Overview Graham Scan Algorithm Thursday March 12, 2015 Outline Overview Convex Hull Overview Graham Scan Algorithm Incremental Algorithm

Thursday March 12, 2015 Convex Hull The convex hull of a set of points is the smallest convex polygon containing the points A convex polygon is a nonintersecting polygon whose internal angles are all convex (i.e., less than 180 degrees) In a convex polygon, a segment joining any two lies entirely inside the polygon segment not contained! convex nonconvex

Convex Hull (2) Think of a rubber band snapping around the points Thursday March 12, 2015 Convex Hull (2) Think of a rubber band snapping around the points Remember to think of special cases Colinearity: A point that lies on a segment of the convex is not included in the convex hull

Applications Motion planning Thursday March 12, 2015 Applications Motion planning Find an optimal route that avoids obstacles for a robot Bounding Box Obtain a closer bounding box in computer graphics Pattern Matching Compare two objects using their convex hulls obstacle start end

Thursday March 12, 2015 Finding a Convex Hull One algorithm for determining a convex polygon is one which, when following the points in counterclockwise order, always produces left-turns

Calculating Orientation Thursday March 12, 2015 Calculating Orientation a b c The orientation of three points (a, b, c) in the plane is clockwise, counterclockwise, or collinear Clockwise (CW): right turn Counterclockwise (CCW): left turn Collinear (COLL): no turn The orientation of three points is characterized by the sign of the determinant Δ(a, b, c) CW c b CCW a c b a COLL function isLeftTurn(a, b, c): return (b.x - a.x)*(c.y - a.y)– (b.y - a.y)*(c.x - a.x) > 0

Calculating Orientation (2) Thursday March 12, 2015 Calculating Orientation (2) Using the isLeftTurn() method: (0.5-0) * (0.5 - 0) - (1-0) * (1-0) = -0.75 (CW) (1-0) * (1-0) - (0.5-0) * (0.5-0) = 0.75 (CCW) (1-0) * (2-0) - (1-0) * (2-0) = 0 (COLL) a (0,0) b (0.5,1) c (1, 0.5) CW c (0.5,1) b (1, 0.5) CCW a (0,0) c(2,2) b(1,1) a(0,0) COLL

Calculating Orientation (3) Thursday March 12, 2015 Calculating Orientation (3) Let a, b, c be three consecutive vertices of a polygon, in counterclockwise order b’ is not included in the hull if a’, b,’ c’ is non-convex, i.e. orientation(a’, b’, c’) = CW or COLL b is included in the hull if a, b, c is convex, i.e. orientation(a, b, c) = CCW, and all other non-hull points have been removed c’ c b’ a’ b a

Thursday March 12, 2015 Graham Scan Algorithm Find the anchor point (the point with the smallest y value) Sort points in CCW order around the anchor You can sort points by comparing the angle between the anchor and the point you’re looking at (the smaller the angle, the closer the point) 4 7 5 6 3 8 2 Anchor 1

Thursday March 12, 2015 Graham Scan Algorithm The polygon is traversed in sorted order and a sequence H of vertices in the hull is maintained For each point a, add a to H While the last turn is a right turn, remove the second to last point from H In the image below, p, q, r forms a right turn, and thus q is removed from H. Similarly, o, p, r forms a right turn, and thus p is removed from H. p q r H o p r H n o r H

Graham Scan: Pseudocode Thursday March 12, 2015 Graham Scan: Pseudocode function graham_scan(pts): // Input: Set of points pts // Output: Hull of points find anchor point sort other points in CCW order around anchor hull = [] for p in pts: add p to hull while last turn is a “right turn” remove 2nd to last point add anchor to hull return hull Work on a diagram on the board B D C A P Hull: A few more pieces “sort in counter-clockwise order” X coordinate of normalized vector from P to any Q works for the sort it is the cos of angle with x axis (Side adjacent over hypotenuse (1)) V = (A – P) / | A-P | Sort according to V.x Right or left turn: Given points A B C take cross product of BA and BC answer is perpendicular to plane and follows right/left hand rule for in vs. out of plane so size of the z coordinate Sign of (Ax-Bx)(Cy-By) – (Ay-By)(Cx-Bx) gives turn direction if positive, left turn if negative, right turn (or maybe vice versa; depends on handedness of coordinate system) Complexity O(n) O(n log n) Loop: O(n) while: O(1) times amortized, since max n points can be removed Note: this is very high-level pseudocode. There are many special cases to consider!

Overall run time: O(nlogn) Thursday March 12, 2015 Graham Scan: Run Time function graham_scan(pts): // Input: Set of points pts // Output: Hull of points find anchor point // O(n) sort other points in CCW order around anchor // O(nlogn) create hull (empty list representing ordered points) for p in pts: // O(n) add p to hull while last turn is a “right turn” // O(1) amortized remove 2nd to last point add anchor to hull return hull Overall run time: O(nlogn)

Incremental Algorithm Thursday March 12, 2015 Incremental Algorithm What if we already have a convex hull, and we just want to add one point q? This is what you’ll be doing on the Java project after heap! Get the angle from the anchor to q and find points p and r, the hull points on either side of q If p, q, r forms a left turn, add q to the hull Check if adding q creates a concave shape If you have right turns on either side of q, remove vertices until the shape becomes convex This is done in the same way as the static Graham Scan

Incremental Algorithm Thursday March 12, 2015 Incremental Algorithm Original Hull: Want to add point q: Find p and r: q H q H H p r p, q, r forms a left turn, so add q: o, p, q forms a right turn, so remove p n, o, q forms a right turn, so remove o p r q H r q H o n r q H n n o s s s

Incremental Algorithm Thursday March 12, 2015 Incremental Algorithm Since m, n, q is a left turn, we’re done with that side. Now we look at the other side: Since q, r, s is a left turn, we’re done! r q H q H r q H n m s s Remember that you can have right turns on either or both sides, so make sure to check in both directions and remove concave points!

Thursday March 12, 2015 Incremental Analysis Let n be the current size of the convex hull, stored in a binary search tree for efficiency How are they sorted? Around the anchor To check if a point q should be in the hull, we insert it into the tree and get its neighbors (p and r on the prior slides) in O(log n) time We then traverse the ring, possibly deleting d points from the convex hull in O((1 + d) log n) time Therefore, incremental insertion is O(d log n) where d is the number of points removed by the insertion