PMC and Booleans Point-Membership Classification Regularized Booleans between polygons
Point-in-polygon test in 2D Given a polygon P and a point q in the plane of P, how would you test whether q lies inside P? This is called “Point-Membership Classification” (abbreviated PMC)
Triangle-based point-in-polygon test Algorithm for testing whether point Q is inside polygon P Boolean PinPoly(Q,P) { pt O = origin or some arbitrary point; Boolean in:= false; for (each edge (A,B) of P) if (PinT(O,A,B,Q)) in := ! in; return in; } boolean PinT(A,B,C,P) {return (right(A,B,P)== right(B,C,P)) && (right(A,B,P)== right(C,A,P)) ;} Why does it work?
XOR shading of a polygon in 2D AB is the set of points that lie in A or in B, but not in both AB := {p: pA pB } Let A, B, C … N be primitives, then ABC… N is the set of points contained in an odd number of these primitives AB := {p: (pA) XOR (pB) XOR (pC) XOR … XOR (pN) } How to shade a polygon A in 2D: Polygon P has edges Ei. Triangle Ti = convex hull of O+Ei. P = T1T2T3… Tn To fill P: fill each Ti while toggling status of visited pixel o E5 o E4 o E3 E2 o o E1 o P Assume no pixel lies on boundary of any triangle
Example of XOR polygon filling
Relation to ray-casting approach? A point Q lies in a set P if a ray from Q intersects the boundary of P an odd number of times If ray hits a vertex or edge or is tangent to a surface, pick another ray We do the same thing. Look at an example in 2D. Here: Only edges E1, E2, E3 intersect ray from Q to O Thus only triangles T1, T2, T3 contain Q Q O Ray from Q Q is in because it is contained in an odd number of triangles
Computing polygon area Two methods: Sum of signed areas of triangles, each joining an arbitrary origin o to a different edge(a,b) SUM oaR(ob) for each edge (a,b) Sum of signed areas between each oriented edge the x-axis y by b ay a x ax bx area(a,b):=(ay+by)(bx–ax)/2
Area of the symmetric difference The symmetric difference AB measures the discrepancy between the two solids A and B It is 0 when A==B Assume that A and B are bounded by consistently oriented polygonal loops. Can I compute AB by summing areas of triangles?
Boolean operation on polygons Diminishing boundary principle: The Boundary of a Boolean combination of shapes is a subset of the union of their boundaries Strategy: Generate-Split-Select Generate a sufficient set of candidates: edges of polygons Split them at their pairwise intersections Select the edge-segments on the boundary of the result How to identify a good edge segment? Must separate in from out t s
Boolean A–B (also written A \ B) A A B B
Regularization AB ? B A