Pi/无限数

发布于 2024-07-27 23:48:26 字数 116 浏览 7 评论 0原文

我对计算中的无限数很好奇,特别是圆周率。

对于计算机来说,要渲染一个圆,它必须了解 pi。 但如果它是无限的怎么可能呢?

我是否对此关注太多? 它会只使用四舍五入的值吗?

I'm curious about infinite numbers in computing, in particular pi.

For a computer to render a circle it would have to understand pi. But how can it if it is infinite?

Am I looking too much into this? Would it just use a rounded value?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

海螺姑娘 2024-08-03 23:48:26

一般情况下,近似值就足够了。 要“渲染”一个圆,计算机只需要充分了解 pi 即可以所需的任何分辨率(有限)准确渲染。

编辑:正如其他人指出的那样,您甚至不需要 pi 来渲染圆。 不过,问题的要点是“计算机如何处理像 pi 这样的数字?” 他们使用近似值,无论谁使用这些近似值,都必须决定它们对于给定目的是否足够精确。

An approximation is generally sufficient. To "render" a circle, the computer only needs to understand pi well enough to render accurately at whatever resolution (finite) is required.

Edit: as others have pointed out, you don't even need pi to render a circle. Still, the gist of the question was "how do computers deal with numbers like pi?" They use approximations, and whoever is using those approximations must decide whether they are precise enough for the given purpose.

烟酉 2024-08-03 23:48:26

从数学上讲,计算机既有限又不连续,因此既不能完全知道 PI,也不能正确绘制圆。

然而,在数字领域中,这些都不存在,因此近似 PI 就足够了,然后用它来近似渲染圆,从而产生与根据精确 PI 计算出的完全相同的像素。

不管怎样,生成的像素也不是真正的圆,因为它们是数字点的有限集合,而圆是由无限多个点组成的曲线,其中大多数点具有无理数值。

(有人向我指出,PI 通常不用于绘制圆,这是事实,但是,用于绘制圆的方法与用于表达和/或计算 PI 值的公式有关,这仍然有同样的问题)。

Mathematically, computers are both finite and non-continuous and therefore can neither know PI completely, nor correctly render a circle.

However, in the digital realm neither of these exist anyway, so it is sufficient to approximate PI and then use that to approximately render the circle, resulting in exactly the same pixels that would have been calculated from an exact PI anyway.

Either way, the resulting pixels aren't really a circle either, because they are a finite collection of digital points and a circle is a curve made up of an infinite number of points, most with irrational values.

(It has been pointed out to me that PI is not normally used to plot a circle, which is true, however, the methods used to plot a circle are related to the formulas used to express and/or calculate the value of PI, which still have the same issues).

策马西风 2024-08-03 23:48:26

我在某个地方看到一个证据,证明要以毫米精度绕宇宙画一个圆,你需要的 pi 位数少于 100 位,换句话说,比那些有太多空闲时间的人计算出的数字要少得多(或者计算能力太强了...)。 现在,如果我能找到那个证据就好了……(编辑)找到了

Somewhere I saw a proof that to draw a circle around the universe to millimetre accuracy, you'd need less than 100 digits of pi, in other words, far fewer digits than have been calculated by people with too much time on their hands (or too much computing power...). Now, if only I could find that proof... (edit) found it

π浅易 2024-08-03 23:48:26

你根本不需要 PI 来画一个圆。 画圆的方法有很多种。 最简单的方法是使用正弦和余弦。

我在 8 位机器上最常看到的算法是 Bresenham 圆。 您甚至不需要浮点数学。

You don't need PI at all to draw a circle. There are many ways to draw a circle. The naive way is with sine and cosine.

The algorithm I saw most often on 8-bit machines was Bresenham's circle. You don't even need floating point math for that.

冰雪梦之恋 2024-08-03 23:48:26

编程语言对 pi 和类似的“无限”数字使用舍入常数。

为了获得更高的精度,您可以使用迭代算法,只要需要就可以循环。

Programming languages use a rounded constant for pi and similar "infinite" numbers.

In order to get higher precision you use iterative algorithms that are looped for as long as is required.

ゞ花落谁相伴 2024-08-03 23:48:26

计算机只是使用 pi 的近似值。

来自 MSDN 关于 System.Math.PI 的文章

该字段的值为
3.14159265358979323846。

顺便说一句:PI 不是无限的。 它是无理数,意味着它有无限多个不重复的小数位。 PI 有几种非常简短的表达式。 (有关更多详细信息,请参阅维基百科页面

以下是​​ PI 的一个非常简短的表达式:

PI 作为整体

Computers just use a good approximation of pi.

From MSDN's article on System.Math.PI

The value of this field is
3.14159265358979323846.

BTW: PI is NOT infinite. It is irrational, meaning that it has an infinite number of non-repeating decimal places. There are several expressions for PI that are very short. (see the Wikipedia page for more details)

Here is a wonderfully short expression for PI:

PI as Integral

初相遇 2024-08-03 23:48:26

我相信它四舍五入到一个非常小的数字,并且很可能是一个常数。 如果您使用 PHP,这就是 PI 的渲染方式:

echo pi(); // 3.1415926535898
echo M_PI; // 3.1415926535898

就像您在高中时只需要 3.14159 一样,计算机只需要这么多就可以得到相当准确的结果。

I believe it rounds it to a very small number, and is most likely a constant. If you use PHP, this is how PI renders:

echo pi(); // 3.1415926535898
echo M_PI; // 3.1415926535898

Just like you only need 3.14159 in High School, computers only need so much to get it fairly accurate.

坚持沉默 2024-08-03 23:48:26

近似值通常“足够好”,无论您是使用此网站另一个

“渲染”是另一回事。 当屏幕分辨率有限时,π 的完美值并不那么重要。

更新:计算可能是另一回事,与渲染不同。 某些应用程序可能需要比标准双精度更高的精度。 这取决于问题。

An approximation is often "good enough", whether you get it using a method from this site or another one.

"Rendering" is another matter. When you have a finite screen resolution, a perfect value of π doesn't matter as much.

UPDATE: Calculation might be another matter, different from rendering. Some applications might require greater precision than the standard double gives. It depends on the problem.

梦归所梦 2024-08-03 23:48:26

Pi 不是无限的,它是无理数,这意味着你不能将它表示为商。 它有无限多个数字。
http://en.wikipedia.org/wiki/Proof_that_π_is_irrational

关于计算 find这里有一些信息。
http://en.wikipedia.org/wiki/Computing_π

不错的页面是还有这个
http://3.14159265358979323846264338327950 2884197169399375105820974944592.com/

Pi is not infinite it is irrational, what mean that you can not express it as quotient. It has infinite number of digits.
http://en.wikipedia.org/wiki/Proof_that_π_is_irrational

About computing find some informations here.
http://en.wikipedia.org/wiki/Computing_π

Nice page is also this
http://3.141592653589793238462643383279502884197169399375105820974944592.com/

烧了回忆取暖 2024-08-03 23:48:26

计算机只使用圆周率的舍入值,当然除非有特殊情况,例如科学计算。 例如,在 python 中 pi 表示为:

>>> import math
>>> math.pi
3.1415926535897931

您可以在 IDLE(Python 交互式解释器)中亲自测试一下。

Computers just use rounded values of pi, unless of course there is a special case such as scientific computing. For example, in python pi is represented as:

>>> import math
>>> math.pi
3.1415926535897931

You can test this out for yourself in IDLE, pythons interactive interpreter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文