| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
众所周知,sin(90) 的结果应该是 1。 
 
可 Python 却给出了一个“错误”的答案: 
 
- Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32
 
 - Type "help", "copyright", "credits" or "license()" for more information.
 
 - >>> from math import sin
 
 - >>> sin(90)
 
 - 0.8939966636005579
 
 - >>> 
 
  复制代码 
 
其实 Python 的答案并没有错。让我们来康康 Python 的官方文档: 
 
- >>> help(sin)
 
 - Help on built-in function sin in module math:
 
  
- sin(x, /)
 
 -     Return the sine of x (measured in radians).
 
  
- >>> 
 
  复制代码 
 
Return the sine of x 返回 x 的 sin 值,没问题; 
 
注意括号里面的—— measured in radians。 
 
以弧度为单位? 
 
 
 
 
仔细想想:sin(90) 的 90 单位是什么?是度(°)。90 的意思是 90 度。 
 
“度”是 degrees,并不是 radians。所以我们需要将 90 从 degrees 转换成 radians。可以使用 math.radians() 方法: 
 
- >>> from math import radians, sin
 
 - >>> help(radians)
 
 - Help on built-in function radians in module math:
 
  
- radians(x, /)
 
 -     Convert angle x from degrees to radians.
 
  
- >>> 
 
  复制代码 
 
试试看: 
 
- >>> from math import radians, sin
 
 - >>> help(radians)
 
 - Help on built-in function radians in module math:
 
  
- radians(x, /)
 
 -     Convert angle x from degrees to radians.
 
  
- >>> sin(radians(90))
 
 - 1.0
 
 - >>> 
 
  复制代码 
 
Great!获取到了正确的结果——1.0。 
 
接下来是 asin。 
 
asin 相当于数学中的 sin-1,即 sin 的逆过程。 
 
这也一样,asin 也需要进行 radians/degrees 转换,不过因为是逆过程,连转换也反过来了,变成了 radians -> degrees。 
 
- >>> from math import asin
 
 - >>> asin(1.0)
 
 - 1.5707963267948966
 
 - >>> 
 
  复制代码 
 
像 radians() 一样,degrees() 则负责从角度(degrees)转换为弧度(radians)。 
 
它正确地输出了结果:90.0。 
 
- >>> from math import degrees, asin
 
 - >>> degrees(asin(1.0))
 
 - 90.0
 
 - >>> 
 
  复制代码 |   
 
 
 
 |