如何纠正浮点错误以下实物仿真:点三角形碰撞检测的3D
- 原始点(X,Y,Z),
- 所需的点(X”,Y ',z')。
- 两个三角形(A,B,C)和(B,C,d),谁共享边缘BC
我使用碰撞检测此方法:
For each Triangle
If the original point is in front of the current triangle, and the desired point is behind the desired triangle:
Calculate the intersection point of the ray (original-desired) and the plane (triangle's normal).
If the intersection point is inside the triangle edges (!)
Respond to the collision.
End If
End If
Next Triangle
问题我我的观点是,有时候这个点落入浮点数学的灰色区域,在那里它非常接近BC线,它不会与任何一个三角形发生碰撞,尽管从技术上讲它应该总是与其中一个碰撞,因为它们共享一个边缘。当发生这种情况时,点在两个边缘共享三角形之间正确通过。我已经用(!)标记了一行代码,因为我相信这是我应该进行更改的地方。
在非常有限的情况下工作的一个想法是跳过边缘测试。有效地将三角形变成飞机。这只适用于我的网格是凸包,但我打算创建凸形。
我特别使用点积和三角法线进行所有前后测试。
这是一个很好的观点,虽然浮点算术中的“平等”是你永远不能指望的东西。 – shoosh 2008-09-19 04:16:21