Advertisement
Guest User

ur_mum.gif

a guest
Nov 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. * Created by Edwin on 11/11/2014.
  5. */
  6. public class Main {
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9. double vinput, anglein, angleinradians, c, m, voutput, vx, vy, ff, fg, ffy;
  10. double ffx, fnety, fnetx, dx, dy, ay, ax, totaldisplacement, height;
  11. /*
  12. * Index of variables, in order:
  13. * [calder, list them here]
  14. */
  15. boolean doISeriouslyHaveToKeepLooping = true;
  16.  
  17. totaldisplacement = 0;
  18. height = 0;
  19. System.out.println("Enter the magnitude of the launch velocity.");
  20. vinput = in.nextDouble();
  21. System.out.println("Enter the launch angle.");
  22. anglein = in.nextDouble();
  23. angleinradians = anglein * 0.01745329251; //Multiplied by 2pi/360 to convert to radians.
  24. c = 0.3; //Most simulations use 0.3. Using the cd = 2Fd/(ρ*v^2*A) equation, I got 0.298.
  25. m = 0.144; //The baseball was massed in class.
  26. while (doISeriouslyHaveToKeepLooping == true) {
  27. vx = vinput * Math.cos(angleinradians);
  28. vy = vinput * Math.sin(angleinradians);
  29. ff = vinput * Math.pow(c, 2); // Ff = cv^2
  30. ffx = ff * Math.cos(angleinradians);
  31. if (vy > 0) {
  32. ffy = ff * Math.sin(angleinradians); //this is in the DOWN direction.
  33. //If the object is travelling upwards, the resistance will be in the down direction.
  34. } else {
  35. ffy = -ff * Math.sin(angleinradians);
  36. //If the object is travelling downwards (ay is negative), air resistance will be applying a force upwards.
  37. }
  38. fg = 9.8 * m;
  39. fnety = ffy + fg; //[down]
  40. fnetx = ffx; //[bckwd]
  41. ay = -fnety / m; //[up]
  42. ax = -fnetx / m; //[fwd]
  43. dx = vx * 0.01 + 0.5 * ax * Math.pow(0.01, 2);
  44. dy = vy * 0.01 + 0.5 * ay * Math.pow(0.01, 2);
  45.  
  46. totaldisplacement = totaldisplacement + dx;
  47. height = height + dy;
  48. vx = vx + ax * 0.01;
  49. vy = vy + ay * 0.01;
  50. angleinradians = -Math.atan(vy / vx);
  51. if (totaldisplacement > 40) {
  52. doISeriouslyHaveToKeepLooping = false;
  53. } else {
  54. doISeriouslyHaveToKeepLooping = true;
  55. System.out.println(height); //We want height to be 0 when the loop ends.
  56. //This ensures our trajectory will be as desired.
  57. }
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement