Implementing Geometric Algorithms. Wouter van Toll June 20, 2017

Similar documents
Implementing Geometric Algorithms for Real-World Applications With and Without EGC-Support

CS368: Geometric Algorithms Handout # 6 Design and Analysis Stanford University Wednesday, 14 May 2003

Voronoi Diagrams. A Voronoi diagram records everything one would ever want to know about proximity to a set of points

Geometric Computation: Introduction

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

CS368: Geometric Algorithms Handout # 2 Design and Analysis Stanford University Monday, 17 April 2006

Week 8 Voronoi Diagrams

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

Robustness in. Monique Teillaud. Robustness in

Numerical Precision. Or, why my numbers aren t numbering right. 1 of 15

Problèmes de robustesse en géométrie algorithmique

Preferred directions for resolving the non-uniqueness of Delaunay triangulations

Computational Geometry

Course 16 Geometric Data Structures for Computer Graphics. Voronoi Diagrams

Geometric Rounding. Snap rounding arrangements of segments. Dan Halperin. Tel Aviv University. AGC-CGAL05 Rounding 1

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

CS133 Computational Geometry

PS Computational Geometry Homework Assignment Sheet I (Due 16-March-2018)

Computational Geometry for Imprecise Data

How Reliable Are Practical Point-in-Polygon Strategies?

Lecture 16: Voronoi Diagrams and Fortune s Algorithm

COMPUTATIONAL GEOMETRY INTRODUCTION

Geometric Algorithms in Three Dimensions Tutorial. FSP Seminar, Strobl,

CS S Lecture February 13, 2017

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

COMPUTING CONSTRAINED DELAUNAY

The Algorithm Design Manual

Approximating a set of points by circles

Computational Geometry Algorithmische Geometrie

Exact Computation with leda real Theory and Geometric Applications

Lecture 1: September 6, 2001

CS3110 Spring 2017 Lecture 14: Computational Geometry and Convex Hulls

CSE 5311 Notes 13: Computational Geometry

Outline. CGAL par l exemplel. Current Partners. The CGAL Project.

Voronoi diagrams and applications

COMPUTATIONAL GEOMETRY INTRODUCTION

Correctness. The Powercrust Algorithm for Surface Reconstruction. Correctness. Correctness. Delaunay Triangulation. Tools - Voronoi Diagram

Tools, Generic Programming, CGAL, and 2D Arrangement of CGAL

On the Use of Adaptive, Exact Decisions Number Types Based on Expression-Dags in Geometric Computing

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

Computational Geometry

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

Optimal Compression of a Polyline with Segments and Arcs

Numerical Robustness (for Geometric Calculations)

6.854J / J Advanced Algorithms Fall 2008

Practical 2: Ray Tracing

Triangle meshes I. CS 4620 Lecture 2

Computational Geometry

Construction of Voronoi Diagrams

CMPS 3130/6130 Computational Geometry Spring Voronoi Diagrams. Carola Wenk. Based on: Computational Geometry: Algorithms and Applications

Other Voronoi/Delaunay Structures

7 Voronoi Diagrams. The Post Office Problem

Largest Bounding Box, Smallest Diameter, and Related Problems on Imprecise Points

On Merging Straight Skeletons

CAD & Computational Geometry Course plan

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

Tiling Three-Dimensional Space with Simplices. Shankar Krishnan AT&T Labs - Research

Data Representation Type of Data Representation Integers Bits Unsigned 2 s Comp Excess 7 Excess 8

Triangle meshes I. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2017

Computational Geometry Lecture Duality of Points and Lines

Computational Geometry. Definition, Application Areas, and Course Overview

Möbius Transformations in Scientific Computing. David Eppstein

Project 1: Convex hulls and line segment intersection

Planar Graphs. 1 Graphs and maps. 1.1 Planarity and duality

Weighted and Continuous Clustering

2 Geometry Solutions

Geometric Computations for Simulation

Simplicial Complexes: Second Lecture

