geometry

# geometry - Geometric Algorithms Geometric Algorithms...

This preview shows pages 1–3. Sign up to view the full content.

Robert Sedgewick and Kevin Wayne • Copyright © 2006 • http://www.Princeton.EDU/~cos226 Geometric Algorithms Reference: Chapters 24-25, Algorithms in C, 2 nd Edition, Robert Sedgewick. 2 Geometric Algorithms Applications. ! Data mining. ! VLSI design. ! Computer vision. ! Mathematical models. ! Astronomical simulation. ! Geographic information systems. ! Computer graphics (movies, games, virtual reality). ! Models of physical world (maps, architecture, medical imaging). History. ! Ancient mathematical foundations. ! Most geometric algorithms less than 25 years old. Reference: http://www.ics.uci.edu/~eppstein/geom.html airflow around an aircraft wing 3 Geometric Primitives Point: two numbers (x, y). Line: two numbers a and b [ax + by = 1] Line segment: two points. Polygon: sequence of points. Primitive operations. ! Is a point inside a polygon? ! Compare slopes of two lines. ! Distance between two points. ! Do two line segments intersect? ! Given three points p 1 , p 2 , p 3 , is p 1 -p 2 -p 3 a counterclockwise turn? Other geometric shapes. ! Triangle, rectangle, circle, sphere, cone, … ! 3D and higher dimensions sometimes more complicated. any line not through origin 4 Intuition Warning: intuition may be misleading. ! Humans have spatial intuition in 2D and 3D. ! Computers do not. ! Neither has good intuition in higher dimensions! Is a given polygon simple? we think of this algorithm sees this 1 6 5 8 7 2 7 8 6 4 2 1 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 1 10 3 7 2 8 8 3 4 6 5 15 1 11 3 14 2 16 no crossings

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
5 Polygon Inside, Outside Jordan curve theorem. [Veblen 1905] Any continuous simple closed curve cuts the plane in exactly two pieces: the inside and the outside. Is a point inside a simple polygon? Application. Draw a filled polygon on the screen. http://www.ics.uci.edu/~eppstein/geom.html 6 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 ]); if (( cond1 || cond2 ) && above ) crossings ++; } return ( crossings % 2 != 0 ); } y = y i + 1 " y i x i + 1 " x i ( x " x i ) + y i where x i # x # x i + 1 ( x i + 1 , y i + 1 ) ( x i , y i ) ( x , y ) Polygon Inside, Outside: Crossing Number Does line segment intersect ray? 7 CCW. Given three point a, b, and c, is a-b-c a counterclockwise turn? ! Analog of comparisons in sorting. ! Idea: compare slopes. Lesson. Geometric primitives are tricky to implement. ! Dealing with degenerate cases. ! Coping with floating point precision.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 11

geometry - Geometric Algorithms Geometric Algorithms...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online