CS 410/584, Algorithm Design & Analysis, Lecture Notes 8

Similar documents
CS 410/584, Algorithm Design & Analysis, Lecture Notes 8!

Computational geometry

Convex Hull Algorithms

CS 532: 3D Computer Vision 14 th Set of Notes

Computational Geometry. Algorithm Design (10) Computational Geometry. Convex Hull. Areas in Computational Geometry

Graduate Algorithms CS F-19 Computational Geometry

Computational Geometry

Planar convex hulls (I) Computational Geometry [csci 3250] Laura Toma Bowdoin College

The convex hull of a set Q of points is the smallest convex polygon P for which each point in Q is either on the boundary of P or in its interior.

A Minimalist s Implementation of the 3-d Divide-and-Conquer Convex Hull Algorithm

Computational Geometry 2D Convex Hulls. Joseph S. B. Mitchell Stony Brook University

Computational Geometry. Geometry Cross Product Convex Hull Problem Sweep Line Algorithm

Computational Geometry

CSE 5311 Notes 13: Computational Geometry

1/60. Geometric Algorithms. Lecture 1: Introduction. Convex Hulls

Algorithms and Data Structures

CS4733 Class Notes. 1 2-D Robot Motion Planning Algorithm Using Grown Obstacles

Prof. Gill Barequet. Center for Graphics and Geometric Computing, Technion. Dept. of Computer Science The Technion Haifa, Israel

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Cross products. p 2 p. p p1 p2. p 1. Line segments The convex combination of two distinct points p1 ( x1, such that for some real number with 0 1,

CS6100: Topics in Design and Analysis of Algorithms

Advanced Algorithm Homework 4 Results and Solutions

Lecture 3: Art Gallery Problems and Polygon Triangulation

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Computer Graphics 7 - Rasterisation

CS S Lecture February 13, 2017

Computational Geometry 2D Convex Hulls

Line segment intersection. Family of intersection problems

Computational Geometry TOPICS Preliminaries Point in a Polygon Polygon Construction Convex Hulls

External-Memory Algorithms with Applications in GIS - (L. Arge) Enylton Machado Roberto Beauclair

COMPUTING CONSTRAINED DELAUNAY

Triangulation and Convex Hull. 8th November 2018

Stacks API and finding the convex hull. CS Spring 2017

Why Graham-Scan Needs to Sort Vertices Before Scanning

Week 8 Voronoi Diagrams

Computational Geometry. HKU ACM ICPC Training 2010

Computational Geometry Overview from Cormen, et al.

Computational Geometry

Lecture 4: Geometric Algorithms (Convex Hull, Voronoi diagrams)

Lecture 16: Voronoi Diagrams and Fortune s Algorithm

Lecture 7: Computational Geometry

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Spring, 2010

COS 226 Lecture 15: Geometric algorithms. Warning: intuition may mislead (continued)

Solutions to problem set 1

Figure 2.1: An example of a convex set and a nonconvex one.

Visibility Graph. How does a Mobile Robot get from A to B?

High-Dimensional Computational Geometry. Jingbo Shang University of Illinois at Urbana-Champaign Mar 5, 2018

External Memory Algorithms for Geometric Problems. Piotr Indyk (slides partially by Lars Arge and Jeff Vitter)

Notes and Answers to Homework Exam 1, Geometric Algorithms, 2017

Geometric Algorithms. 1. Objects

5.4 Closest Pair of Points

COMPUTATIONAL GEOMETRY

CSE 546, Fall, 2016 Homework 1

Closest Pair of Points. Cormen et.al 33.4

I/O-Algorithms Lars Arge Aarhus University

Polygon Partitioning. Lecture03

Computational Geometry

Voronoi Diagram and Convex Hull

RASTERIZING POLYGONS IN IMAGE SPACE

8. Hidden Surface Elimination

CS 161 Fall 2015 Final Exam

Computational Geometry

Computational Geometry Algorithmische Geometrie

Flavor of Computational Geometry. Convex Hull in 2D. Shireen Y. Elhabian Aly A. Farag University of Louisville

Introduction to Algorithms

Rec 8 Notes. 1 Divide-and-Conquer Convex Hull. 1.1 Algorithm Idea. 1.2 Algorithm. Here s another random Divide-And-Conquer algorithm.

CS 373: Combinatorial Algorithms, Fall Name: Net ID: Alias: U 3 / 4 1

Line Arrangement. Chapter 6

On Merging Straight Skeletons

Prime Time (Factors and Multiples)

Chapter 3. Sukhwinder Singh

An Algorithm for Computing the Convex Hull of a Set of Imprecise Line Segment Intersection

Lecture 25: Bezier Subdivision. And he took unto him all these, and divided them in the midst, and laid each piece one against another: Genesis 15:10

Voronoi Diagrams and Delaunay Triangulation slides by Andy Mirzaian (a subset of the original slides are used here)

Distance Between Point and Triangle in 3D

Computational Geometry

Computational Geometry [csci 3250]

1 Divide and Conquer Approach

Computational Geometry. Lecture 17

Polygon Filling. Can write frame buffer one word at time rather than one bit. 2/3/2000 CS 4/57101 Lecture 6 1

Flavor of Computational Geometry. Voronoi Diagrams. Shireen Y. Elhabian Aly A. Farag University of Louisville

Polygon decomposition. Motivation: Art gallery problem

26 The closest pair problem

CS 6463: AT Computational Geometry Spring 2006 Convex Hulls Carola Wenk

Last time. Today: Convex Hull Brute Force Inside(q,abc) Intersect(ab,cd) Orient(a,b,c).

Lecture 11 Combinatorial Planning: In the Plane

Closest Pair of Points in the Plane. Closest pair of points. Closest Pair of Points. Closest Pair of Points

Agenda. Polygon Terminology Types of polygons Inside Test Polygon Filling Algorithms. Scan-Line Polygon Fill Algorithm Flood-Fill Algorithm

Grids Geometry Computational Geometry

Glossary of dictionary terms in the AP geometry units

(Refer Slide Time: 00:02:00)

CMSC 754 Computational Geometry 1

Lattice Polygon s and Pick s Theorem From Dana Paquin and Tom Davis 1 Warm-Up to Ponder

Distributed Algorithm for Voronoi Partition of Wireless Sensor Networks with a Limited Sensing Range

CSE 421 Closest Pair of Points, Master Theorem, Integer Multiplication

6.854J / J Advanced Algorithms Fall 2008

Convex Polygon Generation

A Fast Convex Hull Algorithm for Binary Image

Graphics (Output) Primitives. Chapters 3 & 4

Transcription:

CS 410/584,, Computational Geometry Algorithms for manipulation of geometric objects We will concentrate on 2-D geometry Numerically robust try to avoid division Round-off error Divide-by-0 checks Techniques David Maier 1 Basics Point p = Line segment p 1 p 2 Can represent different things (3,5) (3,5) (3,5) (3,5) (1,2) (1,2) (1,2) (1,2) David Maier 2 1

CS 410/584,, Relative Orientation of Segments p2=(x2,y2) p1=(x1,y1) p2=(x2,y2) How do we know which case it is? Could compare slopes But that has division problems David Maier 3 Cross Product Can compare slopes without division y1/x1 < y2/x2 x2 y1 < x1 y2 David Maier 4 2

CS 410/584,, Examples (-3,1) (3,2) (2,4)= (2,4) (3,2) (4,1)= (3,2) (4,1) (3,2) (2,-2)= (2,-2) (3,2) (-3,1)= 3 (-6,-4) (3,2) (-6,-4)= David Maier 5 Left Turn, Right Turn How do we know if a sequence of two line segments turns to left or right? p1 p1 p3 p2 p2 p3 David Maier 6 3

CS 410/584,, Use Cross Product Translate p2 to origin, along with other points. Look at relative position of p1, p3 p1=(3,6) p1 =(3-4,6-3) p2=(4,3) p2 =(4-4,3-3) p3=(6,1) p3 =(6-4,1-3) David Maier 7 Intersection: Cases p1 p4 p1 p1 p3 p2 p4 p2 p3 p2 p3 p4 p1 p4 p4 p4 p2 p2 p3 p2 p3 p1 Main conditions p1, p2 on different sides of p3, p4 on different sides of p1 p3 David Maier 8 4

CS 410/584,, How Do You Tell Different Sides? One is a left turn and one is a right turn p1 p4 p3 p2 David Maier 9 If 0 Change in Direction Then the point is on the p1 p2 line somewhere OnSegment(p1,p2,p3) 1. min(x1,x2) x3 max(x1,x2) 2. min(y1,y2) y3 max(y1,y2) p1 p3 p2 p3 David Maier 10 5

CS 410/584,, Beware of Boundary Conditions Co-linear points, points on line Multiple intersections Vertical, horizontal lines p1 p2 versus p2 p1 Degenerate objects What about intersection with the degenerate line segment p3 p3 David Maier 11 Polygon Polygon closed sequence of sides Simple polygon if edges don t cross David Maier 12 6

CS 410/584,, Exercise 33.1-7 Find out if point p is in simple polygon P P has n points p1, p2,, pn, want O(n) 1. Assume no 3 consecutive points on the same line 2. Make sure p doesn t lie on any edge of P 3. Construct a segment p q where q is for sure 4. Count number of segments of P that intersect p q David Maier 13 How to Find a Point Outside of P Let x = max xi If p = (x, y), let q = P David Maier 14 7

CS 410/584,, Cases to Watch out For p q passes through a vertex P David Maier 15 What s the Difference in These Cases Do previous and next points lie on the same side of p q or not? Case I Case II p q p q Case III Case IV p q p q David Maier 16 8

CS 410/584,, In Cases III & IV, need to test if p i-1 and p i+2 are same side of p q or not In O(n) time, can head around polygon, counting number of intersections with p q, taking into account David Maier 17 Pairwise Intersection Have a collection of n line segments, want to know if there is a pair that intersect Perhaps they represent traces on a circuit layer Sweep = A vertical line moving left to right over the segments (conceptually) David Maier 18 9

CS 410/584,, Interested in Intersections with Sweep Line Want the intersection points in top-tobottom order A B D C David Maier 19 Intersecting Segments Intersecting segments adjacent in some sweep list Assumptions: No 3 segments intersect No vertical segments A C D B David Maier 20 10

CS 410/584,, Where Does Sweep List Change? Sweep list changes at segment endpoints. Update sweep list just after encountering each endpoint after it enters for after it leaves for A C D B David Maier 21 Maintaining Sweep List Keep sweep list as a structure that supports O(log n) operations Operations: Insert segment Delete segment Above: Below: Some kind of balanced tree, ordered on David Maier 22 11

CS 410/584,, How to Order New Segment on Sweep Line Need to know where new segment B is relative to each segment A already in sweep line. A B B David Maier 23 Order Endpoint List Need to have the endpoints in the order that the sweep line encounters them Sort on x-coordinate What about ties? Left endpoints win over Lower y-coordinate wins over al A cl ar C cr bl B br David Maier 24 12

CS 410/584,, Algorithm EP (endpoints): SL (sweep list) for each p in EP in order insert s into SL check if s intersects lines above and below check if segments above and below s intersect each other delete s from SL David Maier 25 Example A al bl B cl C ar br dl dr D cr EP al bl cl ar dl br dr ar SL David Maier 26 13

CS 410/584,, Polar Angle Next couple algorithms, need to order points by polar angle. David Maier 27 Discussion Problems Have Q = {p1, p2,, pn} 1. Given p, find point pi in Q with smallest positive polar angle from p. 2. Sort points in Q by increasing polar angle from x axis. Try to solve these problems using only cross product. David Maier 28 14

CS 410/584,, Convex Hull Given Q = {p1, p2,, pn}, what is smallest convex polygon P such that Vertices of P will be in Q Consider Q with 100 points. What is the most that can be on convex hull? What is the fewest that can be on convex hull? David Maier 29 Uses of Convex Hull Approximate more complicated shape by convex hull, for intersection precheck David Maier 30 15

CS 410/584,, Multiple Convex Hull Algorithms Some algorithms are good when the number of points on the hull is low. Others perform rm same on any number of points. Can often use heuristics to speed up either. Make any convex polygon R using points in Q. Then points on interior of R David Maier 31 One Way to Choose R Let pa, pb, pc, pd be the points with min x, max x, min y, max y. Let R be polygon pa pd pb pc pa pd pb p p Will this always remove points? David Maier 32 16

CS 410/584,, Package wrapping: Jarvis s March Of points not on hull so far, which is at least angle with the last point on the hull p i p i-1 David Maier 33 Issues Co-linear points: What if several points on same edge of convex hull? Want most points: Want least points: How to find distance? p i p i-1 David Maier 34 17

CS 410/584,, Where to start: Issues, Continued What line to use through first point: David Maier 35 Complexity At each point, do an O(n) process to find point with minimum positive polar angle. How many times do we need to do that search? So, O(n h) where h = David Maier 36 18

CS 410/584,, Graham Scan Start with angle sweep and remove points Find point p0 with minimum i y-coordinate Sort points by polar angle from horizontal line through p Always O(n log n), no matter how many points on hull p0 David Maier 37 Candidate Hull on Stack Push points on stack in order Before you push, check angle with top two points on stack Left turn: Right turn: p i p i TOP NEXT-TO-TOP TOP NEXT-TO-TOP David Maier 38 19

CS 410/584,, May be Several Pops in a Row Can have several points popped because of pi p i David Maier 39 Graham Scan: Start-up Input: 1. Let p[0] have 2. sort p[1]...p[n] by angle with 3. Have stack S 4. Push( ) Push( ) Push( ) David Maier 40 20

CS 410/584,, Graham Scan: Body for i = 3 to N while NEXT-TO-TOP TOP p[i] is POP PUSH( ) S holds the convex hull when done David Maier 41 Complexity O(n log n) to sort points O(n) for rest Each point gets pushed once Can do multiple pops in while-loop, but each is of a previously pushed point David Maier 42 21

CS 410/584,, Planar Minimal Spanning Tree Suppose I give you points in the plane to represent nodes in a graph All edges exist, it weight iht is dit distance bt between end points. What is the first edge to add? David Maier 43 Closest Pair Use divide and conquer Split points in half by x-coordinate Find closest pair on each side Let = David Maier 44 22

CS 410/584,, Closer Pair Can there be a pair of points closer than? Yes! Near the boundary So check David Maier 45 Avoid Too Many Comparisons Don t want to compare all pairs of points near the boundary, otherwise get Only compare each point near boundary to next 7 in order of y-coordinate David Maier 46 23

CS 410/584,, Complexity For n points, have two sub-problems of size n/2 How much other work outside of the recursive calls? Might seem like O(n log n) because of the sorting That would give complexity However, make two lists of the points at the very beginning, one sorted on x and the other on y Can construct ordered lists for sub-problems in linear time. T(n) = 2T(n/2) + O(n) David Maier 47 24