Test if polygon edge is facing another polygon How do I test to see if a polygon edge is facing another polygon? For the edge being tested to return true, the edge needs to be facing a polygon which has a different attribute than itself.



In this example, I am iterating through the edges on Polygon A. Segment 0 and segment 1 would return true for facing the polygon, where segment 2 would return false, because, while it is still facing a polygon, the polygon has the same 'green' attribute.
You can take the normal of the line segment you're testing and find the dot product of that normal and the normal of each segment of the polygon you're testing against. If it is positive, then they are facing the same way. If the dot product is negative, then the line segments are facing in opposite directions. 

If they are facing in opposite directions, then they're either pointing at each other, or away from each other. You can figure out which by calculating a vector from a point on the first segment to a point on the other segment and seeing if it's facing the same direction as its normal (by again using the dot product). If so, they are facing each other, otherwise they're facing away.

You can skip all the tests above by first testing if the polygons are the same color and only doing the tests if they're not.