戻る
import java.applet.Applet; import java.awt.Graphics; import java.awt.Color; public class balla2 extends Applet implements Runnable { private Thread thr; int N = 1; double h = 0.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]; inte2 aa2 = new inte2(); public void init(){ int i; int j; for(i=0; i3) aa2.q=4; if( aa2.Q[0][yy]+10>400 ) aa2.Qd[0][yy] *= -1; repaint(); //System.out.print("q_run "+aa2.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)aa2.Q[0][yy], 20, 20, 0, 360 ); if(aa2.Q[0][yy]+10>400){ g.setColor(Color.red); g.fillArc(300, (int)aa2.Q[0][yy], 20, 20, 0, 360 ); } //System.out.print("q "+aa2.q+" "); } } class inte2 { int xx = 0, yy = 1; int N = 1; int q = 0; double h = 0.1; //時間刻み幅 //double k; //運動エネルギー double Q_old[][] = new double[N][3]; double Qd_old[][] = new double[N][3]; double Q2d_old[][] = new double[N][3]; double Q[][] = new double[N][3]; double Qd[][] = new double[N][3]; double Q2d[][] = new double[N][3]; double Q_new[][] = new double[N][3]; double Qd_new[][] = new double[N][3]; double Q2d_new[][] = new double[N][3]; public inte2() { } public void inte2_a(int q, double Q2d[][], double Qd[][], double Q[][], int a, int xyz) { /*Verlet法、入力、出力*/ // 力、自重(9.8)とする //force(); // _old、力で、_newを計算する。ステップごと //加速度を使わない、力として置き換える。 Q_new[a][xx] = 2.0* Q[a][xx] - Q_old[a][xx] + Q2d[a][xx]*h*h; Q_new[a][yy] = 2.0* Q[a][yy] - Q_old[a][yy] + Q2d[a][yy]*h*h; Qd[a][xx] = Qd[a][xx] + Q2d[a][xx]*h; Qd[a][yy] = Qd[a][yy] + Q2d[a][yy]*h; //k+=(Qd[a][xx]*Qd[a][xx]+Qd[a][yy]*Qd[a][yy])/2.0; Q_old[a][xx] = Q[a][xx]; Q_old[a][yy] = Q[a][yy]; Q[a][xx] = Q_new[a][xx]; Q[a][yy] = Q_new[a][yy]; } }