The Farthest Point Delaunay Triangulation Minimizes Angles

Kurt Mehlhorn, MPI für Informatik. Curve and Surface Reconstruction p.1/25

Efi Fogel, Dan Halperin, Lutz Kettner, Monique Teillaud, Ron Wein, and Nicola Wolpert

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

APPLIED aspects of COMPUTATIONAL GEOMETRY. Dan Halperin School of Computer Science Tel Aviv University

A robust and efficient implementation for the segment Voronoi diagram

Line Arrangement. Chapter 6

G 6i try. On the Number of Minimal 1-Steiner Trees* Discrete Comput Geom 12:29-34 (1994)

The Medial Axis of the Union of Inner Voronoi Balls in the Plane

A computational framework for handling motion

Voronoi Diagrams in the Plane. Chapter 5 of O Rourke text Chapter 7 and 9 of course text

Computational Geometry

Delaunay Triangulations

Numerical Methods 5633

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

Lecture 11 Combinatorial Planning: In the Plane

Gardener s spline curve

VORONOI DIAGRAM PETR FELKEL. FEL CTU PRAGUE Based on [Berg] and [Mount]

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

Integral Geometry and the Polynomial Hirsch Conjecture

Bindel, Fall 2016 Matrix Computations (CS 6210) Notes for

Insertions and Deletions in Delaunay Triangulations using Guided Point Location. Kevin Buchin TU Eindhoven

Project 1: Convex hulls and line segment intersection

Foundations of Computer Systems

15-451/651: Algorithms CMU, Spring 2016 Lecture #24: Computational Geometry Introduciton April 13, 2015 Lecturer: Danny Sleator

VoroCrust: Simultaneous Surface Reconstruction and Volume Meshing with Voronoi cells

Geometric Computing with CGAL and LEDA

COMPUTATIONAL GEOMETRY

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

Basics of Computation. PHY 604:Computational Methods in Physics and Astrophysics II

Voronoi diagram and Delaunay triangulation

PIETRO, GIORGIO & MAX ROUNDING ESTIMATING, FACTOR TREES & STANDARD FORM

Transcription:

Implementing Geometric Algorithms Wouter van Toll June 20, 2017

Introduction 6/20/2017 Lecture: Implementing Geometric Algorithms 2

Focus of this course Create algorithms to solve geometric problems Prove geometric properties and correctness Analyze complexity: running time, storage, O/Ω/Θ No programming: why? The course was pretty theoretical. It might be a nice idea to have students design and implement a geometric algorithm to keep the course more interesting. -- a student, 2016 6/20/2017 Lecture: Implementing Geometric Algorithms 3

Focus of this lecture Robust implementations are very difficult to write What makes it so difficult? (What is a robust implementation?) How can we deal with it? Case study: Voronoi diagrams 6/20/2017 Lecture: Implementing Geometric Algorithms 4

Recap: Degenerate cases Cases in which a definition/algorithm is slightly unusual Degeneracies by definition Voronoi diagram: 4 points on a circle Degeneracies for an algorithm Sweep line: events at equal height Often require extra (pseudo)code Unfortunate, but finite and doable 6/20/2017 Lecture: Implementing Geometric Algorithms 5

Pseudocode to code public List<Point> ConvexHull(List<Point> P) { List<Point> P_sorted = sort(p); List<Point> L_upper = { P_sorted[0], P_sorted[1] }; for (int i=2; i<n; i++) { L_upper.Append(P_sorted[i]); int k = L_upper.Count; while (k > 2 &&!IsPointRightOfLine(L_upper[k-1], L_upper[k-3], L_upper[k-2])) { L_upper[k-2] = L_upper[k-1]; L_upper.RemoveLast(); k--; } } } //... 6/20/2017 Lecture: Implementing Geometric Algorithms 6

