void myActions() { // actions to be executed at each frame scribe("Jarek Rossignac's edge / tringle intersection"); //*:01 prints text at top of the graphic window (see TAB UI), line 0 if ((mousePressed)&&(!keyPressed)) dragPoint(); // while mouse pressed moves the selected point by mouse displacement (in TAB polygon) fill(black); // set fill color to black (for writing text in the windows) strokeWeight(3); // set stroke width to 3 stroke(blue); // set current color to blue pt A=P[0]; A.show(2); A.showLabel("A"); // Assign variable point A to P[0], show it as a disk of radius 4, write its label "A" next to it pt B=P[1]; B.show(2); B.showLabel("B"); pt C=P[2]; C.show(2); C.showLabel("C"); //*:03 stroke(dgreen); fill(cyan,200); beginShape(); A.v(); B.v(); C.v(); endShape(CLOSE); //*:04 show triangle (A,B,C) fill(black); //*:05 reset fill color to black (for writing text in the windows) pt D=P[3]; D.show(2); D.showLabel("D"); pt E=P[4]; E.show(2); E.showLabel("E"); //*:06 a fifth point stroke(dblue); D.to(E); //*:07 show edge (D,E) stroke(red); strokeWeight(5); showEdgeTirangleIntersection(A,B,C,D,E); //*:08 stroke(orange); strokeWeight(5); showEdgeTirangleBorderIntersection(A,B,C,D,E); //*:30 }; void showEdgeTirangleIntersection(pt A, pt B, pt C, pt D, pt E) { //*:09 show intersection between triangle(A,B,C) and edge(D,E) //*:15 if (edgesCross(A, B, D, E)) show(EE(A, B, D, E)); //*:14 Debug test if edge(A,B) and edge(D,E) actually intersect (see below) if (D.isInTriangle(A,B,C)&&E.isInTriangle(A,B,C)) {D.to(E); return ; } //*:21 show DE when it is in triangle if (D.isInTriangle(A,B,C)&&!E.isInTriangle(A,B,C)) { //*:22 if D is in triangle and not E, draw edge from D to exit point if (edgesCross(A, B, D, E)) D.to(EE(A,B,D,E)); //*:23 if exit through AB if (edgesCross(B, C, D, E)) D.to(EE(B,C,D,E)); //*:24 if exit through BC if (edgesCross(C, A, D, E)) D.to(EE(C,A,D,E)); //*:25 if exit through AB return ; } //*:21 show DE when it is in triangle if (!D.isInTriangle(A,B,C)&&E.isInTriangle(A,B,C)) { //*:26 if E is in triangle and not D, draw edge from E to exit point if (edgesCross(A, B, D, E)) E.to(EE(A,B,D,E)); //*:27 if exit through AB if (edgesCross(B, C, D, E)) E.to(EE(B,C,D,E)); //*:28 if exit through BC if (edgesCross(C, A, D, E)) E.to(EE(C,A,D,E)); //*:29 if exit through AB return ; } //*:21 show DE when it is in triangle if (edgesCross(A, B, D, E)) //*:16 if hit AB if (edgesCross(B, C, D, E)) EE(A,B,D,E).to(EE(B,C,D,E)); //*:17 if also hit BC draw line between the two intersections else EE(A,B,D,E).to(EE(C,A,D,E)); //*:18 Assume hits CA, since we must exit triangle entered through AB else //*:19 do not hit AB if (edgesCross(B, C, D, E)) EE(B,C,D,E).to(EE(C,A,D,E)); //*:20 if hit BC, must also hit DE } //*:10 pt EE(pt A, pt B, pt C, pt D) { //*:11 returns intersection point between two edges (Assuming it exists) //*:12 Deleted test, which I will do before calling this vec T=V(A,B); // make vector T=AB vec N = R(V(C,D)); // makes vector N by rotating CD by 90 degrees vec AC = V(A,C); float t = dot(AC,N) / dot(T,N); // compute intersection parameter return S(A,t,T); //*:13 return point of intersection. S() computes a point on a line (see TAB geo2D) } boolean ordered(pt A, pt B, pt C) {return (00 != dot(U(R(V(A,B))),V(A,D))>0) // tests whether two edges cross && (dot(U(R(V(C,D))),V(C,A))>0 != dot(U(R(V(C,D))),V(C,B))>0) ; } void showEdgeTirangleBorderIntersection(pt A, pt B, pt C, pt D, pt E) { //*:31 show intersection between triangleBorder(A,B,C) and edge(D,E) pt XX[] = new pt [4]; //*:32 COPIED (from the code provided at http://www.gvu.gatech.edu/~jarek/3451/projects/P02/) int r; //*:33 nunber of intersection points between DE and an edge of triangle r = ee(A,B,D,E,2,XX); //*:34 COPIED if (r==2) XX[0].to(XX[1]); //*:35 COPIED else if(r==1) show(XX[0]);//*:41 in case DE touches AB at a vertex, show the contact point r = ee(B,C,D,E,2,XX); //*:37 COPIED if (r==2) XX[0].to(XX[1]); //*:38 COPIED else if(r==1) show(XX[0]);//*:42 in case DE touches BC at a vertex, show the contact point r = ee(C,A,D,E,2,XX); //*:39 COPIED if (r==2) XX[0].to(XX[1]); //*:40 COPIED else if(r==1) show(XX[0]);//*:43 in case DE touches CA at a vertex, show the contact point } //*:31 int ee(pt A, pt B, pt C, pt D, float e, pt X[]) { //*:36 (COPIED) returns number of vertices in X[] bounding intersection of edge(A,B) and edge(C,D) with tolerance e int r=0; if ((abs(dot(U(R(V(A,B))),V(A,C)))