// TO DO // resample polyloop !!! // compute center of mass G and show // rshift otate zoom wrt G // CP map int _rec=3, _deg=3; // number of recursions and B-spline degree //float _ga=-1.535224, _gb= 0.410048, _gs=1.5; // subdivision parameters float _ga=0.0, _gb=0.0, _gs=0.0; // subdivision parameters float [] _w = new float[5]; // weights for retrofitting boolean symmetryEnds=true; class Polyloop { // class of polyloops (closed loop polygon) int vn = 5, cap=5000; // number of control vertices and the cap on vn pt[] P = new pt [cap]; // control points vec[] L = new vec [cap]; // adjustment vectors pt G = new pt(0,0); // center of mass float a = 0; // angle to axis ring [] R = new ring[7]; // 7 rings int rc; // counter showing the next control point to load in the top rig Stepper stepper = new Stepper(_rec); // stepper for knowing which ring to advance int bi=-1; boolean openLoop; // says that curve is int p = 0; // id of point selected with mouse for dragging float area; pt lastPt = new pt(0,0), thisPt = new pt(0,0); int ctr; //used to sum up the area int ni(int i) {return (i+1)%vn;} int pi(int i) {return (i+vn-1)%vn;} Polyloop () {vn=0; for (int i=0; i0) px+=vd; else mx-=vd; if(ud>0) py+=ud; else my-=ud; }; if(mx>max(px,py,my)) V.rotateBy(PI); if(py>max(px,mx,my)) V.rotateBy(PI/2.); if(my>max(px,mx,py)) V.rotateBy(-PI/2.); strokeWeight(1); stroke(black); V.showArrowAt(G); stroke(black,60); V.turnLeft(); V.showAt(G); V.turnLeft(); V.showAt(G); V.turnLeft(); V.showAt(G); } void updateGa() {G=this.barycenter(); float xx=0, xy=0, yy=0, px=0, py=0, mx=0, my=0; for (int i=0; i0) px+=vd; else mx-=vd; if(ud>0) py+=ud; else my-=ud; }; if(mx>max(px,py,my)) a+=PI; if(py>max(px,mx,my)) a+=PI/2.; if(my>max(px,mx,py)) a-=PI/2.; } void showGa() { G.show(10); vec V= new vec(50,0); V.rotateBy(a); V.showArrowAt(G); V.turnLeft(); V.showAt(G); V.turnLeft(); V.showArrowAt(G); V.turnLeft(); V.showAt(G); } // EDIT void pickClosestVertex(pt M) {p=0; for (int i=1; ie; i--) P[i+1].setTo(P[i]); vn++; p=this.in(e); P[p].setTo(mouseX,mouseY); }; } void closeLoop() {openLoop=false; vn-=4; for (int i=0; ibx) {bx=P[i].x;}; if (P[i].xby) {by=P[i].y;}; if (P[i].yabs(P[in(i)].y-P[i].y)) {float dy=(P[in(i)].y-P[i].y)/2; P[in(i)].y-=dy; P[i].y+=dy;} else {float dx=(P[in(i)].x-P[i].x)/2; P[in(i)].x-=dx; P[i].x+=dx;}; }; } // INDICES int in(int j) { if (j==vn-1) {return (0);} else {return(j+1);} }; // next vertex in loop int ip(int j) { if (j==0) {return (vn-1);} else {return(j-1);} }; // previous vertex in loop // ARCHIVAL ON FILE void savePts() {this.savePts(0);} void loadPts() {this.loadPts("C0.pts");} void savePts(int n) { String [] inppts = new String [vn+1]; int s=0; inppts[s++]=str(vn); for (int i=0; i=vn) for (int i=0; i0; i--) P[i].setTo(P[i-1]); P[0].setTo(P0); }; // shits vetex table void shiftIDs(int n) {for (int j=0; j0; i--) P[i].setTo(P[i-1]); P[0].setTo(P0); };}; // shifts vetex table void dual() {this.refine(); this.coarsen();} void coarsen() {vn/=2; for (int i=0; i