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?
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).
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.
来源:https://stackoverflow.com/questions/3725630/calculate-if-two-3d-triangles-are-on-the-same-plane