Shortest Path Algorithms



Similar documents
Computational Geometry. Lecture 1: Introduction and Convex Hulls

Geometry Chapter Point (pt) 1.1 Coplanar (1.1) 1.1 Space (1.1) 1.2 Line Segment (seg) 1.2 Measure of a Segment

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

Largest Fixed-Aspect, Axis-Aligned Rectangle

Solving Geometric Problems with the Rotating Calipers *

Shortest Inspection-Path. Queries in Simple Polygons

EE602 Algorithms GEOMETRIC INTERSECTION CHAPTER 27

Seminar. Path planning using Voronoi diagrams and B-Splines. Stefano Martina

Arrangements And Duality

The Essentials of CAGD

Scan-Line Fill. Scan-Line Algorithm. Sort by scan line Fill each span vertex order generated by vertex list

2. If C is the midpoint of AB and B is the midpoint of AE, can you say that the measure of AC is 1/4 the measure of AE?

Line and Polygon Clipping. Foley & Van Dam, Chapter 3

Approximation of an Open Polygonal Curve with a Minimum Number of Circular Arcs and Biarcs

Triangulation by Ear Clipping

Definitions, Postulates and Theorems

2.3 WINDOW-TO-VIEWPORT COORDINATE TRANSFORMATION

CSC2420 Spring 2015: Lecture 3

Selected practice exam solutions (part 5, item 2) (MAT 360)

G.H. Raisoni College of Engineering, Nagpur. Department of Information Technology

Algorithms for Computing Convex Hulls Using Linear Programming

Reflection and Refraction

Advanced GMAT Math Questions

Angle - a figure formed by two rays or two line segments with a common endpoint called the vertex of the angle; angles are measured in degrees

The minimum number of distinct areas of triangles determined by a set of n points in the plane

MA 408 Computer Lab Two The Poincaré Disk Model of Hyperbolic Geometry. Figure 1: Lines in the Poincaré Disk Model

Intersection of a Line and a Convex. Hull of Points Cloud

CIRCLE COORDINATE GEOMETRY

28 Closest-Point Problems

Angles that are between parallel lines, but on opposite sides of a transversal.

Closest Pair Problem

Most popular response to

4. How many integers between 2004 and 4002 are perfect squares?

INCIDENCE-BETWEENNESS GEOMETRY

Geometry Module 4 Unit 2 Practice Exam

Mathematics Spring 2015 Dr. Alexandra Shlapentokh Guide #3

ABSTRACT. For example, circle orders are the containment orders of circles (actually disks) in the plane (see [8,9]).

1 Computational Geometry

DEFINITIONS. Perpendicular Two lines are called perpendicular if they form a right angle.

Catalan Numbers. Thomas A. Dowling, Department of Mathematics, Ohio State Uni- versity.

Diffuse Reflection Radius in a Simple Polygon

THREE DIMENSIONAL GEOMETRY

Terminology: When one line intersects each of two given lines, we call that line a transversal.

Pro/ENGINEER Wildfire 5.0 Introduction to Surface Modeling

Basic Geometry Review For Trigonometry Students. 16 June 2010 Ventura College Mathematics Department 1

39 Symmetry of Plane Figures

Disjoint Compatible Geometric Matchings

2009 Chicago Area All-Star Math Team Tryouts Solutions

56 questions (multiple choice, check all that apply, and fill in the blank) The exam is worth 224 points.

INTERSECTION OF LINE-SEGMENTS

Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Example SECTION X-AXIS - the horizontal number line. Y-AXIS - the vertical number line ORIGIN - the point where the x-axis and y-axis cross

Algebra 2 Chapter 1 Vocabulary. identity - A statement that equates two equivalent expressions.

Lesson 26: Reflection & Mirror Diagrams

SAT Subject Test Practice Test II: Math Level II Time 60 minutes, 50 Questions

Graph Theory Problems and Solutions

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

Shortcut sets for plane Euclidean networks (Extended abstract) 1

Tessellating with Regular Polygons

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time


Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Chapter 3.1 Angles. Geometry. Objectives: Define what an angle is. Define the parts of an angle.

Intermediate Math Circles October 10, 2012 Geometry I: Angles

2006 Geometry Form A Page 1

Grade 7 & 8 Math Circles Circles, Circles, Circles March 19/20, 2013

Fast approximation of the maximum area convex. subset for star-shaped polygons

MA 323 Geometric Modelling Course Notes: Day 02 Model Construction Problem

