140 likes | 154 Views
Learn two approaches to determine if a point is inside or outside a shape: the Odd-Even Rule and Nonzero Winding Rule. Explore ray casting methods, edge crossings, winding numbers, and compute dot and cross products for accurate shape filling.
E N D
We know how to draw outlines • Can we just fill the “inside”? • …but how do we know the difference between the inside and outside? • Can we determine if a point is inside a shape?
One Approach:The Odd-Even Rule 0 • Choose an arbitrary point • Draw ray to a distant point • Don’t intersect any vertices • What’s a “distant” point? • Count edges crossed • Odd count means interior • Even count means exterior 1 2 1 3 1 2 CS-321Dr. Mark L. Hornick
Odd-Even Result 1 2 1 1 3 CS-321Dr. Mark L. Hornick 1
Another approach:Nonzero Winding Rule 0 • Choose a point • Draw ray to a distant point • Don’t intersect any vertices • Consider edges crossed (right hand rule) • Subtract 1 when ray to edge is clockwise • Add 1 when ray to edge is counter-clockwise • Nonzero count means interior • Count = “Winding number” -1 -2 -1 -1 -1 0 CS-321Dr. Mark L. Hornick
Nonzero Winding Example −1 −2 −1 −1 −1 −1 CS-321Dr. Mark L. Hornick
Computing Winding Number • Compute cross product • Between ray and edge • Sign of z value determines direction • +z implies CCW (add 1 to winding number) Seetext, page 128 CS-321Dr. Mark L. Hornick
VA=(1,0,0) VB=(2,0,0) E u=(1,1,0) Cross Product Example “−1” means u crosses E clockwise CS-321Dr. Mark L. Hornick
Cross Product Simplification negative means clockwise CS-321Dr. Mark L. Hornick
Computing Winding Number • Compute dot product • Use perpendicular to ray vs. edge • If ray is given by (ux, uy), perpendicular is (- uy, ux) • Sign of product determines direction • +product implies “right-to-left” (add 1 to winding number) Seetext, page 128 CS-321Dr. Mark L. Hornick
Again, “−1” means u crosses E from left to right VA=(1,0,0) VB=(2,0,0) E u=(1,1,0), w = (−1,1,0) [“right-to-left” perpendicular to u] Dot Product Example CS-321Dr. Mark L. Hornick
Dot Product Simplification Same result as from cross product! CS-321Dr. Mark L. Hornick
Inside-Outside Tests Summary • Odd-even rule • Generalized from scan-line fill • May produce unusual results if edges intersect • Nonzero winding number rule • Alternate way of determining interior CS-321Dr. Mark L. Hornick