<p>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. </p>

<p>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.</p>

<p>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.</p>

CC BY-SA 3.0
2017-01-31T05:00:08.793Z
2017-01-31T05:00:08.793Z
user1118321
<p>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.</p>

<p><img src="https://drive.google.com/uc?export=download&amp;id=0B5gF5vQzfd2SMDFERkhxUE1heEk" alt="polygon example"></p>

<p>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.</p>

CC BY-SA 3.0
2017-01-30T21:53:01.200Z
Your example is not visible. Do you work in 2D or 3D?
user18490
CC BY-SA 3.0
2017-01-30T22:30:51.333Z
Strange, I can see it. 2D. Here is another link to the example: http://bit.ly/2kIc4Wg
agarfield
CC BY-SA 3.0
2017-02-01T20:03:15.827Z
You can also raytrace lines. Cast a ray perpendicular to line and test the lines in the scene. Like ray-tracing but in 2D. That would work and would give you accurate results.
user18490
CC BY-SA 3.0
2017-02-02T23:27:43.193Z
In your picture, Segment 2 does face a polygon of a different colour; Polygon D, but you say it should return false for Segment 2.  This implies you need to see if the path is occluded by polygons of the same colour, right?
PeteUK
CC BY-SA 3.0
2017-02-03T06:22:33.780Z
Yes. That's another piece of it. The segment will return false if the _closest_ edge which the edge is facing is of the same type.
agarfield
<algorithm><computational-geometry><geometry>
Test if polygon edge is facing another polygon
agarfield
# Test if polygon edge is facing another polygon

(Asked by: username_0 on 2017-01-30)

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.

![polygon example](https://drive.google.com/uc?export=download&id=0B5gF5vQzfd2SMDFERkhxUE1heEk)

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.

**Tags:** algorithm, computational-geometry, geometry

> **Comments:**
> **username_1**: Your example is not visible. Do you work in 2D or 3D?  
> **username_0**: Strange, I can see it. 2D. Here is another link to the example: http://bit.ly/2kIc4Wg  
> **username_1**: You can also raytrace lines. Cast a ray perpendicular to line and test the lines in the scene. Like ray-tracing but in 2D. That would work and would give you accurate results.  
> **username_2**: In your picture, Segment 2 does face a polygon of a different colour; Polygon D, but you say it should return false for Segment 2.  This implies you need to see if the path is occluded by polygons of the same colour, right?  
> **username_0**: Yes. That's another piece of it. The segment will return false if the _closest_ edge which the edge is facing is of the same type.  

---

## 1 answers

### Answer by username_3 on 2017-01-31. Score: 1

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.


---

