鱼C论坛

 找回密码
 立即注册
查看: 1837|回复: 1

[技术交流] 【数学笔记】1. radians / degrees

[复制链接]
发表于 2023-6-29 14:37:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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 返回 xsin 值,没问题;

注意括号里面的—— measured in radians

以弧度为单位?

36.png

仔细想想: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
>>> 

本帖被以下淘专辑推荐:

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-6-29 20:03:20 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-9-22 15:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表