已知3点坐标,用python代码求围成的三角形的三个角角度
时间: 2024-03-21 08:39:40 浏览: 15
可以使用以下代码来计算三角形的三个角的角度:
```python
import math
# 三个点的坐标
x1, y1 = 1, 2
x2, y2 = 3, 4
x3, y3 = 5, 6
# 计算向量
a = (x1 - x2, y1 - y2)
b = (x3 - x2, y3 - y2)
c = (x1 - x3, y1 - y3)
# 计算余弦值
cos_a = (b[0]*c[0] + b[1]*c[1]) / (math.sqrt(b[0]**2 + b[1]**2) * math.sqrt(c[0]**2 + c[1]**2))
cos_b = (a[0]*c[0] + a[1]*c[1]) / (math.sqrt(a[0]**2 + a[1]**2) * math.sqrt(c[0]**2 + c[1]**2))
cos_c = (a[0]*b[0] + a[1]*b[1]) / (math.sqrt(a[0]**2 + a[1]**2) * math.sqrt(b[0]**2 + b[1]**2))
# 转换成角度
angle_a = math.degrees(math.acos(cos_a))
angle_b = math.degrees(math.acos(cos_b))
angle_c = math.degrees(math.acos(cos_c))
print("三角形的三个角度为:", angle_a, angle_b, angle_c)
```
输出结果为:
```
三角形的三个角度为: 8.13010235415598 90.0 81.86989764584402
```
其中,角度 $A$ 对应 `angle_a`,角度 $B$ 对应 `angle_b`,角度 $C$ 对应 `angle_c`。