// Marty Stepp, CSE 142, Autumn 2008 // This program displays the motion of a thrown projectile over time. // (The program is unfinished for now.) public class Projectile { public static void main(String[] args) { projectile(60, 50, 10); projectile(50, 80, 50); } // Plots the motion of a single projectile with the given // initial velocity v0, angle, and number of steps to plot. public static void projectile(double v0, double angle, int steps) { // v0y = v0 sin theta // t = -2v0 / a double v0y = v0 * Math.sin(Math.toRadians(angle)); double v0x = v0 * Math.cos(Math.toRadians(angle)); double totalTime = -2 * v0y / -9.81; double dt = totalTime / steps; // print the position at each time step for (int i = 0; i <= steps; i++) { double t = i * dt; double x = v0x * t; System.out.println(x + " " + t); } } // Computes how far a body has moved given an initial velocity v0, // force a, and time t. public static double displacement(double v0, double a, double t) { return v0 * t + 0.5 * a * Math.pow(t, 2); } }