为什么在编程中使用弧度? [英] Why do we use radians in programming?

查看:125
本文介绍了为什么在编程中使用弧度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我和下一个家伙一样喜欢弧度,并且通常更喜欢在度数上使用弧度,但是为什么我们在编程中使用弧度?

I like radians just as much as the next guy, and typically prefer to use them over degrees, but why do we use radians in programming?

要旋转某些东西180度,您需要将其旋转 3.14159265 ... 。当然,大多数语言对于pi都有某种常数,但是为什么当我们可以使用整数而不是整数时,尤其是对于简单程序,为什么要使用像pi这样的非理性数字呢?

To rotate something 180 degrees, you need to rotate it by 3.14159265.... Sure, most languages have some kind of constant for pi, but why do we ever want to use irrational numbers like pi when we can instead use integers, especially for simple programs?

我们依靠计算机说 3.14159265 与pi足够接近,正弦和余弦之类的函数会返回正确的值,但是如果计算机精度太高,则值将略有变化( sin(3.14159265)= 0.00000000358979303 )。使用180度时这不是问题。

We're relying on the computer to say that 3.14159265 is close enough to pi that functions like sine and cosine return the proper values, but if a computer is too accurate, then the values would be slightly off (sin(3.14159265) = 0.00000000358979303). This isn't an issue when using 180 degrees.

推荐答案

实际上问题,它只是以不同的方式显示,尤其是如果您不坚持90度增量。

It actually is an issue, it just shows up in different ways, especially if you don't stick to 90 degree increments.

最终,归结为用于计算触发函数的机制在弧度的术语(即使是由CPU的微代码实现;您可能想查看数值方法文本以获取详细信息,但它们确实希望以弧度完成),并且以度为单位工作,然后需要在两者之间进行恒定转换,从而导致累积错误。由于浮点数(尤其是超验数)已经内置了很多错误,因此在顶部加上额外的转换不仅会减慢速度,而且还会增加更多可避免的错误。

Ultimately, it comes down to the mechanisms used to compute trig functions are defined in terms of radians (even when implemented by a CPU's microcode; you might want to examine a numerical methods text for details, but they really do want to be done in radians) and working in degrees then requires constant conversions between the two, leading to cumulative errors. Since floating point (and transcendental numbers in particular) has plenty of error built into it already, adding that additional conversion on top is both slowing things down and adding even more avoidable error.

这篇关于为什么在编程中使用弧度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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