Triangle - Triangle Intersection/Collision Detection
Author |
Message |
ncvitak
![](http://compsci.ca/v3/uploads/user_avatars/121314691151b50efbb9d9b.png)
|
Posted: 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
} |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
|
|
|
![](images/spacer.gif) |
ncvitak
![](http://compsci.ca/v3/uploads/user_avatars/121314691151b50efbb9d9b.png)
|
|
|
|
![](images/spacer.gif) |
|
|