{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

ORourkeCH1 - UMass Lowell Computer Science 91.504 Advanced...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: UMass Lowell Computer Science 91.504 Advanced Algorithms Computational Geometry Prof. Karen Daniels Spring, 2010 Spring Lecture 1 Start of Part I Material O'Rourke Chapter 1 Part I O Rourke O'Rourke Chapter 1 Polygon Triangulation: Art Gallery Theorems Triangulation: Theory Area of Polygon Implementation Issues Segment Intersection Triangulation: Implementation Art Gallery Theorems Polygons The Art Gallery Theorem Fiske's Proof of Sufficiency Art Gallery Theorems: Polygons What is a polygon? "region of a plane bounded by a finite collection of line segments forming a simple closed curve" curve" ei ei +1 = vi +1 i = 0,..., n - 1 ei e j = 0 / j i +1 n=5 v2 e2 e1 v1 v3 P e3 e0 v0 e4 v4 convex nonconvex simple nonsimple Art Gallery Theorems: The Theorem How many stationary guards are needed to guard the room? Visibility: 2 range x can see y iff closed xy P 2 Find G(n) = the maximum (over all n-vertex polygons) of the nminimum number of guards needed to cover the polygon. Empirically: E i i ll n is sufficient (2D) n necessary f small n? 3? 4? 5? for ll ? Guess: in general n/3 necessary Art Gallery Theorems: Fiske's Proof Given arbitrary n-vertex P: nTriangulate P using diagonals Diagonal: Diagonal: line segment between 2 vertices that are clearly visible to each other (no grazing contact) Form triangulation graph G i l i h G can be 3-colored (proof later...) 3(proof later...) Place a guard at each same-colored samevertex of G This covers all of P By pigeon-hole principle: n/3 guards pigeon- Triangulation Theory Existence of a Diagonal Properties of Triangulations Triangulation Dual 3-Coloring Proof C l i P f Triangulation Theory: Existence of a Diagonal Step 1: Every polygon must have >= 1: 1 strictly convex vertex (no y ( collinearity) Step 2: Every polygon of n >= 4 2: > vertices has a diagonal Conclusion: Conclusion: Every n-vertex polygon nP may be partitioned into triangles by adding (>=0) diagonals [proof by induction using diagonals] Triangulation Theory: Properties Every triangulation of an n-vertex polygon nP uses n-3 diagonals and consists of n-2 ng ntriangles. The sum of the internal angles of an nnvertex polygon is (n-2). (n-2) 9 vertices 7 triangles 6 diagonals Triangulation Theory: Duality The dual of a triangulation is a tree with each node of degree at most 3. g "2"2-Ears" Theorem: every polygon of n >= 4 Theorem: vertices has at least 2 nonoverlapping ears. ears ear ear Triangulation Theory: 3-Coloring "2-Ears" Th "2-E " Theorem can be used to easily b d il prove 3-colorability of triangulation 3graphs h Induction on n Base case: n = 3 For n >= 4: a b c 2-ears theorem guarantees that an ear abc exists apply inductive hypothesis to polygon P' without ear "reattaching" ear adds back in one vertex (w.l.o.g. b) color b whatever color a and c don't use result is a 3-coloring of P 3- A Triangulation Approach Algorithm: Algorithm: TRIANGULATION Al ith Initialize the ear tip status of each vertex. while n > 3 do Locate an ear tip v2. Output diagonal v1 v3. Delete v2. Update the ear tip status of v1 and v3. v2 v1 v3 Triangulate EarInit Diagonal InCone LeftOn Diagonalie Intersect IntersectProp Xor Left Area2 Between Collinear Area of Polygon Cross Product Determinant Form Area of a Convex Polygon Area of a C A f Convex Q d il Quadrilateral l Area of a Nonconvex Quadrilateral Area from an Arbitrary Center Volume in >= 3 Dimensions > Area of Polygon: Cross Product or Determinant ^ i A0 B0 ^ j A1 B1 ^ k ^ ^ A2 = ( A1 B2 - A2 B1 )i + ( A2 B0 - A0 B2 ) ^ + ( A0 B1 - A1 B0 )k j B2 0 f 2D for 1 Area (T ) = ( A0 B1 - A1 B0 ) 2 2 Area(T ) = (b0 - a0 )(c1 - a1 ) - (c0 - a0 )(b1 - a1 ) c B T a A or... b a0 2 Area(T ) = b0 c0 a1 1 b1 1 = (b0 - a0 )(c1 - a1 ) - (c0 - a0 )(b1 - a1 ) c1 1 Area of Polygon: Convex Quadrilateral Could fi d C ld find area of polygon via f l i triangulation...but we want to avoid this! To T see how, first consider triangulation for h fi t id t i l ti f 2 easy polygon cases: Convex Convex Quadrilateral Area A (Q ) = A (a, b, c) + A (a, c, d ) = A (d , a, b) + A (d , b, c) Area Area Area Area d a b c n -1 i =0 v2 v3 v1 v0 v4 Area A ( P ) = A (v0 , v1 , v2 ) + A (v0 , v2 , v3 ) + ... + A (v0 , vn - 2 , vn -1 ) Area Area Area 2 A ( P ) = ( xi yi +1 - yi xi +1 ) Area d a b c Area of Polygon: (continued) Nonconvex Quadrilateral Area (Q ) = Area (a, b, c) + Area ( a, c, d ) negative area c Arbitrary Center Area (T ) = Area ( p, a, b) + Area ( p, b, c ) + Area ( p, c, a ) a c d b T a p1 b p2 2 A ( P ) = ( xi yi +1 - yi xi +1 ) Area i =0 n -1 more efficient 2 Area ( P ) = ( xi + xi +1 )( yi +1 - yi ) i =0 n -1 Area of Polygon: Volume Determinant area formulation extends to higher dimensions. g z c=(0,0,1) In 3D: a0 6Volume(T ) = b0 c0 d0 a1 b1 c1 d1 a2 1 b2 1 a=(1,0,0) ( , , ) d=(0,0,0) b=(0,1,0) y c2 1 d2 1 x Implementation Issues Representation of a Point Representation of a Polygon Code for Area Text describes C code. C or Java code available from text's Web site f t t' W b it Implementation Issues: Point C code uppercase pp constants #define #define typedef #define typedef X Y 0 1 X is 0th element of point; Y is 1st enum { FALSE, TRUE } bool; DIM 2 /* Dimension of points */ int tPointi[DIM]; /* Type integer point */ i for integer g lowercase type identifier integers to minimize roundoff errors (but overflow is possible...) Implementation Issues: Polygon typedef struct tVertexStructure tsVertex; / /* Used only in NEW() */ NEW(). / typedef tsVertex *tVertex; struct tVertexStructure { int vnum; /* Index */ tPointi v; /* Coordinates */ bool ear; /* TRUE iff an ear */ tVertex next,prev; V doubly linked circular list }; for easy vertex deletion/insertion /* Global variable definitions */ tVertex vertices = NULL; nvertices = 0; ; int /* "Head" of circular list. */ /* Total number of polygon vertices. */ p yg Implementation Issues: Area Code /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns twice the signed area of the triangle determined by a,b,c. The area is positive if a,b,c are oriented ccw, negative if cw,and zero if the points are collinear. ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ int Area2( tPointi a, tPointi b, tPointi c ) { return (b[X] - a[X]) * (c[Y] - a[Y]) (c[X] - a[X]) * (b[Y] - a[Y]); } 2 Area(T ) = (b0 - a0 )(c1 - a1 ) - (c0 - a0 )(b1 - a1 ) minimizes number of multiplications to help avoid overflow Segment Intersection Diagonals: key triangulation step Left Boolean Intersection Segment I S Intersection Code i C d Infinite slopes are problematic, so avoid slopes! Segment Intersection: Diagonals Diagonal: Diagonal: line segment between 2 vertices that are clearly visible to each other (no grazing contact) which one is a legal diagonal? s = vi v j is a diagonal of P iff s e = 0 for each edge e of P not incident on vi or v j / s is internal to P in a neighborhood of vi and v j Segment Intersection: Left /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns true iff c is strictly to the left of the directed line through a to b. y g ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ bool Left( tPointi a, tPointi b, tPointi c ) { return AreaSign( a, b, c ) > 0; } returns sign (+,0,-) of area (+,0,instead of area value itself c b a Segment Intersection: Boolean Intersection /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns true iff ab properly intersects cd: they share a point interior to both segments. The properness of the intersection is ensured by using strict leftness. ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ / bool IntersectProp( tPointi a, tPointi b, tPointi c, tPointi d ) { / /* Eliminate improper cases */ cases. / if ( Collinear(a,b,c) || Collinear(a,b,d) || Collinear(c,d,a) || Collinear(c,d,b)) return FALSE; return Xor( Left(a,b,c), Left(a b d) ) && Xor( Left(c d a) Left(c d b) ); Left(a b c) Left(a,b,d) Left(c,d,a), Left(c,d,b) } c b c b a d a c d a b d which are "proper" intersections? Segment Intersection: Intersection Code / /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns TRUE iff segments ab and cd intersect, properly or improperly. ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ bool Intersect( tPointi a tPointi b tPointi c tPointi d ) a, b, c, { if ( IntersectProp( a, b, c, d ) ) return TRUE; else if (Between( a, b, c ) || Between( a, b, d ) || Between( c, d, a ) || Between( c, d, b )) return TRUE; else ; return FALSE; } Triangulation: Implementation Algorithm: Algorithm: TRIANGULATION Initialize the ear tip status of each vertex. while n > 3 do Locate an ear tip v2. Output diagonal v1 v3. Delete v2. Update the ear tip status of v1 and v3. v2 v1 v3 Diagonals (Internal or External) InCone (distinguish Internal from External) Triangulation by Ear Removal Analysis Triangulation: Implementation Diagonals (Internal or External) /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns TRUE iff (a,b) is a proper internal *or* external diagonal of P, *ignoring edges incident to a and b*. ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ bool Diagonalie( tVertex a, tVertex b ) { tVertex c, c1; /* For each edge ( g (c,c1) of P */ ) c = vertices; do { c1 = c->next; c/* Skip edges incident to a or b */ if ( ( c != a ) && ( c1 != a ) && ( c != b ) && ( c1 != b ) && Intersect( a->v, b->v, c->v, c1->v ) abcc1) return FALSE; c = c->next; c} while ( c != vertices ); return TRUE; } Triangulation: Implementation InCone /*--------------------------------------------------------------------/*--------------------------------------------------------------------Returns TRUE iff the diagonal (a,b) is strictly internal to the polygon in the neighborhood of the a endpoint. ---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/ bool InCone( tVertex a, tVertex b ) { tVertex a0,a1; /* a0,a,a1 are consecutive vertices. */ a1 = a->next; aa0 = a->prev; a/* If a is a convex vertex ... */ if( LeftOn( a->v, a1->v, a0->v ) ) aa1a0return Left( a->v, b->v, a0->v ) && Left( b->v, a->v, a1->v ); aba0baa1/* Else a is reflex: */ return !( LeftOn( a->v, b->v, a1->v ) && LeftOn( b->v, a->v, a0->v ) ); aba1baa0} Triangulation: Implementation /* Prints out n-3 diagonals (as pairs of integer indices) which form a triangulation of P*/ nvoid Triangulate( void ){ Triangulate( tVertex v0, v1, v2, v3, v4; /* five consecutive vertices */ int n = nvertices; /* number of vertices; shrinks to 3. */ EarInit(); while ( n > 3 ) { /* I hil Inner loop searches f an ear and removes it */ l h for d it. v2 = vertices; do { if (v2->ear) { /* Ear found. */ (v2v3 = v2->next; v4 = v3->next; v1 = v2->prev; v0 = v1->prev; v2v3v2v1PrintDiagonal( v1, v3 ); v1v1->ear = Diagonal( v0, v3 ); v3->ear = Diagonal( v1, v4 );/* Update earity*/ v3v1v1->next = v3; v3->prev = v1; /* Cut off ear. */ v3vertices = v3; /* In case the head was v2 */ v2. n--; --; break; /* out of inner loop; resume outer loop */ } /* end if ear found */ v2 = v2->next; 2 v22 } while ( v2 != vertices ); } /* end outer while loop */ } /* end Triangulate */ Triangulation: Implementation Analysis Nave Analysis Tighter Analysis Algorithm: Algorithm: TRIANGULATION Initialize the ear tip status of each vertex. O(n2) O(n2) while n > 3 do + + Locate an ear tip v2. O(n) O(n) O( ) Output diagonal v1 v3. iterations iterations Delete v2. O(n) O(n) ( ) O(n) Update the ear tip status of v1 and v3. iterations Total: O(n3) Total: O(n2) Triangulation can be done in O(nlgn) time with different approach. ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online