Problems in 3, 2, 1 Theory: basic questions can be answered correctly Is a point [left of / right of / on] a line? Is a point [inside / outside / on] a circle? Where is the intersection of two (non-parallel) lines? Where is the intersection of two line segments, if any?... predicates new objects In a computer program... answers can be incorrect answers can be inconsistent If the algorithm relies on correctness: 6/20/2017 Lecture: Implementing Geometric Algorithms 7

The reason Inexact number representations Infinitely many numbers in R Finite #bytes in a float, double,... Imprecise numbers and results of operations Good enough for many applications Very difficult for geometric algorithms 6/20/2017 Lecture: Implementing Geometric Algorithms 8

Bits of background info Floating-point numbers 6/20/2017 Lecture: Implementing Geometric Algorithms 9

Real numbers in bytes What Every Computer Scientist Should Know About Floating-Point Arithmetic (D. Goldberg, 1991) https://docs.oracle.com/cd/e19957-01/806-3568/ncg_goldberg.html Floating-Point Numbers 101 : An Introduction Base β, precision p (number of digits), min/max exponent A number has the form ± d 0. d 1 d 2... d p 1 β e Normalized if d 0 is not 0 Examples for the real number 0.1 β=10, p=3: 0.1 = 1.00 10-1 β=2, p=24: 0.1 1.10011001100110011001101 2-4 (!) 6/20/2017 Lecture: Implementing Geometric Algorithms 10

Real numbers in bytes Binary32 (C float) https://en.wikipedia.org/wiki/single-precision_floating-point_format Not all numbers can be represented For each exponent: equally many fractions available more precision closer to 0 Rounding error = real number FPN Relative error = rounding error / real number Operations lead to new FPNs Errors can propagate 6/20/2017 Lecture: Implementing Geometric Algorithms 11

Dealing with inexactness Applied to geometry 6/20/2017 Lecture: Implementing Geometric Algorithms 12

Inexact numbers and geometry A geometric algorithm has numerical and combinatorial aspects Numerical = actual numbers Input: coordinates Algorithm: basic arithmetic Output: coordinates Combinatorial = order in which things happen Input: assignment of coordinates to points Algorithm: e.g. order of events in a sweep Output: e.g. cyclic order of convex hull, topology of subdivision 6/20/2017 Lecture: Implementing Geometric Algorithms 13

Inexact numbers and geometry Numerical errors affect combinatorial properties Basic geometric questions: large error propagation Possible problems Near-degenerate cases recognized wrongly Events processed in the wrong order Assumptions no longer hold later in the algorithm... https://en.wikipedia.org/wiki/binary_expression_tree 6/20/2017 Lecture: Implementing Geometric Algorithms 14

Robustness Wikipedia: ( ) the ability of a computer system to cope with errors during execution and cope with erroneous input. Your program should never crash Geometric algorithms: broader, vague boundary Degenerate cases are handled Output is correct for some perturbation of the input Combinatorial output is the same as with real numbers (and numerical error is negligible) How to write a robust implementation of a GA? 6/20/2017 Lecture: Implementing Geometric Algorithms 15

Idea 0: Ignore the problem Assume that floating-point precision is high enough Your code will work well most of the time Problems? Rotation / scaling /... can break it Impossible to cover all cases, unless you know / test all possible inputs Sometimes good enough, e.g. if you only compare input coordinates kd-trees, orthogonal range queries 6/20/2017 Lecture: Implementing Geometric Algorithms 16

Idea 1: Build in error margins Treat almost true as true dot product < ε points are collinear distance < ε points are equal Effect: you accept slightly incorrect answers OK if you know the consequences Example: convex hull e.g. accept slightly left turns as a right turn Not all points contained? Not entirely convex? 6/20/2017 Lecture: Implementing Geometric Algorithms 17

Idea 1: Build in error margins Problems? Epsilon tweaking What if you scale everything by 1000 or 0.001? Inconsistency: A = B and B = C, but A C Errors can propagate Remember this throughout the whole program Other programmers may not know / like your choices Some tricks can help e.g. finding nearest answer vs. checking for equality 6/20/2017 Lecture: Implementing Geometric Algorithms 18

