Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

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

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2012
    Posts
    2

    Question 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.
    Code :
            // 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.
    Last edited by knownasilya; 09-11-2012 at 12:41 PM. Reason: added p.s.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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)

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2012
    Posts
    2
    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:
    Last edited by knownasilya; 09-18-2012 at 09:55 AM.

  4. #4
    Member Regular Contributor
    Join Date
    May 2000
    Location
    Philadelphia
    Posts
    285
    Try something like thisThe 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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •