Function, windingIntersect()
Posted: Wed Sep 30, 2015 7:26 am
Straightforward winding number function for determining if a point is within the bounds of a regular or irregular polygon.
Needed it with a radial number selector thingaling and the basic intersect (and pointIntersect from it's answers) didn't mesh too well to my problem without 'dirty' fixes.
Anyway hope it helps someone.
Needed it with a radial number selector thingaling and the basic intersect (and pointIntersect from it's answers) didn't mesh too well to my problem without 'dirty' fixes.
Anyway hope it helps someone.
Code: Select all
answer windingIntersect(mouseLoc(),the points of grc "polygonmess")
function windingIntersect p0, inPoints
put 0 into winding
split p0 by comma
repeat with i = 1 to (the num of lines in inPoints-1)
put line i of inPoints into p1
put line i+1 of inPoints into p2
split p1 by comma
split p2 by comma
if (p1[2] <= p0[2]) then
if (p2[2] > p0[2]) then
if ((((p2[1]-p1[1])*(p0[2]-p1[2]))-((p0[1]-p1[1])*(p2[2]-p1[2]))) > 0) then
add 1 to winding
end if
end if
else
if (p2[2] <= p0[2]) then
if ((((p2[1]-p1[1])*(p0[2]-p1[2]))-((p0[1]-p1[1])*(p2[2]-p1[2]))) < 0) then
subtract 1 from winding
end if
end if
end if
end repeat
if (winding <> 0) then
return true
else
return false
end if
end windingIntersect