我有两个以弧度为单位的值c[1]
和c[3]
。我需要将弧度转换为度数,并且我不知道如何对这些数字做些什么来获得它们的度数。我一直在寻找互联网,我无法找到任何我能理解的东西。我已经尝试设计自己的方式来做到这一点,但我确定我甚至没有接近。我尝试过以下方法:
z = (((c[1] * 180) + 180) + ((c[3] * 180) + 180))
z = (((c[1] * math.pi) / 180) + ((c[3] * math.pi) / 180) / 2)
z = (c[1] * (90/math.pi) - (c[3] * (90/math.pi)))
z = math.atan2(c[3], c[1])
z = (math.degrees(c[1]) + math.degrees(c[3])) * 2
z = c[1]
z = (math.asin(c[3]) / math.acos(c[1]))
如何从2弧度获得度数值?
答案 0 :(得分:0)
弧度转换的程度用公式(n deg)*(pi / 180度)完成。
z = (c[1]*(math.pi/180.0) + (c[1]*(math.pi/180)
如果你需要经常做一些功能。
def DegtoRad(deg):
return (deg)*(math.pi/180)
或作为lambda
DegtoRad = lambda x: x*(math.pi/180)
记住,如果你没有导入math / math.pi,这一切都不会起作用。 最好用实际的文字变量来定义pi,直到你的精度需求。
答案 1 :(得分:0)
这在网上找不是很难吗? - 是吗?
http://www.mathwarehouse.com/trigonometry/radians/convert-degee-to-radians.php
该公式与@ user2913685的公式相反:num * 180 / pi (一个容易犯的错误)
这是python的一个例子:
pi = 3.14159265
rad_val = 7
deg_val = rad_val*180/pi
print(deg_val)
给出输出:
401.07045704986604
这使用pi作为3.14159265,并且不使用模块数学。显然你可以像在另一个答案中那样做,但是在改变公式之后。
答案 2 :(得分:0)
在完成你的评论之后,我不认为你得到c [1]和c [3]的弧度两个角度。相反,你正在获得方向余弦。如果您以弧度为单位获取角度,则值的范围为-pi到pi。相反,该值从-1到1(即cos(-pi)到cos(pi))。
您可以先将值更改为以弧度表示的角度,然后更改为度数(如果这是您想要的)。正如一个警告,角度的余弦是对称的...... 所以:
In [12]: zip(angles, (cos(angles)))
Out[12]:
[(-3.1415926535897931, -1.0),
(-2.8108986900540254, -0.94581724170063464),
(-2.4802047265182576, -0.78914050939639346),
(-2.1495107629824899, -0.5469481581224267),
(-1.8188167994467224, -0.24548548714079912),
(-1.4881228359109546, 0.082579345472332394),
(-1.1574288723751871, 0.40169542465296937),
(-0.82673490883941936, 0.67728157162574099),
(-0.49604094530365161, 0.87947375120648907),
(-0.16534698176788387, 0.98636130340272232),
(0.16534698176788387, 0.98636130340272232),
(0.49604094530365161, 0.87947375120648907),
(0.82673490883941891, 0.67728157162574132),
(1.1574288723751867, 0.40169542465296976),
(1.4881228359109544, 0.082579345472332616),
(1.8188167994467221, -0.2454854871407989),
(2.1495107629824899, -0.5469481581224267),
(2.4802047265182576, -0.78914050939639346),
(2.8108986900540254, -0.94581724170063464),
(3.1415926535897931, -1.0)]
但是,
In [11]: zip(angles, arccos(cos(angles)))
Out[11]:
[(-3.1415926535897931, 3.1415926535897931),
(-2.8108986900540254, 2.8108986900540254),
(-2.4802047265182576, 2.4802047265182576),
(-2.1495107629824899, 2.1495107629824899),
(-1.8188167994467224, 1.8188167994467224),
(-1.4881228359109546, 1.4881228359109546),
(-1.1574288723751871, 1.1574288723751871),
(-0.82673490883941936, 0.82673490883941936),
(-0.49604094530365161, 0.49604094530365156),
(-0.16534698176788387, 0.16534698176788418),
(0.16534698176788387, 0.16534698176788418),
(0.49604094530365161, 0.49604094530365156),
(0.82673490883941891, 0.82673490883941891),
(1.1574288723751867, 1.1574288723751867),
(1.4881228359109544, 1.4881228359109544),
(1.8188167994467221, 1.8188167994467221),
(2.1495107629824899, 2.1495107629824899),
(2.4802047265182576, 2.4802047265182576),
(2.8108986900540254, 2.8108986900540254),
(3.1415926535897931, 3.1415926535897931)]
这意味着从你的方向角度来看你的角度,你需要这样做:
In [13]: def toAng(a): return sign(a)*arccos(a)
将为您提供正确的角度:
In [19]: zip(angles, toAng(cos(angles)))
Out[19]:
[(-3.1415926535897931, -3.1415926535897931),
(-2.8108986900540254, -2.8108986900540254),
(-2.4802047265182576, -2.4802047265182576),
(-2.1495107629824899, -2.1495107629824899),
(-1.8188167994467224, -1.8188167994467224),
(-1.4881228359109546, 1.4881228359109546),
(-1.1574288723751871, 1.1574288723751871),
(-0.82673490883941936, 0.82673490883941936),
(-0.49604094530365161, 0.49604094530365156),
(-0.16534698176788387, 0.16534698176788418),
(0.16534698176788387, 0.16534698176788418),
(0.49604094530365161, 0.49604094530365156),
(0.82673490883941891, 0.82673490883941891),
(1.1574288723751867, 1.1574288723751867),
(1.4881228359109544, 1.4881228359109544),
(1.8188167994467221, -1.8188167994467221),
(2.1495107629824899, -2.1495107629824899),
(2.4802047265182576, -2.4802047265182576),
(2.8108986900540254, -2.8108986900540254),
(3.1415926535897931, -3.1415926535897931)]
最后,如果你需要将它转换为度数,你可以这样做:
在[20]中:def toAng(a):返回180 *符号(a)* arccos(a)/ pi
In [21]: zip(angles, toAng(cos(angles)))
Out[21]:
[(-3.1415926535897931, -180.0),
(-2.8108986900540254, -161.05263157894737),
(-2.4802047265182576, -142.10526315789474),
(-2.1495107629824899, -123.1578947368421),
(-1.8188167994467224, -104.21052631578948),
(-1.4881228359109546, 85.263157894736835),
(-1.1574288723751871, 66.31578947368422),
(-0.82673490883941936, 47.368421052631582),
(-0.49604094530365161, 28.421052631578949),
(-0.16534698176788387, 9.4736842105263346),
(0.16534698176788387, 9.4736842105263346),
(0.49604094530365161, 28.421052631578949),
(0.82673490883941891, 47.368421052631554),
(1.1574288723751867, 66.315789473684191),
(1.4881228359109544, 85.263157894736835),
(1.8188167994467221, -104.21052631578947),
(2.1495107629824899, -123.1578947368421),
(2.4802047265182576, -142.10526315789474),
(2.8108986900540254, -161.05263157894737),
(3.1415926535897931, -180.0)]
这为你提供了角度的正确角度......
注意我正在使用sign
,pi
等是numpy对象的环境。在您的程序中,您可能需要单独导入它们。