编程语言
首页 > 编程语言> > python 根据余弦定理计算两边的夹角

python 根据余弦定理计算两边的夹角

作者:互联网

前面写过C#的。

import numpy

def GetAngle(sta_point, mid_point, end_point):
    ma_x = sta_point.X-mid_point.X
    ma_y = sta_point.Y-mid_point.Y
    mb_x = end_point.X-mid_point.X
    mb_y = end_point.Y-mid_point.Y
    ab_x = sta_point.X-end_point.X
    ab_y = sta_point.Y-end_point.Y
    ab_val2 = ab_x * ab_x + ab_y * ab_y
    ma_val2 = ma_x * ma_x + ma_y * ma_y
    mb_val2 = mb_x * mb_x + mb_y * mb_y
    cos_M = (ma_val2+mb_val2-ab_val2) / (2 * numpy.sqrt(ma_val2)*numpy.sqrt(mb_val2))
    angleAMB = numpy.arccos(cos_M)/numpy.pi * 180
    return angleAMB

 

标签:ab,ma,mb,python,point,end,余弦定理,val2,夹角
来源: https://www.cnblogs.com/yzhyingcool/p/11415255.html