Idea 2: Fixed-point arithmetic Input coordinates are integers in a known range (or floats in a known range with maximum #decimals) Problems? Same property may not hold for the output (e.g. intersection of line segments) Solve with snapping? Rounding can change properties: angles, collinearity, existence of intersections,... 6/20/2017 Lecture: Implementing Geometric Algorithms 19

Idea 3: Use robust predicates Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates (J.R. Shewchuk, 1997). http://www.cs.cmu.edu/~quake/robust.html Check if a determinant is 0, <0, or >0 Steps of increasingly smaller error (and increasing running time) Guaranteed correctness C code in public domain Used in Triangle library Delaunay triangulations Related structures 6/20/2017 Lecture: Implementing Geometric Algorithms 20

Idea 3: Use robust predicates Problems? Not everything can be expressed in these predicates Not everything can be expressed in predicates alone (e.g. line segment intersection) 6/20/2017 Lecture: Implementing Geometric Algorithms 21

Idea 4: Use exact number types Avoid floating-point arithmetic completely e.g. store a number as an expression of integers Fractions Results of + - * /... Takes away all FPN concerns: guaranteed correctness Problems? (Takes some getting used to) Representation can become very complex memory usage Expressions need to be evaluated high running times 6/20/2017 Lecture: Implementing Geometric Algorithms 22

Idea 4: Use exact number types BigNum Integers that can become as large as you need LEDA Many types of numbers and arithmetic CGAL The Computational Geometry Algorithms Library Specifically for geometric algorithms 6/20/2017 Lecture: Implementing Geometric Algorithms 23

Idea 4: Use exact number types https://www.cgal.org/ 6/20/2017 Lecture: Implementing Geometric Algorithms 24

Ideas 5 to n-1 6/20/2017 Lecture: Implementing Geometric Algorithms 25

Examples: What would you do? Construct a kd-tree of a point set Check if a point is inside a triangle Check if two line segments intersect Compute the intersection of two line segments 0 1/3 1/2/3 0. Nothing special 1. Error margins 2. Assumptions 3. Robust predicates 4. Exact numbers 1/2/3/4 Compute a Voronoi diagram of points Compute the convex hull of a point set 2/3 0/1/3 Compute a Euclidean Minimum Spanning Tree Compute a Voronoi diagram of line segments 3 4? 6/20/2017 Lecture: Implementing Geometric Algorithms 26

Halfway Many ways to tackle an implementation Consequences for precision, robustness, efficiency Best choice depends on your goals Ignore the problem is only recommended if any (other) part of your program does not rely on correctness 6/20/2017 Lecture: Implementing Geometric Algorithms 27

Case study Voronoi diagrams 6/20/2017 Lecture: Implementing Geometric Algorithms 28

Construction algorithms Divide-and-conquer (Shamos and Hoey, 1975) Plane sweep (Fortune, 1987, also Chapter 7) Incremental (Green and Sibson, 1978) Randomized (Guibas et al., 1992, also Chapter 9) Considered easiest to implement; lots of work on robustness 6/20/2017 Lecture: Implementing Geometric Algorithms 29

Point sites Line segment sites Duality with Delaunay only for point sites Compute DT, then convert (usually easier) More difficult for segment sites All three VD construction algorithms can be extended Discovered later, or considered trivial 6/20/2017 Lecture: Implementing Geometric Algorithms 30

Robust implementation Topology-Oriented Implementation An Approach to Robust Geometric Algorithms (Sugihara et al., 2000) Incremental construction Floating-point numbers Adaptive epsilons Lots of domain knowledge: we know what the VD is supposed to look like 6/20/2017 Lecture: Implementing Geometric Algorithms 31

Implementation: Boost C++ library with many components Voronoi: Plane sweep algorithm (vertical sweep line) Input coordinates are integers Output coordinates are doubles Adaptive-precision predicates Topologically correct Assumes non-intersecting line segments 6/20/2017 Lecture: Implementing Geometric Algorithms 32

Implementation: Vroni M. Held, since ~2000 https://www.cosy.sbg.ac.at/~held/projects/vroni/vroni.html Written in C with floating-point numbers Topology-oriented incremental approach Restarts whenever segments intersect Also supports circular arcs as sites 6/20/2017 Lecture: Implementing Geometric Algorithms 33

Implementation: CGAL M. Karavelas, since ~2004 http://doc.cgal.org/latest/voronoi_diagram_2/index.html Incremental algorithm Integrates well with Boost data structures + rest of CGAL Guaranteed to work well with CGAL s exact numbers (but otherwise...) 6/20/2017 Lecture: Implementing Geometric Algorithms 34

My experience: UUCS framework Path planning and crowd simulation Retraction and the medial axis Wrappers for Vroni and Boost Both: rounded input coordinates, pre-processing (Tried CGAL ~6 years ago, worth retrying) (GPU implementation: unreliable) If a usable implementation exists, use it 6/20/2017 Lecture: Implementing Geometric Algorithms 35

UUCS and the multi-layered MA MSc / PhD research: multi-layered medial axis Multi-layered environment (MLE): 2D layers and connections MA defined with projected distances Implementation in framework Cannot fully rely on existing libraries Performance is important 6/20/2017 Lecture: Implementing Geometric Algorithms 36

UUCS and the multi-layered MA Computing the MA of an MLE: Compute MA of each layer, then open the connections 1 by 1 Opening deleting a line segment site, but slightly weirder Opening takes O(m log m) time; maybe O(m)? Overall, for n boundary vertices and k connections: O(n log n log k) time; maybe O(n log n)? 6/20/2017 Lecture: Implementing Geometric Algorithms 37

UUCS and the multi-layered MA The each layer part: use existing libraries Vroni: faster, captures more details Boost: parallel computing, thread-safety The open the connections part: custom code Floating-point numbers and epsilons Difficult to get 100% right Assumptions about input can help a lot 6/20/2017 Lecture: Implementing Geometric Algorithms 38

UUCS and the multi-layered MA 6/20/2017 Lecture: Implementing Geometric Algorithms 39

Closing comments 6/20/2017 Lecture: Implementing Geometric Algorithms 40

Summary Geometric algorithms are difficult to implement Numerical errors affect combinatorial properties Floating-point numbers Sometimes good enough (but not in the general case) Tricks: epsilons, rounding, robust predicates Domain-specific solutions (e.g. Voronoi) Exact numbers Theoretically solves all problems Resource-intensive Robustness/implementation is a whole research area 6/20/2017 Lecture: Implementing Geometric Algorithms 41

Take-home advice If you want to implement a geometric algorithm: 1. Study the problem well 2. Decide how precise / robust / fast your solution should be 3. Check if (auxiliary) software is available 4. Choose a style of dealing with imprecision 5. Make clear assumptions about input + ensure that they are met (or return an error) 6/20/2017 Lecture: Implementing Geometric Algorithms 42

Resources What Every Computer Scientist Should Know About Floating-Point Arithmetic (D. Goldberg, 1991) https://docs.oracle.com/cd/e19957-01/806-3568/ncg_goldberg.html Adaptive Precision Floating-Point Arithmetic and Fast Robust Geometric Predicates (J.R. Shewchuk, 1997) http://www.cs.cmu.edu/~quake/robust.html Precision and Robustness in Geometric Computations (S. Schirra) Chapter in LNCS Tutorial on Algorithmic Foundations of Geographic Information Systems, 1997 Geometric Software (M. Joswig, L. Kettner, S. Näher) Two chapters in Handbook of Discrete and Computational Geometry, 2nd ed., 2004 Topology-Oriented Implementation An Approach to Robust Geometric Algorithms (Sugihara et al.) In Algorithmica 27, 2000. CGAL, Boost (Voronoi), Vroni 6/20/2017 Lecture: Implementing Geometric Algorithms 43