// July 2002, java applet by Oliver Knill for the CCP project // Green's Theorem and the Planimeter by Oliver Knill and Dale Winter // Harvard University, Nov 15, 2002. See // http://math.duke.edu/education/ccp/materials/mvcalc/green // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License of the Free Software Foundation for // details. Compile with // javac -O instrument.java comment.java wheel.java curve.java planimeter.java import java.lang.Math; import java.awt.*; class wheel { private int h,w; // width and height taken over private int x,y; // location of pointer private int x_old,y_old; // old location of pointer public int c_old,d_old; // old location of pointer private int x1,y1; // location of pointer private int a1,b1; // variables in calculation of vector field private double aa1,bb1; // variables in calculucation of vector field private int c1,d1; // location of vector field end point private double u1,v1; // coordinate of (x,) with respect to center private double r1; // distance from center private double l=(int) w/4; // length of planimter arm private int x_wheel, y_wheel; // location of wheel on screen private int ccos, ssin; // cos and sin of wheel rotation angle private int i; // index private int gear=200; // gear factor to turn wheel, bigger -> wheel slower private int spines=7; // symmetry of wheel private double sum, sum_old; // integration sum private boolean active1; // true during measurement private int wheel_radius; // wheel radius private Color wheel_color; // wheel color private int left_border=80; // border,where wheel no more displayed private boolean found=false; // line integral found? private boolean counting=false;// summing up? private boolean moved=false; // moved a bit on the curve? public wheel(int width,int height) { this.w = width; this.h = height; l=(int) w/4; x_wheel=25; y_wheel=25; sum=0; sum_old=0; active1=false; found=false; counting=false; moved=false; wheel_radius=22; wheel_color=new Color(255,0,255); } public void read_pointer(int x, int y) { this.x = x; this.y = y; } public boolean sum_found() { return found; } public boolean sum_counting() { return counting; } public double update( Graphics g, boolean status) { active1=status; if (sum==0) { ccos=1; ssin=0; x_old=x; y_old=y; sum=0.00001; sum_old=sum;} if (active1) { wheel_color=new Color(255,0,255); } else { wheel_color=new Color(255,127,255); } if (x_old>left_border) { for (i=0; i(2*l)) { r1=2*l; }; if (r1==0) {r1=1; } aa1 = r1/2; bb1=Math.sqrt( l*l-r1*r1/4 ); a1 = (int) (w/2+( aa1*u1 + bb1*v1)/r1); b1 = (int) (h/2+(-bb1*u1 + aa1*v1)/r1); c1 = (int) (x1+15*(y1-b1)/l); d1 = (int) (y1-15*(x1-a1)/l); sum-=(x1-x_old)*(c1-x1)+(y1-y_old)*(d1-y1); if (x1>left_border) { for (i=0; i50) ) { // reset if over menu counting=false; found=false; moved=false; sum=0.0000001; } if ( (Math.abs(x-430)>10) || (Math.abs(y-200)>10) && (counting)) { // check whether moved on curve moved=true; } if ( (Math.abs(x-430)<3) && (Math.abs(y-200)<3) && (!found) && (!counting)) { // reset if first time zero sum_old=sum; sum=0.0000001; counting=true; moved=false; } if ( (Math.abs(x-430)<3) && (Math.abs(y-200)<3) && (counting) && (moved) ) { found=true; counting=false; } // stop counting if second time zero and moved return sum; } }