[WPI] [cs4731] [Classes]

cs4731, D96/97 Class 12

Inside Outside Tests

The inside/outside test tells whether a point is inside or outside a polygon. The line-crossing algorithm discussed in Class 6 is one way to perform this test. Another way is to take the polygon edges vertices in pairs and sum the angles formed with the point when going along edges in the polygon.

If the angles sum to "zero" (be sure to leave some tolerance for roundoff errors in the computer), then the point is outside. If it is not zero, the point is inside the polygon. In that case, the sign of the sum is another way to test whether the path is CW or CCW.

One way to perform the angle test that works properly in 2D with all possible cases of points is to use these definitions and equations:

Be sure to use the C/C++ function atan2() to get the correct 4-quadrant result.

Clipping Algorithm

We examined another clipping algorithm that is slower than the ones discussed in Class 11 but which has the advantage of working with any convex polygon.

Take the polygon edges in the usual CCW order starting at any vertex.If one of the line endpoints is outside the edge and the line intersects the edge between the edge vertices, then move the endpoint to its intersection with the edge. Repeat with the other line endpoint. If the line survives clipping (neither point is outside of any edge), render it.


 
WPI Home Page
[cs4731] [Classes]

Contents ©1997, Norman Wittels
Updated 14Apr97