0% found this document useful (0 votes)
47 views11 pages

Geometry

memo

Uploaded by

tecnicoengen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views11 pages

Geometry

memo

Uploaded by

tecnicoengen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Geometric Algorithms

Geometric Algorithms Applications.


!Data mining.
!VLSI design.
!Computer vision.
!Mathematical models.
!Astronomical simulation. airflow around an aircraft wing
!Geographic information systems.
!Computer graphics (movies, games, virtual reality).
!Models of physical world (maps, architecture, medical imaging).
Reference: http://www.ics.uci.edu/~eppstein/geom.html

History.
Reference: Chapters 24-25, Algorithms in C, 2nd Edition, Robert Sedgewick. ! Ancient mathematical foundations.
! Most geometric algorithms less than 25 years old.

Robert Sedgewick and Kevin Wayne • Copyright © 2006 • http://www.Princeton.EDU/~cos226 2

Geometric Primitives Intuition

Point: two numbers (x, y). any line not through origin Warning: intuition may be misleading.
Line: two numbers a and b [ax + by = 1] !Humans have spatial intuition in 2D and 3D.
Line segment: two points. !Computers do not.
Polygon: sequence of points. !Neither has good intuition in higher dimensions!

Primitive operations. Is a given polygon simple?


! Is a point inside a polygon? no crossings

! Compare slopes of two lines. 1 6 5 8 7 2

! Distance between two points. 7 8 6 4 2 1

! Do two line segments intersect?


! Given three points p1, p2, p3, is p1-p2-p3 a counterclockwise turn? 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2

1 2 18 4 18 4 19 4 19 4 20 3 20 3 20

Other geometric shapes.


!Triangle, rectangle, circle, sphere, cone, …
1 10 3 7 2 8 8 3 4
!3D and higher dimensions sometimes more complicated.
6 5 15 1 11 3 14 2 16

we think of this algorithm sees this


3 4
Polygon Inside, Outside Polygon Inside, Outside: Crossing Number

