import numpy as np
def calc_angle(x):
# 判断斜率为正或负
if x>=0:
angle = np.rad2deg(np.arctan(x))
else:
angle = 180 + np.rad2deg(np.arctan(x))
return angle
# 定义两个点坐标
x1, y1 = 0, 0
x2, y2 = 1, 1
# 计算斜率
slope = (y2-y1)/(x2-x1)
# 计算角度
angle_deg = calc_angle(slope)
print("Angle (degrees) between line with slope", slope, "and horizontal is", angle_deg)
06-24
161
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)