0

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:

Triangle Triangle Code

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.

5
  • As in, how do you call the function? I would assume pass your six verticies that you already have to it. Commented Nov 30, 2014 at 4:53
  • From the comments in the code it seemed like it was asking me for edges in P1, P2, Q1, and Q2. Is that no different from a vertex? Commented Nov 30, 2014 at 4:59
  • An edge is made by two vertices. You can't pass an edge, as there is no such thing as an edge, just two points which make a line which we call an edge. Commented Nov 30, 2014 at 5:11
  • @David Yeah, that's what I thought. I just put the test code that was in the file in my post, does that help? Commented Nov 30, 2014 at 5:14
  • Not at all. Nonetheless, what is going wrong? Commented Nov 30, 2014 at 5:15

2 Answers 2

1

From the sample code it seems like what it mean by an edge is the vector from the originating vertex to the end vertex. In the case of a triangle with three vertices C1, C2, C3, the two input edges would be P1 = C2-C1, P2=C3-C1

Sign up to request clarification or add additional context in comments.

1 Comment

Okay, awesome. The algorithm doesn't seem to work right with every combination of triangles, but you were right about how to feed it input.
0

Reading the test code, it looks like C and D are two [3][3] array of 9 doubles, which are points 1, 2 and 3 and their 3D x,y,z coordinates.

P1 and P2 are the x,y,z distances of points 2 and 3 from point 1 in triangle C, and Q1 and Q2 are the x,y,z distances of points 2 and 3 of triangle D from point 1. (Edit: byebyebryan said it better, this is the x,y,z vector from point 1 to points 2 and 3). These two are both an array of [3] doubles (basically, bounding box info).

No idea why the Ps and Qs are not computed inside the function, unless the vars also serve to hold return values somehow.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.