70 #define vector(a,b,c) \
71 (a)[0] = (b)[0] - (c)[0]; \
72 (a)[1] = (b)[1] - (c)[1]; \
73 (a)[2] = (b)[2] - (c)[2];
77 #define innerProduct(v,q) \
82 #define crossProduct(a,b,c) \
83 (a)[0] = (b)[1] * (c)[2] - (c)[1] * (b)[2]; \
84 (a)[1] = (b)[2] * (c)[0] - (c)[2] * (b)[0]; \
85 (a)[2] = (b)[0] * (c)[1] - (c)[0] * (b)[1];
87 bool rayIntersectsTriangle(
const double *p,
const double *d,
const double *v0,
const double *v1,
const double *v2,
double &t)
90 double e1[3],e2[3],h[3],s[3],q[3];
98 if (a > -0.00001 && a < 0.00001)
105 if (u < 0.0 || u > 1.0)
110 if (v < 0.0 || u + v > 1.0)
123 bool lineIntersectsTriangle(
const double *rayStart,
const double *rayEnd,
const double *p1,
const double *p2,
const double *p3,
double *sect)
127 dir[0] = rayEnd[0] - rayStart[0];
128 dir[1] = rayEnd[1] - rayStart[1];
129 dir[2] = rayEnd[2] - rayStart[2];
131 double d = sqrt(dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]);
147 sect[0] = rayStart[0] + dir[0]*t;
148 sect[1] = rayStart[1] + dir[1]*t;
149 sect[2] = rayStart[2] + dir[2]*t;