利用python实现判断空间上5个点是否属于同个平面。
数学原理
方法:利用向量的叉乘,按照顺时针取向量进行叉乘,所得值同号,则说明点在四边形内部。
#代码实现:
def isInside(testPoint, Point): # testPoint为待测点[x,y], Point为按顺时针顺序的4个点[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]
A = Point[0]
B = Point[1]
C = Point[2]
D = Point[3]
# 计算叉乘
a = (B[0] - A[0]) * (testPoint[1] - A[1]) - (B[1] - A[1]) * (testPoint[0] - A[0])
b = (C[0] - B[0]) * (testPoint[1] - B[1]) - (C[1] - B[1]) * (testPoint[0] - B[0])
c = (D[0] - C[0]) * (testPoint[1] - C[1]) - (D[1] - C[1]) * (testPoint[0] - C[0])
d = (A[0] - D[0]) * (testPoint[1] - D[1]) - (A[1] - D[1]) * (testPoint[0] - D[0])
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