Jordan curve theorem. [Veblen 1905] Any continuous simple closed Does line segment intersect ray?
curve cuts the plane in exactly two pieces: the inside and the outside.
yi+1 " yi (xi+1 , yi+1 )
y = (x " xi ) + yi
Is a point inside a simple polygon? xi+1 " xi
where xi # x # xi+1 !
(xi , yi )

!
! (x , y )

!
public boolean contains(double x0, double y0) {
int crossings = 0;
for (int i = 0; i < N; i++) {
double slope = (y[i+1] - y[i]) / (x[i+1] - x[i]);
boolean cond1 = (x[i] <= x0) && (x0 < x[i+1]);
boolean cond2 = (x[i+1] <= x0) && (x0 < x[i]);
boolean above = (y0 < slope * (x0 - x[i]) + y[i]);
http://www.ics.uci.edu/~eppstein/geom.html
if ((cond1 || cond2) && above) crossings++;
}
return (crossings % 2 != 0);
Application. Draw a filled polygon on the screen. }

5 6

Implementing CCW Implementing CCW

CCW. Given three point a, b, and c, is a-b-c a counterclockwise turn? CCW. Given three point a, b, and c, is a-b-c a counterclockwise turn?
!Analog of comparisons in sorting. !Determinant gives twice area of triangle.
!Idea: compare slopes.
ax ay 1
c c b
2 " Area(a, b, c) = bx by 1 = (bx # a x )(c y # a y ) # (by # a y )(c x # a x )
c b c
cx cy 1
b c b b a c

!
!
If area > 0 then a-b-c is counterclockwise.
a a a a b a
If area < 0, then a-b-c is clockwise.
yes no Yes
If area = 0, then a-b-c are collinear.
??? ??? ???
(! slope) (collinear) (collinear) (collinear)

(bx , by) (cx , cy)

Lesson. Geometric primitives are tricky to implement.


! Dealing with degenerate cases. >0 <0
! Coping with floating point precision. (ax , ay) (bx , by) (ax , ay)
(cx , cy)

7 8
Immutable Point ADT

Convex Hull
public final class Point {
public final int x;
public final int y;

public Point(int x, int y) { this.x = x; this.y = y; }

public double distanceTo(Point q) {


return Math.hypot(this.x - q.x, this.y - q.y);
}

public static int ccw(Point a, Point b, Point c) {


double area2 = (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
if else (area2 < 0) return -1;
else if (area2 > 0) return +1;
else if (area2 > 0 return 0;
}

public static boolean collinear(Point a, Point b, Point c) {


return ccw(a, b, c) == 0;
}
}

9 10

Convex Hull Mechanical Solution

A set of points is convex if for any two points p and q in the set, Mechanical algorithm. Hammer nails perpendicular to plane;
the line segment pq is completely in the set. stretch elastic rubber band around points.

Convex hull. Smallest convex set containing all the points.

p p

q q

convex not convex


http://www.dfanning.com/math_tips/convexhull_1.gif

convex hull

Properties.
! "Simplest" shape that approximates set of points.
! Shortest (perimeter) fence surrounding the points.
! Smallest (area) convex polygon enclosing the points.

11 12
Brute Force Package Wrap (Jarvis March)

Observation 1. Edges of convex hull of P connect pairs of points in P. Package wrap.


! Start with point with smallest y-coordinate.
Observation 2. Edge pq is on convex hull if all other points are ! Rotate sweep line around current point in ccw direction.
counterclockwise of pq. ! First point hit is on the hull.
q
! Repeat.
p

O(N3) algorithm. For all points p and q in P, check whether pq is


an edge of convex hull.
each check requires O(N) ccw calculations,
where N is the number of points in P

13 14

Package Wrap (Jarvis March) How Many Points on the Hull?

Implementation. Parameters.
!Compute angle between current point and all remaining points. ! N = number of points.
!Pick smallest angle larger than current angle. ! h = number of points on the hull.
!"(N) per iteration.
Package wrap running time. "(N h) per iteration.

How many points on hull?


!Worst case: h = N.
!Average case: difficult problems in stochastic geometry.
– in a disc: h = N1/3.
– in a convex polygon with O(1) edges: h = log N.

15 16
Graham Scan: Example Graham Scan: Example

Graham scan. Implementation.


! Choose point p with smallest y-coordinate. !Input: p[1], p[2], …, p[N] are points.
! Sort points by polar angle with p to get simple polygon. !Output: M and rearrangement so that p[1], ..., p[M] is convex hull.
! Consider points in order, and discard those that
would create a clockwise turn. // preprocess so that p[1] has smallest y-coordinate
// sort by angle with p[1]
p
points[0] = points[N]; // sentinel
int M = 2;
for (int i = 3; i <= N; i++) {
while (Point.ccw(p[M-1], p[M], p[i]) <= 0) {
M--;
} discard points that would create clockwise turn
M++;
swap(points, M, i);
} add i to putative hull

Running time. O(N log N) for sort and O(N) for rest.

why?
17 18

Quick Elimination Convex Hull Algorithms Costs Summary

Quick elimination.
!Choose a quadrilateral Q or rectangle R with 4 points as corners.
!If point is inside, can eliminate. Q
Algorithm Running Time
– 4 ccw tests for quadrilateral Package wrap Nh
– 4 comparisons for rectangle
R Graham scan N log N
Quickhull N log N
Three-phase algorithm
! Pass through all points to compute R. Mergehull N log N

! Eliminate points inside R. Sweep line N log N


! Find convex hull of remaining points. Quick elimination Nt
Best in theory N log h
output sensitive running time

Practice. Can eliminate almost all points asymptotic cost to find h-point hull in N-point set
these
in linear time. points t assumes "reasonable" point distribution

eliminated

19 20
Convex Hull: Lower Bound

Models of computation.
!Comparison based: compare coordinates.
Closest Pair of Points
(impossible to compute convex hull in this model of computation)

(a.x < b.x) || ((a.x == b.x) && (a.y < b.y)))

! Quadratic decision tree model: compute any quadratic function


of the coordinates and compare against 0.

(a.x*b.y - a.y*b.x + a.y*c.x - a.x*c.y + b.x*c.y - c.x*b.y) < 0

Theorem. [Andy Yao, 1981] In quadratic decision tree model,


any convex hull algorithm requires #(N log N) ops.
higher degree polynomial tests
don't help either [Ben-Or, 1983]
even if hull points are not required to be
output in counterclockwise order

21 22

Closest Pair of Points Closest Pair of Points

Closest pair. Given N points in the plane, find a pair with smallest Algorithm.
Euclidean distance between them. ! Divide: draw vertical line L so that roughly !N points on each side.
! Conquer: find closest pair in each side recursively.
Fundamental geometric primitive. ! Combine: find closest pair with one point in each side.
! Graphics, computer vision, geographic information systems, ! Return best of 3 solutions. seems like "(N2)

molecular modeling, air traffic control.


! Special case of nearest neighbor, Euclidean MST, Voronoi.
fast closest pair inspired fast algorithms for these problems L

Brute force. Check all pairs of points p and q with "(N2)


distance calculations. 8
21

1-D version. O(N log N) easy if points are on a line.


12
Assumption. No two points have same x coordinate.

to make presentation cleaner

23 26
Closest Pair of Points Closest Pair of Points

Find closest pair with one point in each side, assuming that distance < $. Def. Let si be the point in the 2$-strip, with
Observation: only need to consider points within $ of line L.
! the ith smallest y-coordinate.
Sort points in 2$-strip by their y coordinate.
!

Only check distances of those within 11 positions in sorted list!


! Claim. If |i – j| % 12, then the distance between 39 j
si and sj is at least $.
31
Pf.
! No two points lie in same !$-by-!$ box.
L ! Two points at least 2 rows apart !$
7
have distance % 2(!$). ! 2 rows
6 29
30
!$
5
4 21 i 27
28 !$
Fact. Still true if we replace 12 with 7.
$ = min(12, 21) 26
12 3
25

$ 30
$ $ 31

Closest Pair Algorithm Closest Pair of Points: Analysis

Running time.
Closest-Pair(p1, …, pn) {
Compute separation line L such that half the points O(N log N)
are on one side and half on the other side. T(N) " 2T ( N /2) + O(N log N) # T(N) = O(N log 2 N)

$1 = Closest-Pair(left half)
2T(N / 2)
$2 = Closest-Pair(right half)
!
$ = min($1, $2)
avoid sorting by y-coordinate from scratch
Delete all points further than $ from separation line L O(N)

Sort remaining points by y-coordinate. O(N log N) Upper bound. Can be improved to O(N log N).

Scan points in y-order and compare distance between Lower bound. In quadratic decision tree model, any algorithm for
each point and next 11 neighbors. If any of these O(N)
distances is less than $, update $. closest pair requires #(N log N) steps.

return $.
}

32 33
1854 Cholera Outbreak, Golden Square, London

Nearest Neighbor

http://content.answers.com/main/content/wp/en/c/c7/Snow-cholera-map.jpg
34 35

Nearest Neighbor Voronoi Diagram

Input. N Euclidean points. Voronoi region. Set of all points closest to a given point.
Voronoi diagram. Planar subdivision delineating Voronoi regions.
Nearest neighbor problem. Given a query point p, which one of original Fact. Voronoi edges are perpendicular bisector segments.
N points is closest to p?

Algorithm Preprocess Query


Brute 1 N
Goal N log N log N

Voronoi of 2 points Voronoi of 3 points


(perpendicular bisector) (passes through circumcenter)

36 37
Voronoi Diagram Voronoi Diagram: Applications

Voronoi region. Set of all points closest to a given point. Toxic waste dump problem. N homes in a region. Where to locate
Voronoi diagram. Planar subdivision delineating Voronoi regions. nuclear power plant so that it is far away from any home as possible?
Fact. Voronoi edges are perpendicular bisector segments.
looking for largest empty circle
(center must lie on Voronoi diagram)

Path planning. Circular robot must navigate through environment with


N obstacle points. How to minimize risk of bumping into a obstacle?

robot should stay on Voronoi diagram of obstacles

Reference: J. O'Rourke. Computational Geometry.

Quintessential nearest neighbor data structure.

38 39

Voronoi Diagram: More Applications Scientific Rediscoveries

Anthropology. Identify influence of clans and chiefdoms on geographic regions.


Year Discoverer Discipline Name
Astronomy. Identify clusters of stars and clusters of galaxies.
1644 Descartes Astronomy "Heavens"
Biology, Ecology, Forestry. Model and analyze plant competition.
Cartography. Piece together satellite photographs into large "mosaic" maps. 1850 Dirichlet Math Dirichlet tesselation
Crystallography. Study Wigner-Setiz regions of metallic sodium. 1908 Voronoi Math Voronoi diagram
Data visualization. Nearest neighbor interpolation of 2D data. 1909 Boldyrev Geology area of influence polygons
Finite elements. Generating finite element meshes which avoid small angles.
1911 Thiessen Meteorology Thiessen polygons
Fluid dynamics. Vortex methods for inviscid incompressible 2D fluid flow.
1927 Niggli Crystallography domains of action
Geology. Estimation of ore reserves in a deposit using info from bore holes.
Geo-scientific modeling. Reconstruct 3D geometric figures from points. 1933 Wigner-Seitz Physics Wigner-Seitz regions
Marketing. Model market of US metro area at individual retail store level. 1958 Frank-Casper Physics atom domains
Metallurgy. Modeling "grain growth" in metal films. 1965 Brown Ecology area of potentially available
Physiology. Analysis of capillary distribution in cross-sections of muscle tissue.
1966 Mead Ecology plant polygons
Robotics. Path planning for robot to minimize risk of collision.
1985 Hoofd et al. Anatomy capillary domains
Typography. Character recognition, beveled and carved lettering.
Zoology. Model and analyze the territories of animals.
Reference: Kenneth E. Hoff III
References: http://voronoi.com, http://www.ics.uci.edu/~eppstein/geom.html
40 41
Fortune's Algorithm Fortune's Algorithm

Fortune's algorithm. Sweep-line algorithm can be implemented in


O(N log N) time.
but very tricky to get right due to
degeneracy and floating point!

Algorithm Preprocess Query


Brute 1 N
Fortune N log N log N

http://www.diku.dk/hjemmesider/studerende/duff/Fortune

42 43

Discretized Voronoi Hoff's Algorithm

Discretized Voronoi. Solve nearest neighbor problem on an N-by-N grid. Hoff's algorithm. Align apex of a right circular cone with sites.
!Minimum envelope of cone intersections projected onto plane is
the Voronoi diagram.
!View cones in different colors & render Voronoi.

Brute force. For each grid cell, maintain closest point. When adding a Implementation. Draw cones using standard graphics hardware!
new point to Voronoi, update N2 cells. http://www.cs.unc.edu/~geom/voronoi/siggraph_paper/voronoi.pdf

44 45
Delaunay Triangulation Summary

Delaunay triangulation. Triangulation of N points such that no point Summary. Many fundamental geometric problems require ingenuity
is inside circumcircle of any other triangle. to solve large instances.

Fact 0. It exists and is unique (assuming no degeneracy). Problem Brute Cleverness


Fact 1. Dual of Voronoi (connect adjacent points in Voronoi diagram). convex hull N2 N log N
Fact 2. No edges cross & O(N) edges.
closest pair N2 N log N
Fact 3. Maximizes the minimum angle for all triangular elements.
Fact 4. Boundary of Delaunay triangulation is convex hull. furthest pair N2 N log N
Fact 5. Shortest Delaunay edge connects closest pair of points. Delaunay triangulation N4 N log N

polygon triangulation N2 N

asymptotic time to solve a 2D problem with N points


Delaunay
Voronoi

46 47

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy