如何确定 Pi (π) 的准确性

发布于 2024-07-20 10:55:39 字数 254 浏览 14 评论 0原文

在优化我们正在开发的游戏时,我们正进入每个 CPU 周期都至关重要的阶段。 我们使用弧度来计算围绕其他对象旋转的对象的位置,我想减少查找表中不必要的精度。 为此,我们大量使用预定义的 Pi。 这个 Pi 应该有多准确?

所以,我的问题是:

  • 多准确才足够准确?
  • 或者更好,如何确定所需的准确度? >

Optimizing a game we're developing, we're running into the phase where every CPU cycle won counts. We using radians for position calculations of objects circling around other objects and I want to cut the needless accuracy in my lookup tables. For that, we make heavy use of a predefined Pi. How accurate should this Pi be?

So, my question is:

  • How accurate is accurate enough?
  • Or even better, how to determine the needed accuracy?

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

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

发布评论

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

评论(7

绾颜 2024-07-27 10:55:39

您不妨使其与您可以存储的任何浮点表示形式一样准确。 使用更精确的相同类型的浮点数执行计算不会花费更长的时间。

准确度通常以有效位数来衡量; 您需要自己决定您感兴趣的精度有多少位。如果您使用不太准确的 pi 值,该值的不准确度将传播到它所在的其他计算中。

You might as well just make it as accurate as whatever floating-point representation you can store is. It won't take longer to perform calculations using a more accurate floating-point number of the same type.

Accuracy is generally measured as number of significant digits; you'll need to decide for yourself how many digits of accuracy you're interested in. If you use a less accurate value for pi, that value's inaccuracy will propagate to the other calculations it's in.

魂归处 2024-07-27 10:55:39

作为比较:我认为 NASA 使用精确到小数点后 7 位的 pi 来对接太空。

首先,我们需要确定您的位置计算需要有多准确,即程序中取决于 pi 的公式必须有多准确。 我们需要从这里开始,以便了解要实现此目标需要多准确的 pi。

一旦确定了这一点,您就可以使用或多或少直接的数值分析来确定 pi 所需的准确度。 我可以帮助你,但我需要位置公式来做到这一点:)

编辑:我怀疑你的公式线性依赖于 pi,即你没有使用一些晦涩的函数 f(x,y,z,pi)其中 pi 是平方或相似的。 在这种情况下,公式的精度是 pi 精度的一个因子,例如 k*eps(pi)。 否则它基本上是一个因子乘以 f 对 pi 的导数。 不计算所有其他参数 f 的准确性取决于!

干杯!

As a comparision: I think NASA use pi with 7 decimals accuracy to be able to dock into space.

First of all we need to determine how accurate your position calculations need to be, i.e. how accurate the formulas in your program which depends on pi have to be. We need to start there in order to know how accurate pi you need to achive this.

Once that has been determined, you can probably use more or less straight forward numerical analysis to determine how good accuracy you need for pi. I can help you with that, but I need the position formulas to do that :)

Edit: I suspect that your formulas are linearly dependent on pi, i.e. you aren't using some obscure function f(x,y,z,pi) where pi is squared or similar. In that case the accuracy of your formula is a factor times the pi accuracy, e.g. k*eps(pi). Otherwise it's basically a factor times the derivative of f with respect to pi. Not counting the accuracy of all other parameters f depends on !

Cheers !

爱冒险 2024-07-27 10:55:39

这取决于您的计算中有多少有效数字。 给定公式

C = pi * d,

如果您想知道直径为一英里的圆的周长有多少英寸,则需要六位数的 pi 来计算保持您想要的精度,因为一英里有 63,360 英寸,周长有 199,051 英寸。 由于答案中有六位有效数字,因此我需要六位 pi 才能将其计算到所需的精度。

3.14 * 63,360 = 198950.4

3.142 * 63,360 = 199077.12

3.1416 * 63,360 = 199051.776

3.14159 * 63,360 = 199051.1424

正如你所看到的,我只用了 5 位数字就得到了正确的答案pi​​,但情况并非总是如此。 您至少需要与有效数字一样多的 pi 位数,以确保您有足够的精度。

It depends on how many significant digits you have in your calculation. Given the formula

C = pi * d

if you want to know how many inches in the circumference of a circle one mile in diameter, you'd need six digits of pi to keep the accuracy you want, since there are 63,360 inches in a mile, and there would be 199,051 inches in the circumference. Since there are six significant digits in the answer, I need six digits of pi to calculate it to the needed accuracy.

3.14 * 63,360 = 198950.4

3.142 * 63,360 = 199077.12

3.1416 * 63,360 = 199051.776

3.14159 * 63,360 = 199051.1424

As you can see, I got the right answer in this case with only 5 digits of pi, but that's not always going to be the case. You need at least as many digits of pi as you have significant digits to ensure you have enough precision.

安静 2024-07-27 10:55:39

如果您要预先计算并存储它,则只需使用系统上的数学库即可尽可能准确地计算一次。 一个不错的选择是:

double PI = (16.0 * atan(1/5)) - (4.0 * atan(1/239));

这将为您提供相当准确的 PI 值,您可以在启动时计算该值并根据需要重复使用。 很难获得比易于重用的版本更准确的版本。

If you're precalculating it and storing it, you can just use the math library on your system to compute it one time as accurately as possible. A good option is:

double PI = (16.0 * atan(1/5)) - (4.0 * atan(1/239));

That will give you a fairly accurate value for PI which you can compute at startup and reuse as needed. It's difficult to get a more accurate version than that which is easily reusable.

凌乱心跳 2024-07-27 10:55:39

目前还不完全清楚你在做什么。 您是否根据角度查找坐标? 在这种情况下,Pi 的准确性根本不重要。 重要的是查找表的大小,您当然会以尽可能高的精度预先计算它。 除了考虑将数据类型从单精度更改为双精度之外,更高的准确性不会花费额外的执行时间。

It's not fully clear what you are doing. Are you looking up coordinates based on an angle? In this case the accuracy of Pi doesn't matter at all. Important is the size of the lookup table and you will of course precalculate it with the highest possible accuracy. Further accuracy doesn't cost additional execution time besides you are thinking about changing the data type from single to double.

与风相奔跑 2024-07-27 10:55:39

如果您预先计算该值,请使其尽可能准确地存储,但要真正了解实际需要的精度,您必须查看公式和其他组件的精度,然后确保您所具有的精度pi 与其他组件相匹配。 数值分析将为您提供大量线索。

If you are pre-calculating the value make it as accurate as feasible to store but to get the true feel of what accuracy in actually needed you have to look at your formulas and the accuracy of other components and than make sure the accuracy you have for pi matches that for other components. Numerical analysis will give you plaenty of clues.

你列表最软的妹 2024-07-27 10:55:39

圆周率的新公式

Pi=2.m.sin(90/m)

Pi=3.m.sin(60/m)

Pi=4.m.sin(45/m)

Pi=5.m.sin(36/m)

对于数以百万计的圆周率免费计算器 XP,XM,….. 推荐 m=1.0E+10000000 要成功计算器您需要安装 netframework2.0

http://harry-j-smith-memorial.com/index.html

new formula for pi

Pi=2.m.sin(90/m)

Pi=3.m.sin(60/m)

Pi=4.m.sin(45/m)

Pi=5.m.sin(36/m)

For millions across the value of PI free calculator XP,XM,….. recommend m=1.0E+10000000 to the success of the calculator you need to install netframework2.0

http://harry-j-smith-memorial.com/index.html

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