߂
import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; public class balla extends Applet implements Runnable { private Thread thr; int N = 1; int xx = 0; int yy = 1; double ix[] = new double[N]; double iy[] = new double[N]; double vx[] = new double[N]; double vy[] = new double[N]; inte aa = new inte(); public void init(){ int i; int j; for(i=0; i3) aa.q=4; //if( (aa.Q[0][yy]+aa.Qd[0][yy])>400 ) aa.Qd[0][yy] *= -1; if( aa.Q[0][yy]+10>400 ) aa.Qd[0][yy] *= -1; repaint(); //System.out.print("q_run "+aa.q+" "); try { Thread.sleep(5); } catch (InterruptedException e){ } } } public void stop() { if (thr != null) { thr = null; } } public void paint(Graphics g){ g.setColor(Color.black); g.drawLine(100, 400, 500, 400); g.setColor(Color.cyan); g.fillArc(300, (int)aa.Q[0][yy], 20, 20, 0, 360 ); if(aa.Q[0][yy]+10>400){ g.setColor(Color.red); g.fillArc(300, (int)aa.Q[0][yy], 20, 20, 0, 360 ); } //System.out.print("q "+aa.q+" "); } } class inte { double dt = 0.1; double xx = 0, yy = 1; int N = 1; int q = 0; double Q[][] = new double[N][3]; double Qd[][] = new double[N][3]; double Q2d[][] = new double[N][3]; double Qd01[][] = new double[N][3]; double Qd02[][] = new double[N][3]; double Qd03[][] = new double[N][3]; double Q2d01[][] = new double[N][3]; double Q2d02[][] = new double[N][3]; double Q2d03[][] = new double[N][3]; public inte() { } public void inte_a(int q, double Q2d[][], double Qd[][], double Q[][], int a, int xyz){ double k1, k2, k3, k4; double l1, l2, l3, l4; if(q==1||q==2||q==3){ k1 = dt * Q2d[a][xyz]; l1 = dt * Qd[a][xyz]; k2 = dt * (Q2d[a][xyz] + k1/2); l2 = dt * (Qd[a][xyz] + l1/2); k3 = dt * (Q2d[a][xyz] + k2/2); l3 = dt * (Qd[a][xyz] + l2/2); k4 = dt * (Q2d[a][xyz] + k3); l4 = dt * (Qd[a][xyz] + l3); Qd[a][xyz] = Qd[a][xyz] + (k1 + 2*k2 + 2*k3 + k4)/6; Q[a][xyz] = Q[a][xyz] + (l1 + 2*l2 + 2*l3 + l4)/6; if(q==1) { Q2d01[a][xyz] = Q2d[a][xyz]; Qd01[a][xyz] = Qd[a][xyz]; } if(q==2) { Q2d02[a][xyz] = Q2d01[a][xyz]; Qd02[a][xyz] = Qd01[a][xyz]; } if(q==3) { Q2d03[a][xyz] = Q2d03[a][xyz]; Qd03[a][xyz] = Qd03[a][xyz]; } } else{ Qd[a][xyz] = Qd[a][xyz] + ( 55*Q2d[a][xyz] - 59*Q2d01[a][xyz] + 37*Q2d02[a][xyz] - 9*Q2d03[a][xyz] )*dt/24; Q[a][xyz] = Q[a][xyz] + ( 55*Qd[a][xyz] - 59*Qd01[a][xyz] + 37*Qd02[a][xyz] - 9*Qd03[a][xyz] )*dt/24; } Q2d03[a][xyz] = Q2d02[a][xyz]; Qd03[a][xyz] = Qd02[a][xyz]; Q2d02[a][xyz] = Q2d01[a][xyz]; Qd02[a][xyz] = Qd01[a][xyz]; Q2d01[a][xyz] = Q2d[a][xyz]; Qd01[a][xyz] = Qd[a][xyz]; } }