/*************************************************************************/
/* Program file name: Ex1_8.java                                         */
/*                                                                       */
/* © Tao Pang 2006                                                       */
/*                                                                       */
/* Last modified: June 7, 2006                                           */
/*                                                                       */
/* (1) This Java program is created for the book, "An Introduction to    */
/*     Computational Physics, 2nd Edition," written by Tao Pang and      */
/*     published by Cambridge University Press on January 19, 2006.      */
/*                                                                       */
/* (2) No warranties, express or implied, are made for this program.     */
/*                                                                       */
/*************************************************************************/


// Program for Exercise 1.8.  The trejactory of a motorcycle jump is
// calculated with the Euler method.

import java.lang.*;
public class Ex1_8 {
  static final int n = 1000, j = 20;
  public static void main(String argv[]) {
    double x[] = new double[n+1];
    double y[] = new double[n+1];
    double vx[] = new double[n+1];
    double vy[] = new double[n+1];
    double ax[] = new double[n+1];
    double ay[] = new double[n+1];

 // Assign all the constants involved
    double g = 9.80;
    double angle = 45*Math.PI/180; 
    double speed = 67;
    double mass = 250;
    double area = 0.93;
    double density = 1.2;
    double k = area*density/(2*mass);
    double dt = 2*speed*Math.sin(angle)/(g*n);
    double d = dt*dt/2;

 // Assign the quantities for the first point
    x[0] = y[0] = 0;
    vx[0] = speed*Math.cos(angle);
    vy[0] = speed*Math.sin(angle);
    double v = Math.sqrt(vx[0]*vx[0]+vy[0]*vy[0]);
    ax[0] = -k*v*vx[0];
    ay[0] = -g-k*v*vy[0];

 // Calculate other position and velocity recursively
    for (int i=0; i<n; ++i) {
      x[i+1] = x[i]+dt*vx[i];
      y[i+1] = y[i]+dt*vy[i];
      vx[i+1] = vx[i]+dt*ax[i];
      vy[i+1] = vy[i]+dt*ay[i];
      v = Math.sqrt(vx[i+1]*vx[i+1]+vy[i+1]*vy[i+1]);
      ax[i+1] = -k*v*vx[i+1];
      ay[i+1] = -g-k*v*vy[i+1];
    }

 // Output the result in every j time steps
    for (int i=0; i<=n; i+=j)
      System.out.println(x[i] +" " + y[i]);
  }
}
