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 2 of 2

Thread: Line Triangle intersection - Is this output correct?

  1. #1
    Newbie Newbie
    Join Date
    Nov 2012
    Posts
    3

    Line Triangle intersection - Is this output correct?

    Hello, I guess I missed too many classes on geometry.
    This code should compute the intersection between a line, with origin at s1 and s2 as direction, and a triangle, with vertices p0, p1 and p2. I'm using a function from GLM extensions to chack for these intersections. It writes the result to intersec

    Code :
    #include <cstdio>
    #include <glm/glm.hpp>
    #include <glm/gtx/intersect.hpp>
     
     
    int main() {
     
    	glm::vec3 p0(1,0,1), p1(1,0,-1), p2(1,1,0);
    	glm::vec3 s1(0,0,0), s2(1,0,0);
    	glm::vec3 intersec;
     
     
    	if ( glm::intersectLineTriangle(s1,s2,p0,p1,p2,intersec) ) 
    		printf("Intersected on (%lf %lf %lf)\n",intersec.x,intersec.y,intersec.z);
    	else
    		printf("Not intersected\n");
     
    }

    Does this output make sense?

    Code :
    Intersected on (1.000000 0.500000 -0.000000)

    Shouldn't it be (1.00000 0.000000 0.0000000)?

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    455
    Looking at the source, the result it returns is in barycentric coordinates.

Posting Permissions

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