计算两个 3D 三角形是否在同一平面上

发布于 2024-09-19 03:04:09 字数 107 浏览 8 评论 0原文

对于我正在开发的 3D 游戏引擎,我需要计算两个 3D 三角形是否在同一平面上才能相应地显示它。如何计算 3D 空间中三角形的角度?

计算表面法线并比较它们是否会给出 2 个等效法线?

For a 3D game engine I'm working on I need to calculate if two 3D triangles are on the same plane to display it accordingly. How do I calculate the angles of a triangle in 3D space?

Would calculating a surface normal and comparing those ever give me 2 equivalent normals?

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

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

发布评论

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

评论(2

九厘米的零° 2024-09-26 03:04:10

你为什么要这么做?您希望测试的三角形数量是多少?对于实时渲染算法来说似乎有点复杂!

无论如何:

计算三角形的法线n。然后计算平面方程:
ax + by + cz + d = 0,其中 (a,b,c) 为三角形法线,d = - dot(n,P)代码>(P是三角形顶点之一)。对第二个三角形执行相同的操作。

如果四个值abcd相等或相反(全部在一起),则两个平面相同。

Why do you want to do that? What is the number of triangle you expect to test? It seems a little bit complex for a real time rendering algorithm!

Anyway:

Compute the normal n of the triangle. Then compute the plane equation:
a.x + b.y + c.z + d = 0 with (a,b,c) being your triangle normal and d = - dot(n,P) (P is one of your triangle vertex). Do the same for the second triangle.

The two planes are the same if the four valuesabcd are equals or opposite (all together).

奈何桥上唱咆哮 2024-09-26 03:04:10

你所问的问题在数字上是不可能的。舍入误差将使此类测试完全无关。

但是,您可能想要测试“两个三角形是否在同一平面上,且在一定的公差范围内”。这很难做到,而且在这里,舍入误差也可能会扰乱任何可能的方法。事实上,只要三角形很薄,它们所在的平面就有很大的不确定性。

如果您确实想要的话,我可以向您推荐一些文献(您最好的选择是查看 CGAL 库看看他们是否实施了与您的问题相关的措施)。任何事情都可能涉及任意精度的浮点、巧妙的运算重新排序,并且无论如何都会导致不精确的结果。

因此,我强烈建议您为实际问题找到另一种方法。

如果您尝试计算通过三个点的平面方程,然后测试其他三个点,则舍入误差是一个(巨大)问题。还有另一种解决方案。

您可能想要计算六个点的惯性矩阵,将其对角化并查看其是否最小特征值在其他两个特征值的某个微小值之内。这意味着您的六个点实际上位于同一平面上,且在公差范围内。

What you are asking is impossible numerically. Roundoff errors will make such a test completely irrelevant.

However, you may want to test "if two triangles are on the same plane, within some tolerance". This is very difficult to do, and here too, roundoff errors will likely mess up any method possible. Indeed, whenever the triangles are thin, there is a great incertitude about the plane on which they live.

I could point you to some litterature if you really want (your best bet would be to look at the CGAL library and see if they implemented something relevant to your problem). Anything will likely involves arbitrary precision floating points, clever reordering of operations, and will anyway lead to unprecise results.

I thus strongly suggest you find another approach for your actual problem.

Roundoff errors are a (huge) problem if you try to compute the equation of the plane passing through three points and then testing the three other ones. There is another solution.

You may want to compute the inertia matrix of your six points, diagonalize it and see if its smallest eigenvalue is within some tiny value of the two other ones. This will imply that your six points actually lie on the same plane, within a tolerance.

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