#
def isInterArea(testPoint,AreaPoint):#testPoint为待测点[x,y]
LBPoint = AreaPoint[0]#AreaPoint为按顺时针顺序的4个点[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
LTPoint = AreaPoint[1]
RTPoint = AreaPoint[2]
RBPoint = AreaPoint[3]
a = (LTPoint[0]-LBPoint[0])*(testPoint[1]-LBPoint[1])-(LTPoint[1]-LBPoint[1])*(testPoint[0]-LBPoint[0])
b = (RTPoint[0]-LTPoint[0])*(testPoint[1]-LTPoint[1])-(RTPoint[1]-LTPoint[1])*(testPoint[0]-LTPoint[0])
c = (RBPoint[0]-RTPoint[0])*(testPoint[1]-RTPoint[1])-(RBPoint[1]-RTPoint[1])*(testPoint[0]-RTPoint[0])
d = (LBPoint[0]-RBPoint[0])*(testPoint[1]-RBPoint[1])-(LBPoint[1]-RBPoint[1])*(testPoint[0]-RBPoint[0])
#print(a,b,c,d)
if (a>0 and b>0 and c>0 and d>0) or (a<0 and b<0 and c<0 and d<0):
return True
else:
return False
python中判断某点是否在四边形内部(可推广到多边形)
最新推荐文章于 2024-07-27 12:20:46 发布