Python:将弧度转换为度 [英] Python: converting radians to degrees

查看:251
本文介绍了Python:将弧度转换为度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python.org数学库中,我只能找到带有cos/sin/tan/acos/asin/atan的math.cos(x).这将返回以弧度为单位的答案.如何获得度数的答案?

In the python.org math library, I could only find math.cos(x), with cos/sin/tan/acos/asin/atan. This returns the answer in radians. How can I get the answer in degrees?

这是我的代码:

import math

x = math.cos(1)
y = x * 180 / math.pi
print y
30.9570417874

我的度数计算器给我:

cos(1)
0.9998476...

推荐答案

Python在math包中包含两个函数; radians将度数转换为弧度,degrees将度数转换为弧度.

Python includes two functions in the math package; radians converts degrees to radians, and degrees converts radians to degrees.

要匹配计算器的输出,您需要:

To match the output of your calculator you need:

>>> math.cos(math.radians(1))
0.9998476951563913

请注意,所有的三角函数都在角度和三角形两侧的比率之间转换. cos,sin和tan以弧度表示的角度作为输入并返回比率; acos,asin和atan以比率作为输入,并返回以弧度表示的角度.您只转换角度,而不转换比例.

Note that all of the trig functions convert between an angle and the ratio of two sides of a triangle. cos, sin, and tan take an angle in radians as input and return the ratio; acos, asin, and atan take a ratio as input and return an angle in radians. You only convert the angles, never the ratios.

这篇关于Python:将弧度转换为度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