Python:从cos(a)和sin(a)值中查找角度[0:360]的度数

Python:从cos(a)和sin(a)值中查找角度[0:360]的度数,python,trigonometry,Python,Trigonometry,我想找到我角度的0到360度之间的度数。 我有一个数据框,有两列:cos和sin值 我想你的意思是: import math angle = math.degrees(math.acos(df['cos'])) 要真正停留在[0360],您必须检查负cos并调整代码,如: import math a_acos = math.acos(df['cos']) if df['sin'] < 0: angle = math.degrees(-a_acos) % 360 else:

我想找到我角度的0到360度之间的度数。 我有一个数据框,有两列:cos和sin值


我想你的意思是:

import math

angle = math.degrees(math.acos(df['cos']))

要真正停留在[0360],您必须检查负cos并调整代码,如:

import math
a_acos = math.acos(df['cos'])
if df['sin'] < 0:
   angle = math.degrees(-a_acos) % 360
else: 
   angle = math.degrees(a_acos)

您可以使用numpy模块,该模块包含处理向量的三角函数,例如and,它获取sin和cos值并返回角度。您可以使用该功能将弧度转换为度。

不要搞符号检查。 你需要原因和罪恶

import math
a_acos = math.acos(df['cos'])
if df['sin'] < 0:
   angle = math.degrees(-a_acos) % 360
else: 
   angle = math.degrees(a_acos)
import math
for i in range(360):
   angle = i * math.pi / 180
   cs = math.cos(angle)
   sn = math.sin(angle)
   angle2 = math.atan2(sn, cs)  # ALWAYS USE THIS
   angle2 *= 180 / math.pi
   if angle2 < 0: angle2 += 360
   print(angle2)