已知四边形四个顶点坐标,求面积

def calcArea(m1,m2,n1,n2,j1,j2,k1,k2):
q1 = Point(m1,m2)
q2 = Point(n1,n2)
q3 = Point(j1,j2)
q4 = Point(k1,k2)
d12 = calcDistance(q1.y, q1.x, q2.y, q2.x)
d23 = calcDistance(q2.y, q2.x, q3.y, q3.x)
d34 = calcDistance(q3.y, q3.x, q4.y, q4.x)
d41 = calcDistance(q4.y, q4.x, q1.y, q1.x)
d24 = calcDistance(q2.y, q2.x, q4.y, q4.x)
k1 = (d12+d41+d24)/2
k2 = (d23+d34+d24)/2
s1 = (k1*(k1-d12)(k1-d41)(k1-d24))**0.5
s2 = (k2*(k2-d23)(k2-d34)(k2-d24))**0.5
s = s1+s2
return s
将四边形分为两个三角形,根据海伦公式:s=(a+b+c)/2,则面积=√s(s-a)(s-b)(s-c)

你可能感兴趣的:(python)