void myActions() { // actions to be executed at each frame scribe("Jarek Rossignac's edge / edge intersection (general position)"); // 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"); A.to(B); // draw a line from A to B in current color (see TAB geo2D, end of class pt) stroke(green); pt C=P[2]; C.show(2); C.showLabel("C"); pt D=P[3]; D.show(2); D.showLabel("D"); C.to(D); stroke(orange); showEdgeEdgeIntersection(A,B,C,D); // WHERE THE ACTUAL INTERSECTION IS COMPUTED AND DISPLAYED (see below) fill(black); }; void showEdgeEdgeIntersection(pt A, pt B, pt C, pt D) { // show intersection point between two edges if it exists if (edgesCross(A, B, C, D)) { // test if edge(A,B) and edge(C,D) actually intersect (see below) 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 show(S(A,t,T)); // show() shows a point as a small disk. S() computes a point on a line (see TAB geo2D) // EXAMPLES OF DEBUGGING TECHNIQUES if (debugging) println("t="+t); // prints current value of t in the text output pane only once each time user presses '?' scribe("t="+t,1); // prints the value of t at the top of the graphics window (line 1) at each frame stroke(cyan,200); arrow(M(C,D),50,U(N)); // shows semi-transparent 50 pixel arrow from (C+D)/2 aligned with N } } 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) ; }