题目:
代码:
# -*- coding:utf-8 -*-
def rayCasting(p, poly):
px = p['x']
py = p['y']
flag = False
i = 0
l = len(poly)
j = l - 1
#for(i = 0, l = poly.length, j = l - 1; i < l; j = i, i++):
while i < l:
sx = poly[i]['x']
sy = poly[i]['y']
tx = poly[j]['x']
ty = poly[j]['y']
#点与多边形顶点重合
if (sx == px and sy == py) or (tx == px and ty == py):
return (px, py)
#判断线段两端点是否在射线两侧
if (sy < py and ty >= py) or (sy >= py and ty < py):
#线段上与射线 Y 坐标相同的点的 X 坐标
x = sx + (py - sy) * (tx - sx) / (ty - sy)
#点在多边形的边上
if x ==