1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| function inPoly(pt, poly2)
Dim coord, coordPt
coord =poly2
coordPt =pt
poly =split(coord,",",-1,1)
monPoint =split(coordPt,",",-1,1)
Dim npoints
npoints=Ubound(poly)
Dim xnew,ynew,xold,yold,x1,y1,x2,y2,i
Dim inside
inside=false
if (npoints/2 < 3) then
inPoly = 1
end if
xold=poly(npoints-2)
yold=poly(npoints-1)
for i=0 to npoints
xnew=poly(i)
ynew=poly(i+1)
if xnew > xold then
x1=xold
x2=xnew
y1=yold
y2=ynew
else
x1=xnew
x2=xold
y1=ynew
y2=yold
end if
if ((xnew < monPoint(0)) = (monPoint(0) <= xold) and ((monPoint(1)-y1)*(x2-x1) < (y2-y1)*(monPoint(0)-x1))) then
inPoly = true
else
inPoly = false
end if
xold=xnew
yold=ynew
i=i+2
next
end function |
Partager