a polygon is defined as a sequential list of pairs of points A, B, C .... A. no side AB, BC ... intersects the other side
Define the field Xmin, Xmax, Ymin, Ymax
case 1 control point P is out of field
case 2, the control point P lies inside the box:
Define the "diameter" D of the window {[Xmin, Ymin] - [Xmax, Ymax]} (and add a little extra to avoid possible confusion with D on the side)
Define the gradients M of all sides
Find a gradient Mt different from all gradients M
The test line runs from P in a gradient of Mt to a distance D.
Set the number of intersections to zero.
For each of the sides AB, BC, the test is for the PD to intersect with the side from its launch to, but NOT including its end. Increase the number of intersections if necessary. Note that the zero distance from P to the intersection indicates that P is on the side
An odd number indicates that P is inside the polygon
david n laine Oct 07 '13 at 16:35 2013-10-07 16:35
source share