//求直线 s1 s2 与三角形v0,v1,v2的交点 e1 = v1 - v0; e2 = v2 - v0; dir = s2 - s1; p = cross_product(dir, e2); tmp = (num_type)1/(p*e1); s = s1 - v0; u = tmp * s * p; if(u < 0 || u > 1) { //the intersection is not in the triangle return; } q = cross_product(s, e1); v = tmp * dir * q; if(v < 0 || v > 1) { //the intersection is not in the triangle return; } if(u + v > 1) { //the intersection is not in the triangle return; } //the result is stored in inter->pt pt = s1+(tmp*e2*q)*dir;
原文:http://www.cnblogs.com/soulgon/p/3584800.html