Python 计算三点角度

x1 = 0

y1 = 3

x2 = 0

y2 = 0

x3 = 6

y3 = 0

abx = x1 - x2

aby = y1 - y2

cbx = x3 - x2

cby = y3 - y2

abmcb = abx * cbx + aby * cby

dab = math.sqrt(abx * abx + aby * aby)

dcd = math.sqrt(cbx * cbx + cby * cby)

cos = abmcb / (dab * dcd) # 计算余弦

print(cos)

result = math.acos(cos) # 反余弦

print(result)

print(math.degrees(result)) # 角度