I am using some code I found that tests two triangles for intersection. The portion of the code I am having trouble with is:
/*tr_tri_intersect3D - C1 is a vertex of triangle A. P1,P2 are the two edges originating from this vertex. D1 is a vertex of triangle B. P1,P2 are the two edges originating from this vertex. Returns zero for disjoint triangles and non-zero for intersection.*/ int tr_tri_intersect3D (double *C1, double *P1, double *P2, double *D1, double *Q1, double *Q2); What I don't understand is, if I have the three vertices of 2 triangles, what do I need to do to produce the input for this function?
The full source code can be found at:
The source code had a test function, it was: for (i = 0; i<10000; i++){ for (j = 0; j<3; j++){ for (k = 0; k<3; k++){ PS[i][j][k] = drand48(); QS[i][j][k] = drand48(); } } for (j = 0; j<2; j++){ for (k = 0; k<3; k++){ EPS[i][j][k] = PS[i][j + 1][k] - PS[i][0][k]; EQS[i][j][k] = QS[i][j + 1][k] - PS[i][0][k]; } } } double sum = 0; int t0 = clock(); int sums[100] = { 0 }; for (j = 0; j<1000; j++) for (i = 0; i<10000; i++){ int res = tr_tri_intersect3D(PS[i][0], EPS[i][0], EPS[i][1], QS[j][0], EQS[j][0], EQS[j][1]); sums[res]++; } if that help.