开发者

Can using Bullet3D for 2D only cause floating-point numerical error in Z axis?

开发者 https://www.devze.com 2023-02-16 18:02 出处:网络
I guess it\'s possible to use bullet3D in 2D only mode, but what I\'m concerning is floating-point accura开发者_如何学Gocy error. If all values and operations for Z axis are 0, the Z values may be inf

I guess it's possible to use bullet3D in 2D only mode, but what I'm concerning is floating-point accura开发者_如何学Gocy error. If all values and operations for Z axis are 0, the Z values may be influenced by operations for other axis. If this accumulated, the result may wrong.

However I didn't used bullet3d yet. If you experienced with bullet3d in 2D only mode, please let me know your opinion.


I'm using Bullet physics for a 2D game right now, it works just fine. Bullet provides a method btRigidBody::setLinearFactor that allows you to force the Z axis position to be exactly 0, no matter what. You can even mix 2D and 3D by setting the linear factor only on the objects you want constrained to the plane.

That being said, I am using a shape with some Z-axis depth (just its position is constrained to 2D) so it's not 0 thickness. And even so, because it is thin I do occasionally have problems with it slipping through meshes that it shouldn't. You can use setMargin to combat that.


I don't know about Bullet specifically, but assuming that it's a reasonably well-written library, this will not be an issue.

Floating-point arithmetic is not mysticism. Rounding error does not magically occur, nor is rounding random, fuzzy, or any of the many other terms people use to describe phenomena that they do not understand.

Floating-point arithmetic is deterministic, like everything else on a computer (barring cosmic rays randomly flipping bits). Computations with exact zeros, properly formulated, produce exact zero results. If it is true that all the operations that effect the Z axis are zeros, then the resulting Z coordinate will be exactly zero. If it's not, then the algorithm being used is unsuitable, and I wouldn't trust it for any calculation.

The place where you would run into trouble would be if you were summing quantities with non-zero Z components that are physically supposed to sum to zero; in such a situation, rounding error could accumulate to result in a small, but non-zero Z component. However, it doesn't sound like that's the situation in which you find yourself. It sounds like all of the quantities involved should have zero Z components, and that will be preserved.

0

精彩评论

暂无评论...
验证码 换一张
取 消