Final Review Geometry A Fall Semester

61. Pascal s Hexagon Theorem.

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

TImath.com. Geometry. Points on a Perpendicular Bisector

Equations Involving Lines and Planes Standard equations for lines in space

Solutions to Homework 10

Solutions to old Exam 1 problems

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION GEOMETRY. Thursday, January 24, :15 a.m. to 12:15 p.m.

Everyday Mathematics CCSS EDITION CCSS EDITION. Content Strand: Number and Numeration

1. A student followed the given steps below to complete a construction. Which type of construction is best represented by the steps given above?

COMMON CORE STATE STANDARDS FOR MATHEMATICS 3-5 DOMAIN PROGRESSIONS

Intersection of Convex Objects: The Method of Separating Axes

Vector storage and access; algorithms in GIS. This is lecture 6

Geometry Progress Ladder

MODERN APPLICATIONS OF PYTHAGORAS S THEOREM

1. Find the length of BC in the following triangles. It will help to first find the length of the segment marked X.

MATH STUDENT BOOK. 8th Grade Unit 6

Geometry: Unit 1 Vocabulary TERM DEFINITION GEOMETRIC FIGURE. Cannot be defined by using other figures.

Lesson 1.1 Building Blocks of Geometry

12. Parallels. Then there exists a line through P parallel to l.

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Star and convex regular polyhedra by Origami.

Bicycle Math. presented to the Math, Computer Science, & Physics Seminar Bard College Annandale-on-Hudson, New York. Timothy E.

Geometry 8-1 Angles of Polygons

Basic AutoSketch Manual

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Solutions to Practice Problems

Tutorial 1: The Freehand Tools

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

USING TRIANGULATIONS IN COMPUTER SIMULATIONS OF GRANULAR MEDIA

The GED math test gives you a page of math formulas that

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Transcription:

Shortest Path Algorithms Jaehyun Park CS 97SI Stanford University June 29, 2015

Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Cross Product 2

Cross Product Arguably the most important operation in 2D geometry We ll use it all the time Applications: Determining the (signed) area of a triangle Testing if three points are collinear Determining the orientation of three points Testing if two line segments intersect Cross Product 3

Cross Product Define ccw(a, B, C) = (B A) (C A) = (b x a x )(c y a y ) (b y a y )(c x a x ) Cross Product 4

Segment-Segment Intersection Test Given two segments AB and CD Want to determine if they intersect properly: two segments meet at a single point that are strictly inside both segments Cross Product 5

Segment-Segment Intersection Test Assume that the segments intersect From A s point of view, looking straight to B, C and D must lie on different sides Holds true for the other segment as well The intersection exists and is proper if: ccw(a, B, C) ccw(a, B, D) < 0 and ccw(c, D, A) ccw(c, D, B) < 0 Cross Product 6

Non-proper Intersections We need more special cases to consider! e.g., If ccw(a, B, C), ccw(a, B, D), ccw(c, D, A), ccw(c, D, B) are all zeros, then two segments are collinear Very careful implementation is required Cross Product 7

Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Convex Hull Problem 8

Convex Hull Problem Given n points on the plane, find the smallest convex polygon that contains all the given points For simplicity, assume that no three points are collinear Convex Hull Problem 9

Simple Algorithm AB is an edge of the convex hull iff ccw(a, B, C) have the same sign for all other points C This gives us a simple algorithm For each A and B: If ccw(a, B, C) > 0 for all C A, B: Record the edge A B Walk along the recorded edges to recover the convex hull Convex Hull Problem 10

Faster Algorithm: Graham Scan We know that the leftmost given point has to be in the convex hull We assume that there is a unique leftmost point Make the leftmost point the origin So that all other points have positive x coordinates Sort the points in increasing order of y/x Increasing order of angle, whatever you like to call it Incrementally construct the convex hull using a stack Convex Hull Problem 11

Incremental Construction We maintain a convex chain of the given points For each i, do the following: Append point i to the current chain If the new point causes a concave corner, remove the bad vertex from the chain that causes it Repeat until the new chain becomes convex Convex Hull Problem 12

Example Points are numbered in increasing order of y/x Convex Hull Problem 13

Example Add the first two points in the chain Convex Hull Problem 14

Example Adding point 3 causes a concave corner 1-2-3: remove 2 Convex Hull Problem 15

Example That s better... Convex Hull Problem 16

Example Adding point 4 to the chain causes a problem: remove 3 Convex Hull Problem 17

