import java.util.Date; import java.applet.*; import java.awt.Graphics; import java.awt.event.*; import java.awt.*; import Rectangle; import Line; public class man_plane extends Applet { double x1 = 350.0; double y1 = 150.; int go = 1; int lasty; double tim = 0; double dtim=0.01; static double qvalue = 10; static double speed = 10.; double arrowlength; double arrowlength2 = 20; double arrowlength3 = 60; double angle = 20; double radangle = angle*(Math.PI/180); double sinangle = Math.sin(radangle); double cosangle = Math.cos(radangle); double dx1; double dx2; double dy1; double dy2; double recenty[]; double inter[]; long recentt[]; double I_loop=0.; int max = 40; int j; int xcoord, ycoord; long lastt; long red; long green; long blue; double r; int maxtim =1; int brectcx; int brectcy; double dist1; double dist2; double compx, compx1, compx2; double compy, compy1, compy2; double dummy = 0.; double rada = 100.; double ang=Math.PI/6.; int x2 = 325; int y2 = 240; int numline = 2; Scrollbar speedScroll = new Scrollbar(Scrollbar.HORIZONTAL,(int)speed,10,10,100); public Label speedLabel = new Label("Speed of Light =" + speed); Rectangle rect; Rectangle rectn; Line line; /* public void Reset() { x1 = 350.0; y1 = 350.; go = 1; tim = 0; repaint(); } public void Settvalue(String m) { maxtim = new Integer(m).intValue(); } public void Setqvalue(String m) { qvalue = new Double(m).doubleValue(); } public void Setbvalue(String m) { betavalue = new Double(m).doubleValue(); } public void SetGo() { go = 1; repaint(); } */ public void init() { setBackground(java.awt.Color.white); rect = new Rectangle(0,200,7,(int)x1,(int)y1); rectn = new Rectangle(0,200,7,(int)x1+4,(int)y1+90); recenty = new double[max+1]; recentt = new long[max+1]; inter = new double[10*max+1]; line=new Line(0.0,0.0,0.0,0.0); j = 0; while(j <= max) { recenty[j] = y1; recentt[j] = 0; j++; } j = 0; while(j <= 10*max) { inter[j] = y1; j++; } speedScroll.setForeground(Color.black); speedScroll.setBackground(Color.lightGray); setLayout(new BorderLayout()); Panel t = new Panel(); t.setLayout(new FlowLayout(FlowLayout.CENTER)); t.add(speedScroll); t.add(speedLabel); add("South",t); } public void Setbvalue(String m) { speed = new Double(m).doubleValue(); } public void paint(Graphics g) { { line.ang = ang; //the angle of field line measured from horizontal line.emag = 1; rect.cx = (int)x1; rect.cy = (int)y1; double vey,vex; /* g.setColor(java.awt.Color.white); g.drawLine(brectcx-rect.rw,brectcy-rect.rh,brectcx-rect.rw,brectcy+rect.rh); g.drawLine(brectcx-rect.rw,brectcy-rect.rh,brectcx+rect.rw,brectcy-rect.rh); g.drawLine(brectcx+rect.rw,brectcy-rect.rh,brectcx+rect.rw,brectcy+rect.rh); g.drawLine(brectcx+rect.rw,brectcy+rect.rh,brectcx-rect.rw,brectcy+rect.rh); */ g.setColor(java.awt.Color.red); g.drawLine(rect.cx-rect.rw,rect.cy-rect.rh,rect.cx-rect.rw,rect.cy+rect.rh); g.drawLine(rect.cx-rect.rw,rect.cy-rect.rh,rect.cx+rect.rw,rect.cy-rect.rh); g.drawLine(rect.cx+rect.rw,rect.cy-rect.rh,rect.cx+rect.rw,rect.cy+rect.rh); g.drawLine(rect.cx+rect.rw,rect.cy+rect.rh,rect.cx-rect.rw,rect.cy+rect.rh); g.setColor(java.awt.Color.black); g.drawLine(rectn.cx-rectn.rw,rectn.cy-rectn.rh,rectn.cx-rectn.rw,rectn.cy+rectn.rh); g.drawLine(rectn.cx-rectn.rw,rectn.cy-rectn.rh,rectn.cx+rectn.rw,rectn.cy-rectn.rh); g.drawLine(rectn.cx+rectn.rw,rectn.cy-rectn.rh,rectn.cx+rectn.rw,rectn.cy+rectn.rh); g.drawLine(rectn.cx+rectn.rw,rectn.cy+rectn.rh,rectn.cx-rectn.rw,rectn.cy+rectn.rh); // interpolate positions int many; double yfirst, ysecond, rfirst, rsecond; int intmax; int ilinc; intmax=(int)(speed/10.); ilinc=0; while(ilinc < max) { yfirst=recenty[ilinc]; ysecond=recenty[ilinc+1]; many=0; while(many < intmax) { rsecond=(double)many/(double)intmax; rfirst=1.-rsecond; inter[ilinc*intmax+many]=rfirst*yfirst + rsecond*ysecond; many++; // System.out.println("many" +many + "ilinc"+ilinc+"rfirst"+rfirst+"resecond"+rsecond); } ilinc++; } // Now draw lines double delarc = 9.; double intarc; intarc = delarc/3.; double deriv; int ilarrow,ilarrow2; int r1=10; int m1; many=0; while (many < 1) { line.sx = x1 ; // line.sy = y1 +(many-4)*40; line.sy = y1 ; ilinc=0; ilarrow=0; ilarrow2=0; m1=max*intmax; while(ilinc <= m1 && line.sx < 500 && line.sx > 0 && line.sy < 700 && line.sy > 0 ) { g.setColor(java.awt.Color.green); deriv=intmax*15.*(inter[ilinc+1]-inter[ilinc]); line.ey = inter[ilinc]+(many-4)*40; line.ey = inter[ilinc]; line.ex = line.sx-10; // draw moving field line g.drawLine((int)line.sx, (int)line.sy, (int)line.ex, (int)line.ey); g.drawLine(700-(int)line.sx, (int)line.sy, 700-(int)line.ex, (int)line.ey); // draw stationary field line g.drawLine((int)line.sx, 200, (int)line.ex, 200); g.drawLine(700-(int)line.sx, 200, 700-(int)line.ex, 200); // draw arrow head on field line every once in awhile ilarrow++; ilarrow2++; if (ilarrow>5) { compx=line.ex-line.sx; compy=line.ey-line.sy; line.emag = Math.sqrt(Math.pow(compx,2) + Math.pow(compy,2)); vey = line.sy ; vex = line.sx ; dy1 = 1*(arrowlength2*((sinangle*compx-cosangle*compy)/line.emag)); dx1 = -1*(arrowlength2*((cosangle*compx+sinangle*compy)/line.emag)); dy2 = 1*(arrowlength2*((-sinangle*compx-cosangle*compy)/line.emag)); dx2 = -1*(arrowlength2*((cosangle*compx-sinangle*compy)/line.emag)); // moving field line g.drawLine((int)vex, (int)vey, (int)(vex + dx1/2.),(int)(vey + dy1/2.)); g.drawLine((int)vex, (int)vey, (int)(vex + dx2/2.),(int)(vey + dy2/2.)); g.drawLine(700-(int)vex, (int)vey,700- (int)(vex + dx1/2.),(int)(vey + dy1/2.)); g.drawLine(700-(int)vex, (int)vey, 700-(int)(vex + dx2/2.),(int)(vey + dy2/2.)); // stationary field line vey=200.; compx=-1.; compy=0.; line.emag = Math.sqrt(Math.pow(compx,2) + Math.pow(compy,2)); dy1 = 1*(arrowlength2*((sinangle*compx-cosangle*compy)/line.emag)); dx1 = 1*(arrowlength2*((cosangle*compx+sinangle*compy)/line.emag)); dy2 = 1*(arrowlength2*((-sinangle*compx-cosangle*compy)/line.emag)); dx2 = 1*(arrowlength2*((cosangle*compx-sinangle*compy)/line.emag)); g.drawLine((int)vex, (int)vey, (int)(vex + dx1/2.),(int)(vey + dy1/2.)); g.drawLine((int)vex, (int)vey, (int)(vex + dx2/2.),(int)(vey + dy2/2.)); g.drawLine(700-(int)vex, (int)vey,700- (int)(vex + dx1/2.),(int)(vey + dy1/2.)); g.drawLine(700-(int)vex, (int)vey, 700-(int)(vex + dx2/2.),(int)(vey + dy2/2.)); ilarrow=0; } // draw perturbation electric field line // g.drawLine((int)line.ex, (int)y1+50, (int)line.ex, (int)(y1+deriv+50)); // g.drawLine(700-(int)line.ex, (int)y1+50, 700-(int)line.ex, (int)(y1+deriv+50)); g.drawLine((int)line.ex, 350, (int)line.ex, 350+(int)deriv); g.drawLine(700-(int)line.ex, 350, 700-(int)line.ex, 350+(int)deriv); // draw arrow head on perturbation electric field line every once in a while compx=0.; compy=deriv; line.emag = Math.sqrt(Math.pow(compx,2) + Math.pow(compy,2)); if ( line.emag > .01) { if (ilarrow2>0) { vex = line.ex ; vey = 350.+deriv ; dy1 = 1*(arrowlength2*((sinangle*compx-cosangle*compy)/line.emag)); dx1 = -1*(arrowlength2*((cosangle*compx+sinangle*compy)/line.emag)); dy2 = 1*(arrowlength2*((-sinangle*compx-cosangle*compy)/line.emag)); dx2 = -1*(arrowlength2*((cosangle*compx-sinangle*compy)/line.emag)); g.drawLine((int)vex, (int)vey, (int)(vex + dx1/3.),(int)(vey + dy1/3.)); g.drawLine((int)vex, (int)vey, (int)(vex + dx2/3.),(int)(vey + dy2/3.)); g.drawLine(700-(int)vex, (int)vey,700- (int)(vex + dx1/3.),(int)(vey + dy1/3.)); g.drawLine(700-(int)vex, (int)vey, 700-(int)(vex + dx2/3.),(int)(vey + dy2/3.)); ilarrow2=0; } } // System.out.println("m1"+m1+ " ilinc"+ilinc); // draw magnetic vectors r=3.*java.lang.Math.abs(deriv); red = (long)(255-r); blue = (long)(255); green = (long)(255-r); if(red>255) {red=255;} if(green>255) {green=255;} if(blue>255) {blue=255;} if(red<0) {red=0;} if(green<0) {green=0;} if(blue<0) {blue=0;} g.setColor(new Color((int)red,(int)green,(int)blue)); if(deriv<0) { g.drawOval((int)line.sx-r1/2,350-r1/2,r1,r1); g.drawLine((int)line.sx-(r1*71/200),350-(r1*71/200),(int)line.sx+(r1*71/200),350+(r1*71/200)); g.drawLine((int)line.sx-(r1*71/200),350+(r1*71/200),(int)line.sx+(r1*71/200),350-(r1*71/200)); } else { g.drawOval((int)line.sx-r1/2,350-r1/2,r1,r1); g.fillOval((int)line.sx-r1/6,350-r1/6,r1/3,r1/3); } if(deriv>0) { g.drawOval(700-((int)line.sx-r1/2),350-r1/2,r1,r1); g.drawLine(700-((int)line.sx-(r1*71/200)),350-(r1*71/200),700-((int)line.sx+(r1*71/200)),350+(r1*71/200)); g.drawLine(700-((int)line.sx-(r1*71/200)),350+(r1*71/200),700-((int)line.sx+(r1*71/200)),350-(r1*71/200)); } else { g.drawOval(700-(int)line.sx-r1/2,350-r1/2,r1,r1); g.fillOval(700-(int)line.sx-r1/6,350-r1/6,r1/3,r1/3); } line.sx = line.ex; line.sy = line.ey; ilinc++; } many++; } brectcx = rect.cx; brectcy = rect.cy; tim+=dtim; // System.out.println("tim=" +tim); //g.setColor(java.awt.Color.white); // g.fillRect(0,0,450,500); g.setColor(java.awt.Color.black); } // } } /* public boolean mouseMove(Event e, int x, int y) { xcoord = x; ycoord = y; return true; } */ public boolean mouseDown(Event e, int x, int y) { xcoord = x; ycoord = y; if(xcoord < (int)x1 + rect.rw && xcoord > (int)x1-rect.rw && ycoord < (int)y1+rect.rh && ycoord > (int)y1-rect.rh) { rect.hit = 1; } return true; } public boolean mouseUp(Event e, int x, int y) { rect.hit = 0; return true; } public boolean mouseDrag(Event e, int x, int y) { xcoord = x; ycoord = y; if (rect.hit == 1) { lasty = rect.cy; lastt = new Date().getTime(); j = 0; while(j < max) { recenty[max-j] = recenty[(max-j-1)]; recentt[max-j] = recentt[(max-j-1)]; j++; } recenty[0] = lasty; recentt[0] = lastt; rect.cy = y; y1 = rect.cy; // System.out.println("Recentx[0] = " + recentx[0] + " Recentx[1] = " + recentx[1] + " Recentx[2] = " + recentx[2]); // System.out.println("Recentt[0] = " + recentt[0] + " Recentt[1] = " + recentt[1] + " Recentt[2] = " + recentt[2]); //System.out.println("x=" + x + " y = " + y+ "I_loop " + I_loop); // I_loop=recentx[max]-recentx[max-1]; repaint(); } return true; } public boolean handleEvent(Event e) { Object target=e.target; if(target==speedScroll) { speed = speedScroll.getValue(); speedLabel.setText("Speed of Light = " + speed); } return super.handleEvent(e); } }