1、#转化为通过三边计算三角形面积
import math
def cal_area(p1,p2,p3):
a = float(math.sqrt((p2[0]-p3[0])*(p2[0]-p3[0])+(p2[1]-p3[1])*(p2[1]-p3[1])))
b = float(math.sqrt((p1[0]-p3[0])*(p1[0]-p3[0])+(p1[1]-p3[1])*(p1[1]-p3[1])))
c = float(math.sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])))
s = (a+b+c)/2
S = (s*(s-a)*(s-b)*(s-c))**0.5
return S
2、#通过三点直接求面积
def calc_area(p1, p2, p3):
(x1, y1), (x2, y2), (x3, y3) = p1,p2,p3
return 0.5 * abs(x2 * y3 + x1 * y2 + x3 * y1 - x3 * y2 - x2 * y1 - x1 * y3)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/17098.html