Computational Geometry Exercise session #1 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 1 Administrivia • Exercise sessions (Shprinzak 202): Wednesday, 11:00 – 11:45. • Course web page: www.cs.huji.ac.il/~compgeom • Course email: compgeom@cs.huji.ac.il • Reception hours (Ross 28): Wednesday, 10:00 – 11:00 (notify by email to course) Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 2 1
Mission statement • Complement main lectures: � Technical details � Algorithm Examples • Present and discuss homework. • Give examples related to homework. • New material related to current topic. Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 3 Session 1 topics • Geometric primitives � Distance measures � Vector cross products � Geometric predicates • Point in polygon queries � Simple polygons � Convex polygons • Closest pair of points Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 4 2
Geometric primitives • Distance between two planar points p and q d ( p , q ) = [( p 1 - q 1 ) 2 + ( p 2 - q 2 ) 2 ] 1/2 • L w metric distance between points in R d d w ( p , q ) = [ Σ d i =1 ( p i - q i ) w ] 1/ w • Signed distance between point p =( p 1 , p 2 ) and line L : ax+by+c =0 (with a 2 + b 2 =1) d ( p , L ) = ap 1 +bp 2 +c Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 5 Vector cross products (3D) b = ( b 1 , b 2 , b 3 ) α a = ( a 1 , a 2 , a 3 ) i j k × = = − + − + − a b a a a ( a b a b ) i ( a b a b ) j ( a b a b ) k 1 2 3 2 3 3 2 3 1 1 3 1 2 2 1 b b b 1 2 3 × = sin( α a b ab ) Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 6 3
Vector cross products (2D) b = ( b 1 , b 2 ) r α p a = ( a 1 , a 2 ) q a a × = = − 1 2 a b ( a b a b ) 1 2 2 1 b b 1 2 × = sin( α a b ab ) p p 1 1 2 = = − + − + − 2 area ( p , q , r ) q q 1 p ( q r ) p ( r q ) q r q r 1 2 1 2 2 2 1 1 1 2 2 1 r r 1 1 2 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 7 Geometric Predicates • Building blocks of geometric algorithms • Require two properties: � Efficiency � Robustness r q r q w p p Is r to the left of the segment pq ? Do the segments pq and rw intersect? Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 8 4
Point-Line orientation r q r q q r p p p 1 left ( CCW ) = = − ori sign ( area ( p , q , r )) 1 right ( CW ) 0 colinear Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 9 Segment intersection r q w p Do the segments pq and rw intersect? Suggestions? Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 10 5
Segment intersection I • Quick filter – bounding box test � For segments to intersect, both x and y intervals must overlap. � { p 1 , p 2 } and { p 3 , p 4 } are {lower left, upper right} vertices of bounding boxes. Condition for overlap: ( p 2 x ≥ p 3 x ) & ( p 4 x ≥ p 1 x ) & ( p 2 y ≥ p 3 y ) & ( p 4 y ≥ p 1 y ) p 4 p 2 p 3 p 1 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 11 Segment intersection II r q w p ori ( p , q , r )* ori ( p , q , w ) = -1 & ori ( w , r , p )* ori ( w , r , q ) = -1 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 12 6
Segment intersection - special cases improper intersection segments overlap impossible after filter Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 13 Point in simple polygon Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 14 7
Point in convex polygon Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 15 Point in star-shaped polygon kernel Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 16 8
Closest pair of points S 1 S 2 δ 2 δ 1 Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 17 Closest pairs – the merge step δ δ p δ Yaron Ostrovsky-Berman, Computational Geometry, Spring 2005 18 9
Recommend
More recommend