boolean showVertexIds=false, showVertices=false; boolean showLinear=false, showSpiral=true, showCircles=false, animate=false, showFrames=true; float tt=0; void myActions() { // actions to be executed at each frame if ((mousePressed)&&(!keyPressed)) editPolygon(); // edit points if ((mousePressed)&&(mouse().isInWindow())&&(keyPressed)) { if (key=='z') scaleBy(1.- d(screenCenter(),Mouse()) / d(screenCenter(),Pmouse()) ); if (key=='r') rotateBy( angle( V(screenCenter(),Mouse()) , V(screenCenter(),Pmouse()) ) ); if (key=='t') translateBy(MouseDrag()); } pt A=P[0]; pt B=P[1]; pt C=P[2]; pt D=P[3]; pt E=P[4]; EDGE AB=E(A,B); EDGE DE=E(D,E); pt c=AB.grab(C); pt F=P[5]; F.setTo(DE.put(c)); fill(black); A.showLabel("A"); B.showLabel("B"); C.showLabel("C"); D.showLabel("D"); E.showLabel("E"); noFill(); strokeWeight(1); stroke(dgreen); B.to(C); C.to(A); stroke(dblue); E.to(F); F.to(D); strokeWeight(3); stroke(dgreen); AB.show(); stroke(dblue); DE.show(); strokeWeight(1); if(showFrames) { float dt=0.1; if(showLinear) {stroke(magenta); for(float t=0; t<=1; t+=dt) {EDGE PQ=Slinear(AB,t,DE); PQ.show(c);};}; if(showSpiral) {stroke(red); for(float t=0; t<=1.01; t+=dt) {EDGE PQ=Sspiral(AB,t,DE); PQ.show(c);};}; }; if(animate) {strokeWeight(2); tt+=0.01; if(tt>1) tt=0; if(showLinear) {stroke(magenta); EDGE PQ=Slinear(AB,tt,DE); PQ.show(c);}; if(showSpiral) {stroke(red); EDGE PQ=Sspiral(AB,tt,DE); PQ.show(c);}; strokeWeight(1);}; String S="File: P"+Format0(fn,2)+" out of "+Format0(maxfn,2)+". Using"; if (showLinear) S=S+" linear"; if (showLinear&&showSpiral) S=S+" and "; if (showSpiral) S=S+" spiral"; scribe(S); }; EDGE E(pt A, pt B) {return new EDGE(A,B); } class EDGE { pt A=P(); pt B=P(); vec Vec() {return V(A,B);} float n2() {return dot(V(A,B),V(A,B));} float n() {return d(A,B);} EDGE(pt P, pt Q) {A.setTo(P); B.setTo(Q);}; void show() {A.show(2); A.to(B);} void show(pt c) {pt C=put(c); A.show(2); A.to(B); B.to(C); C.to(A);} pt grab(pt C) {return P(dot(V(A,C),V(A,B))/n2(),dot(V(A,C),R(V(A,B)))/n2() );} pt put(pt C) {return S(S(A,C.x,V(A,B)),C.y,R(V(A,B))); } } EDGE Slinear(EDGE E0, float t, EDGE E1) {return E(S(E0.A,t,E1.A),S(E0.B,t,E1.B));} EDGE Sspiral(EDGE E0, float t, EDGE E1) { float a = a(E0.Vec(),E1.Vec()); float s = E1.n() / E0.n(); pt C1=circleCenterForAngle(E0.A,E1.A,a); float r1=d(C1,E0.A); pt C2=circleCenterForAngle(E0.B,E1.B,a); float r2=d(C2,E0.B); pt Gr = CCr(C1,r1,C2,r2); pt Gl = CCl(C1,r1,C2,r2); pt G=Gl; if (abs(s-d(Gr,E1.A)/d(Gr,E0.A))