1、#转化为通过三边计算三角形面积
1 import math 2 def cal_area(p1,p2,p3):
9 a = float(math.sqrt((p2[0]-p3[0])*(p2[0]-p3[0])+(p2[1]-p3[1])*(p2[1]-p3[1]))) 10 b = float(math.sqrt((p1[0]-p3[0])*(p1[0]-p3[0])+(p1[1]-p3[1])*(p1[1]-p3[1]))) 11 c = float(math.sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1]))) 12 s = (a+b+c)/2
13 S = (s*(s-a)*(s-b)*(s-c))**0.5
14 return S
2、#通过三点直接求面积
1 def calc_area(p1, p2, p3): 2 (x1, y1), (x2, y2), (x3, y3) = p1,p2,p3 3 return 0.5 * abs(x2 * y3 + x1 * y2 + x3 * y1 - x3 * y2 - x2 * y1 - x1 * y3)
转载于:https://www.cnblogs.com/lmh001/p/9859121.html