【python】已知三点计算三角形面积

#转化为通过三边计算三角形面积
import math
def cal_area(p1,p2,p3):
    ''' :param p: [x,y] :return S: area of triangle '''
    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
#通过三点直接求面积
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)
    原文作者:Vincent_gc
    原文地址: https://blog.csdn.net/a529975125/article/details/79850751
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