鱼C论坛

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

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

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

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

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

x
众所周知,sin(90) 的结果应该是 1。

可 Python 却给出了一个“错误”的答案:

  1. Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32
  2. Type "help", "copyright", "credits" or "license()" for more information.
  3. >>> from math import sin
  4. >>> sin(90)
  5. 0.8939966636005579
  6. >>>
复制代码


其实 Python 的答案并没有错。让我们来康康 Python 的官方文档:

  1. >>> help(sin)
  2. Help on built-in function sin in module math:

  3. sin(x, /)
  4.     Return the sine of x (measured in radians).

  5. >>>
复制代码


Return the sine of x 返回 xsin 值,没问题;

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

以弧度为单位?

36.png

仔细想想:sin(90) 的 90 单位是什么?是度(°)。90 的意思是 90 度。

“度”是 degrees,并不是 radians。所以我们需要将 90 从 degrees 转换成 radians。可以使用 math.radians() 方法:

  1. >>> from math import radians, sin
  2. >>> help(radians)
  3. Help on built-in function radians in module math:

  4. radians(x, /)
  5.     Convert angle x from degrees to radians.

  6. >>>
复制代码


试试看:

  1. >>> from math import radians, sin
  2. >>> help(radians)
  3. Help on built-in function radians in module math:

  4. radians(x, /)
  5.     Convert angle x from degrees to radians.

  6. >>> sin(radians(90))
  7. 1.0
  8. >>>
复制代码


Great!获取到了正确的结果——1.0。

接下来是 asin

asin 相当于数学中的 sin-1,即 sin 的逆过程。

这也一样,asin 也需要进行 radians/degrees 转换,不过因为是逆过程,连转换也反过来了,变成了 radians -> degrees。

  1. >>> from math import asin
  2. >>> asin(1.0)
  3. 1.5707963267948966
  4. >>>
复制代码


radians() 一样,degrees() 则负责从角度(degrees)转换为弧度(radians)。

它正确地输出了结果:90.0。

  1. >>> from math import degrees, asin
  2. >>> degrees(asin(1.0))
  3. 90.0
  4. >>>
复制代码

本帖被以下淘专辑推荐:

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-6-29 20:03:20 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-6-2 02:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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