射线三角形相交

时间:2019-10-20 10:56:44

标签: intersection ray

我正在阅读本文:https://cadxfem.org/inf/Fast%20MinimumStorage%20RayTriangle%20Intersection.pdf 我知道为什么u,v必须大于零,以便点位于三角形内,但是我迷惑了为什么它们同时检查* u> det和* u + * v> det。我以为u,v必须在[0,1]中。如果有人解释,我将不胜感激。

int intersect_triangle(Eigen::Vector3f orig, Eigen::Vector3f dir,
                   Eigen::Vector3f vert0, Eigen::Vector3f vert1, Eigen::Vector3f vert2,
                   double* t, double* u, double* v) {
Eigen::Vector3f edge1, edge2, tvec, pvec, qvec;
double det, inv_det;

edge1 = vert1 - vert0;
edge2 = vert2 - vert0;

// begin calculating determinant
pvec = dir.cross(edge2);
det = edge1.dot(pvec);

if (det < EPSILON)
    return 0;
// calculate distance from vert0 to ray origin
tvec = orig - vert0;
// now calculate u parameter and test bounds
*u = tvec.dot(pvec); // following the rules of determinants 
if (*u < 0.0 || *u > det)
    return 0;

qvec = tvec.cross(edge1);
*v = dir.dot(qvec);
if (*v < 0.0 || *u + *v > det)
    return 0; // ... code continues

0 个答案:

没有答案