Example Continue adding points... Convex Hull Problem 18

Example Continue adding points... Convex Hull Problem 19

Example Continue adding points... Convex Hull Problem 20

Example Bad corner! Convex Hull Problem 21

Example Bad corner again! Convex Hull Problem 22

Example Continue adding points... Convex Hull Problem 23

Example Continue adding points... Convex Hull Problem 24

Example Continue adding points... Convex Hull Problem 25

Example Done! Convex Hull Problem 26

Pseudocode Set the leftmost point as (0, 0), and sort the rest of the points in increasing order of y/x Initialize stack S For i = 1,..., n: Let A be the second topmost element of S, B be the topmost element of S, and C be the ith point If ccw(a, B, C) < 0, pop S and go back Push C to S Points in S form the convex hull Convex Hull Problem 27

Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Sweep Line Algorithm 28

Sweep Line Algorithm A problem solving strategy for geometry problems The main idea is to maintain a line (with some auxiliary data structure) that sweeps through the entire plane and solve the problem locally We can t simulate a continuous process, (e.g. sweeping a line) so we define events that causes certain changes in our data structure And process the events in the order of occurrence We ll cover one sweep line algorithm Sweep Line Algorithm 29

Sweep Line Algorithm Problem: Given n axis-aligned rectangles, find the area of the union of them We will sweep the plane from left to right Events: left and right edges of the rectangles The main idea is to maintain the set of active rectangles in order It suffices to store the y-coordinates of the rectangles Sweep Line Algorithm 30

Example Sweep Line Algorithm 31

Example Sweep Line Algorithm 32

Example Sweep Line Algorithm 33

Example Sweep Line Algorithm 34

Example Sweep Line Algorithm 35

Example Sweep Line Algorithm 36

Example Sweep Line Algorithm 37

Example Sweep Line Algorithm 38

Example Sweep Line Algorithm 39

Example Sweep Line Algorithm 40

Example Sweep Line Algorithm 41

Pseudo-pseudocode If the sweep line hits the left edge of a rectangle Insert it to the data structure Right edge? Remove it Move to the next event, and add the area(s) of the green rectangle(s) Finding the length of the union of the blue segments is the hardest step There is an easy O(n) method for this step Sweep Line Algorithm 42

Notes on Sweep Line Algorithms Sweep line algorithm is a generic concept Come up with the right set of events and data structures for each problem Exercise problems Finding the perimeter of the union of rectangles Finding all k intersections of n line segments in O((n + k) log n) time Sweep Line Algorithm 43

Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Intersecting Half-planes 44

Intersecting Half-planes Representing a half-plane: ax + by + c 0 The intersection of half-planes is a convex area If the intersection is bounded, it gives a convex polygon Given n half-planes, how do we compute the intersection of them? i.e., Find vertices of the convex area There is an easy O(n 3 ) algorithm and a hard O(n log n) one We will cover the easy one Intersecting Half-planes 45

Intersecting Half-planes For each half-plane a i x + b i y + c i 0, define a straight line e i : a i x + b i y + c i = 0 For each pair of e i and e j : Compute their intersection p = (p x, p y ) Check if a k p x + b k p y + c k 0 for all half-planes If so, store p in some array P Otherwise, discard p Find the convex hull of the points in P Intersecting Half-planes 46

Intersecting Half-planes The intersection of half-planes can be unbounded But usually, we are given limits on the min/max values of the coordinates Add four half-planes x M, x M, y M, y M (for large M) to ensure that the intersection is bounded Time complexity: O(n 3 ) Pretty slow, but easy to code Intersecting Half-planes 47

Outline Cross Product Convex Hull Problem Sweep Line Algorithm Intersecting Half-planes Notes on Binary/Ternary Search Notes on Binary/Ternary Search 48

Notes on Binary Search Usually, binary search is used to find an item ofi rulnterest in a sorted array There is a nice application of binary search, often used in geometry problems Example: finding the largest circle that fits into a given polygon Don t try to find a closed form solution or anything like that! Instead, binary search on the answer Notes on Binary/Ternary Search 49

Ternary Search Another useful method in many geometry problems Finds the minimum point of a convex function f Not exactly convex, but let s use this word anyway Initialize the search interval [s, e] Until e s becomes small enough : m 1 := s + (e s)/3, m 2 := e (e s)/3 If f(m 1 ) f(m 2 ), set e := m 2 Otherwise, set s := m 1 Notes on Binary/Ternary Search 50