# Getting polygon (triangle) edge normals in 3D space - perpendicular to surface normal

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.

The first normal is perpendicular to a plane defined by the points p0,p1 and pt(0,0,0) - not a vector perpendicular to the plane p0,p1,p2. All the other normals are vectors perpendicular to the plane but with different signs (ie some are front face some are back face)

So the problem that I’m having is that when the AABB is under a diagonal edge of a triangle but does not intersect it then it still thinks it’s intersecting because it doesn’t check the diagonal axis. How can I get the edge normal? Is that even possible?

This is an example of what is going on, and in this situation (except in 3D, where this is the only axis that would say it’s not colliding: Try something like this:(The signs of the edge normals are likely wrong. You will need to correct by changuing order of arguments in sub() and cross())

``````// 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( edge1, edge2);
normal.normalize();
axes[ 0 ] = normal;

// 3 Edge normals
Vector3d normal1 = new Vector3d();
normal1.cross( edge1, normal);
normal1.normalize();
axes[ 1 ] = normal1;

Vector3d normal2 = new Vector3d();
normal2.cross( edge2, normal);
normal2.normalize();
axes[ 2 ] = normal2;

Vector3d normal3 = new Vector3d();
normal3.cross( edge3, normal);
normal3.normalize();
axes[ 3 ] = normal3;``````