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

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

Computational Geometry

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

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

COMPUTATIONAL GEOMETRY

Geometry. Zachary Friggstad. Programming Club Meeting

Computer Graphics II

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

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

Lesson 1. Unit 2 Practice Problems. Problem 2. Problem 1. Solution 1, 4, 5. Solution. Problem 3

Lecture 14: Computational Geometry Steven Skiena. skiena

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Computational Geometry. HKU ACM ICPC Training 2010

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

Lecture 13 Geometry and Computational Geometry

Computational Geometry Algorithmische Geometrie

CS 372: Computational Geometry Lecture 3 Line Segment Intersection

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

Course Guide (/8/teachers/teacher_course_guide.html) Print (/8/teachers/print_materials.html) LMS (/8

Three Dimensional Geometry. Linear Programming

CSE 5311 Notes 13: Computational Geometry

From Vertices To Fragments-1

Basics of Computational Geometry

CS 325 Computer Graphics

Scan Conversion. Drawing Lines Drawing Circles

From Ver(ces to Fragments: Rasteriza(on

6 Mathematics Curriculum

Line Arrangement. Chapter 6

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

27 Geometric Intersection

Chapter 3. Sukhwinder Singh

Clipping. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Overview. Pipeline implementation I. Overview. Required Tasks. Preliminaries Clipping. Hidden Surface removal

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Grids Geometry Computational Geometry

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

Geometric Computations for Simulation

Realtime 3D Computer Graphics Virtual Reality

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

Glossary of dictionary terms in the AP geometry units

Direct Rendering. Direct Rendering Goals

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

Stacks API and finding the convex hull. CS Spring 2017

1/25 Warm Up Find the value of the indicated measure

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.

3D convex hulls. Computational Geometry [csci 3250] Laura Toma Bowdoin College

Clipping and Scan Conversion

Computer Graphics. - Rasterization - Philipp Slusallek

GEOMETRY & INEQUALITIES. (1) State the Triangle Inequality. In addition, give an argument explaining why it should be true.

Ray Tracing Basics I. Computer Graphics as Virtual Photography. camera (captures light) real scene. photo. Photographic print. Photography: processing

Lecture 7: Computational Geometry

Question. Why is the third shape not convex?

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

CSE 546, Fall, 2016 Homework 1

Mathematics Curriculum

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Computer Graphics 7 - Rasterisation

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Hidden-Surface Removal.

CSCI 4620/8626. Coordinate Reference Frames

Computational Geometry 2D Convex Hulls

Lofting 3D Shapes. Abstract

Linear Programming- Manufacturing with

CS 372: Computational Geometry Lecture 10 Linear Programming in Fixed Dimension

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

Boardworks Ltd KS3 Mathematics. S1 Lines and Angles

Rasterization: Geometric Primitives

CHAPTER 2 REVIEW COORDINATE GEOMETRY MATH Warm-Up: See Solved Homework questions. 2.2 Cartesian coordinate system

Voronoi diagram and Delaunay triangulation

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

Line Arrangements. Applications

Convex Hulls in Three Dimensions. Polyhedra

Rational Numbers: Graphing: The Coordinate Plane

Topic #1: Rasterization (Scan Conversion)

Accelerating Geometric Queries. Computer Graphics CMU /15-662, Fall 2016

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

Arizona Academic Standards

Visible Surface Detection Methods

Geometry: Angle Relationships

Chapter 8: Implementation- Clipping and Rasterization

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

Geometric and Algebraic Connections

Approximating a set of points by circles

Linear Programming in Small Dimensions

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

EF432. Introduction to spagetti and meatballs

CPSC / Sonny Chan - University of Calgary. Collision Detection II

Clipping & Culling. Lecture 11 Spring Trivial Rejection Outcode Clipping Plane-at-a-time Clipping Backface Culling

CS123 INTRODUCTION TO COMPUTER GRAPHICS. Clipping. Concepts, Algorithms for line clipping. 1 of 16. Andries van Dam. Clipping - 10/12/17

Lesson 7.1. Angles of Polygons

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

CSCI 4620/8626. Computer Graphics Clipping Algorithms (Chapter 8-5 )

Computing Visibility. Backface Culling for General Visibility. One More Trick with Planes. BSP Trees Ray Casting Depth Buffering Quiz

Main Idea: classify polygons and determine which polygons can form a tessellation.

Intro to Modeling Modeling in 3D

Algorithms and Data Structures

Identify parallel lines, skew lines and perpendicular lines.

Advanced Algorithms Computational Geometry Prof. Karen Daniels. Fall, 2012

Pseudo code of algorithms are to be read by.

Transcription:

CS 226 ecture 15: eometric algorithms Warning: intuition may mislead (continued) Important applications involve geometry models of physical world computer graphics mathematical models x: Find intersections among set of rectangles we think of this algorithm sees this Ancient mathematical foundations ost geometric algorithms less than 25 years old nowledge of fundamental algorithms is critical use them directly use the same design strategies know how to compare and evaluate algs 15.1 15.3 Warning: intuition may mislead eometric algorithms: overview Humans have spatial intuition in 2D and 3D computers do not! neither have good intuition in high dimensions x: Is a polygon convex? we think of this alg sees this or even this ew primitives points, lines, planes; polygons, circles Primitive operations distance, angles "compare" point to line do two line segments intersect? Problems extend to higher dimensions (algorithms sometimes do, sometimes don t) Higher level intrinsic structures arise 15.2 asic problems intersection proximity point location range search 15.4

Approaches to solving geometric problems Algorithm design paradigms (continued) incremental (brute-force) Progression of algorithm design (oversimplified) divide-and-conquer sweep-line algs multidimensional tree structures all possibilities double recursion 2^ brute force nested for loops ^2 divide-and-conquer recursion, trees log elegant idea 1 "for" loop randomization random choices randomized algs any examples in geometric algorithms discretized algorithms online and dynamic algs 15.5 15.7 Algorithm design paradigms eometric primitives (2D) Draw from knowledge about fundamental algs ove up one level of abstraction use fundamental algs and data structures know their performance characterisitics ore primitives lead to wider range of problems Some problems too complex to admit simple algorithms For many important problems classical approaches give good algorithms need research to find "best" algorithms no excuse for using "dumb" algorithms PIT two numbers (x, y) I two numbers a and b [ax + by = 1] I ST four numbers (x1, y1) (x2, y2) PY sequence of points o shortage of other geometric shapes TRIA SQUAR CIRC 15.6 3D and higher dimensions more complicated 15.8

uilding algorithms from geometric primitives CCW implementation First, need good implementations of primitives! is polygon simple? is point on line? is point inside polygon? do two line segments intersect? do two polygons intersect? Algorithms search through STS of primitives all points in specified range closest pair in set of points intersecting pairs in set of line segments overlapping areas in set of polygons compare slopes less: greater: equal: points are collinear #typedef struct point PIT int ccw(pit p0, PIT p1, PIT p2) { int dx1, dx2, dy1, dy2; dx1 = p1.x - p0.x; dy1 = p1.y - p0.y; dx2 = p2.x - p0.x; dy2 = p2.y - p0.y; if (dx1*dy2 > dy1*dx2) return 1; if (dx1*dy2 < dy1*dx2) return -1; return 0; 15.9 15.11 ine segment intersection CCW implementation (continued) Do two line segments intersect? Still not quite right! ug in degenerate case To implement ITRSCT(l1, l2) use simpler primitive SA(p1, p2, l): iven two points p1, p2 and a line l, are p1 and p2 on the same side of l? four collinear points Does A intersect CD? on the line in the order ACD: on the line in the order ACD: YS To implement SA use simpler primitive CCW(p1, p2, p3): iven three points p1, p2, p3, is the route p1-p2-p3 a ccw turn? Can t just return 0 if dx1*dy2 = dx2*dy1 (see book) CCW is an important basic primitive x: is point inside convex -gon? CCW tests two ccw tests to implement SA four ccw tests to implement ITRSCT esson: geometric primitives are tricky to implement can t ignore degenerate cases 15.10 15.12

Convex hull of a point set Package-wrap implementation asic property of a set of points CVX HU: smallest convex polygon enclosing the points shortest fence surrounding the points intersection of halfplanes defined by point pairs Running time of algorithm can depend on : number of points : number of points on the hull point distribution 15.13 int wrap(pit p[], int ) { int i, min, ; float th, v; struct point t; for (min = 0, i = 1; i < ; i++) if (p[i].y < p[min].y) min = i; p[] = p[min]; th = 0.0; for ( = 0; < ; ++) { t = p[]; p[] = p[min]; p[min] = t; min = ; v = th; th = 360.0; for (i = +1; i <= ; i++) if (theta(p[], p[i]) > v) if (theta(p[], p[i]) < th) { min = i; th = theta(p[], p[min]); if (min == ) return ; Use pseudo-angle theta to save time (see text) 15.15 Package-wrap algorithm Package-wrap example perates like selection sort Abstract idea sweep line anchored at current point CCW first point hit is on hull F P A C I J H D Implementation compute angle to all points pick smallest angle larger than current one D 15.14 15.16

raham Scan Divide-and-conquer convex hull algorithms Sort points on angle with bottom point as origin forms simple closed polygon Proceed through polygon discard points that would cause a CW turn divide points int grahamscan(struct point p[], int ) { int i, min, ; struct point t; for (min = 1, i = 2; i <= ; i++) if (p[i].y < p[min].y) min = i; for (i = 1; i <= ; i++) if (p[i].y == p[min].y) if (p[i].x > p[min].x) min = i; t = p[1]; p[1] = p[min]; p[min] = t; quicksort(p, 1, ); p[0] = p[]; for ( = 3, i = 4; i <= ; i++) { while (ccw(p[],p[-1],p[i]) >= 0) --; ++; t = p[]; p[] = p[i]; p[i] = t; return ; 15.17 divide space 15.19 raham scan example Incremental convex hull algorithm P Consider next point if inside hull of previous points, ignore if outside, update hull F F I C A H A D 15.18 Two subproblems to solve test if point inside or outside polygon update hull for outside points oth subproblems can be solved by looking at all hull points can be improved with binary search Randomized algorithm consider points in random order + log 15.20

"Sweep line" convex hull algorithm Summary of 2D convex hull algs Sort points on x-coordinate first liminates "inside" test Package wrap raham scan log (sort time) Divide-and-conquer log (with work) Quick elimination (fast average-case) ne-by-one elimination log Sweep line log (sort time) Total time proportional to log (for sort) 15.21 How many points on the hull? Worst case: Average case: depends on distribution uniform in a convex polygon: log uniform in a circle: ^(1/3) requires understanding of basic properties of DATA 15.23 Quick elimination Higher dimensions Improve the performance of any convex hull algorithm by quickly eliminating most points (known not to be on the hull) Use points at "corners": max, min x+y, x-y ultifaceted (convex) polytope encloses points T a simple object x: points d dimensions d=2: convex hull d=3: uler s formula (v - e + f = 2) d>3: exponential number of facets at worst XTR PITS return points on the hull, not necc in order Check if point inside quadrilateral: four CCW tests Check if point inside rectangle: four comparisons Almost all points eliminated if points random number of points left proportional to ^(1/2) IAR algorithm 15.22 Package-wrap Divide-and-conquer Randomized Interior elimination 15.24

eometric models of mathematical problems Impact of geometric algs extends far beyond physical models eometric problem find point where two lines intersect in 2D find point where three planes intersect in 3D athematical equivalent solve simultaneous equations algorithm: gaussian elimination eometric problem find convex polytope defined by intersecting half-planes find vertex hit by line of given slope moving in from infinity athematical equivalent IAR PRRAI algorithm: SIPX (stay tuned) 15.25 inear programming example aximize a+b subject to the constraints b - a < 5 a + 4b < 45 2a + b < 27 3a - 4b < 24 a > 0 b > 0 x2 (5,10) (9,9) (0,5) (12,3) (0,0) (8,0) x1 15.26