knownasilya

09-11-2012, 01:17 PM

Hello all :)

So I have a triangle with the following points: p0, p1, p2 in 3D space and I'm testing it against a collision with a AABB (cube).

So far this is the code that I have, but my collision detection (SAT) implementation fails. The failure happens when the triangle projection "overlaps" on the surface normal only, so I'm assuming that the edge normals are not correct since they don't end the test as not intersecting. So I'm guessing I'm having concept/math issues.

// subtract the two to get the edge vector

edge1.sub( p1, p0 );

edge2.sub( p2, p0 );

edge3.sub( p2, p1 );

// 1 Surface normal

Vector3d normal = new Vector3d();

normal.cross( p0, p1 );

normal.normalize();

axes[ 0 ] = normal;

// 3 Edge normals

Vector3d normal1 = new Vector3d();

normal1.cross( edge1, edge2 );

normal1.normalize();

axes[ 1 ] = normal1;

Vector3d normal2 = new Vector3d();

normal2.cross( edge1, edge3 );

normal2.normalize();

axes[ 2 ] = normal2;

Vector3d normal3 = new Vector3d();

normal3.cross( edge3, edge2 );

normal3.normalize();

axes[ 3 ] = normal3;

I'm not sure if the edge normals are actually perpendicular to the surface normal. Am I wrong in my implementation, if so, what can I do to fix it (need to understand this :))? Thank you all!

p.s. The projection of the triangle on the edge normal axis results in the min = max, for all edge normals.

So I have a triangle with the following points: p0, p1, p2 in 3D space and I'm testing it against a collision with a AABB (cube).

So far this is the code that I have, but my collision detection (SAT) implementation fails. The failure happens when the triangle projection "overlaps" on the surface normal only, so I'm assuming that the edge normals are not correct since they don't end the test as not intersecting. So I'm guessing I'm having concept/math issues.

// subtract the two to get the edge vector

edge1.sub( p1, p0 );

edge2.sub( p2, p0 );

edge3.sub( p2, p1 );

// 1 Surface normal

Vector3d normal = new Vector3d();

normal.cross( p0, p1 );

normal.normalize();

axes[ 0 ] = normal;

// 3 Edge normals

Vector3d normal1 = new Vector3d();

normal1.cross( edge1, edge2 );

normal1.normalize();

axes[ 1 ] = normal1;

Vector3d normal2 = new Vector3d();

normal2.cross( edge1, edge3 );

normal2.normalize();

axes[ 2 ] = normal2;

Vector3d normal3 = new Vector3d();

normal3.cross( edge3, edge2 );

normal3.normalize();

axes[ 3 ] = normal3;

I'm not sure if the edge normals are actually perpendicular to the surface normal. Am I wrong in my implementation, if so, what can I do to fix it (need to understand this :))? Thank you all!

p.s. The projection of the triangle on the edge normal axis results in the min = max, for all edge normals.