Computer Science Canada Triangle - Triangle Intersection/Collision Detection |
Author: | ncvitak [ Wed Jun 05, 2013 9:28 pm ] |
Post subject: | Triangle - Triangle Intersection/Collision Detection |
I am working on a game, and I am going to use triangle - triangle collision detection, since all 3d meshes are made out of triangles. However I can't seem to find out how to do it. Please help me if you can. Thanks! I have the following: // Vector3f: a class i created to represent a 3D vector with public numeric variables x,y,z class Vector3f { public: float x; float y; float z; //additional operator overloads for vector3f - vector3f, or vector3f - scalar operations //Ex: +, -, *, /, etc... }; Vector3f Tri1[3]; //3 Verticies, which can be interpreted as 3D vectors for Triangle 1 Vector3f Tri2[3]; //3 Verticies, which can be interpreted as 3D vectors for Triangle 2 bool TriangleTriangleCollisionDetected(Vector3f T1[3], Vector3f T2[3]) { //code to check if the 2 triangles intersect //returns true if the intersect //returns false if they do not intersect } |
Author: | Insectoid [ Wed Jun 05, 2013 9:55 pm ] |
Post subject: | RE:Triangle - Triangle Intersection/Collision Detection |
I was reading through this StackOverflow thread, which has a good solution, but then I got to the bottom and it links to this thread on compsci.ca. Basically, you need to check all the lines against each other to see if they intersect, and if they don't, then check to see if any corner is inside the other triangle. If they aren't, then they haven't collided. Otherwise, they have. |
Author: | Tony [ Wed Jun 05, 2013 11:01 pm ] |
Post subject: | Re: Triangle - Triangle Intersection/Collision Detection |
ncvitak @ Wed Jun 05, 2013 9:28 pm wrote: I am going to use triangle - triangle collision detection, since all 3d meshes are made out of triangles.
What happens when the two triangles are not in the same plane? http://stackoverflow.com/questions/7113344/find-whether-two-triangles-intersect-or-not Of course this doesn't cover the case where one object is completely inside of another. Are they in a state of collision? |
Author: | ncvitak [ Sat Jun 08, 2013 4:42 pm ] |
Post subject: | Re: Triangle - Triangle Intersection/Collision Detection |
I was able to find this C source code http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/code/opttritri.txt for the following document online http://fileadmin.cs.lth.se/cs/Personal/Tomas_Akenine-Moller/pubs/tritri.pdf This code works extremely well, and a big thank you to Tomas M?ller for sharing it. Since this code is in C, it should be relatively easy to port it to other languages. |