Max Height formula

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster

Max Height formula

 
0
  #1
29 Days Ago
I cant figure out how to make a function that correctly solves the max height of a parabola

I know height = distance * tan(angle) - (gravity * distance^2) /2 *( speed * cos(angle))^2

I try to put this in and I get like 1.2 trillion

I think im doing it right....


anyone mind helping me figure this out?

Distance = 3831.57
Angle = 35
Gravity = 9.81
Speed = 200

after inputing these in the the formula the anwser is suppose to be like 670 but I dont know how to do it let alone put it in c++
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training
 
0
  #2
29 Days Ago
Originally Posted by UKmason View Post
I know height = distance * tan(angle) - (gravity * distance^2) /2 *( speed * cos(angle))^2
Did you remember to use parentheses?

height = (distance*(tan(angle)))-((gravity*(distance*distance))/(2*((speed*(cos(angle)))*(speed*(cos(angle))))))

Better to use too many parentheses then too few
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 329
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 37
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Whiz
 
0
  #3
29 Days Ago
  1. #include<cmath>
  2. height = (distance * tan(angle)) - (gravity * pow(distance, 2)) /2 * pow(speed * cos(angle), 2);
Last edited by Clinton Portis; 29 Days Ago at 3:06 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster
 
0
  #4
29 Days Ago
That is the formula I was using Clinton Portis and it still came out to 1.7 x 10 to the 13th

and Skeen going back and making sure I had all the parentheses got me a lot closer but still about 8000 away from the anwser


... I don't know what is going on
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training

Wild guess

 
0
  #5
29 Days Ago
Originally Posted by UKmason View Post
... I don't know what is going on :
Wild guess, you forgot that <cmath> is using radians for tan(), cos(), ect?
Last edited by Skeen; 29 Days Ago at 3:00 pm.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster
 
0
  #6
29 Days Ago
Haha, I wish it was that simple of a fix... Do you think I need to post my whole program up here?
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 329
Reputation: Clinton Portis is on a distinguished road 
Solved Threads: 37
Clinton Portis's Avatar
Clinton Portis Clinton Portis is offline Offline
Posting Whiz
 
0
  #7
29 Days Ago
That is the formula I was using Clinton Portis and it still came out to 1.7 x 10 to the 13th

This is what you posted:
  1. I know height = distance * tan(angle) - (gravity * distance^2) /2 *( speed * cos(angle))^2

which is not the same as this:
  1. #include<cmath>
  2. height = (distance * tan(angle)) - (gravity * pow(distance, 2)) /2 * pow(speed * cos(angle), 2);
Last edited by Clinton Portis; 29 Days Ago at 3:10 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training
 
0
  #8
29 Days Ago
Originally Posted by UKmason View Post
Haha, I wish it was that simple of a fix... Do you think I need to post my whole program up here?
You could try, donno how bad the program is?
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 43
Reputation: UKmason is an unknown quantity at this point 
Solved Threads: 1
UKmason UKmason is offline Offline
Light Poster
 
0
  #9
29 Days Ago
Well this is what I have... It compiles and everything just somthing is funky when trying to find out the max height

  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. // This program is to calculate the trajectories of projectiles and how the initial speed and
  6. // angle from the horizontal affect the distance the projectile will travel on different planets
  7. // and satellites.
  8. //
  9. //********************************************************************
  10. //
  11. //Example interaction with the user:
  12.  
  13. //Trajectory Plotter!
  14. //Enter a speed of launch (mps): 200
  15. //Enter the angle of launch (in degrees): 35
  16. //Speed = 200.00 mps, Angle = 35.00 degrees = 0.61 radians
  17.  
  18. //Distance travelled on Earth = 3831.57 m, max height = 670.72 m
  19. //Distance travelled on Mars = 9970.21 m, max height = 1745.30 m
  20. //Distance travelled on the Moon = 23202.29 m, max height = 4061.60 m
  21.  
  22. //Maximum distance traveled = 23202.29
  23. //Maximum height reached = 4061.60
  24. //For Earth, the 5 points of the parabola would be:
  25. // x0, y0 (0.00, 0.00)
  26. // x1, y1 (957.89, 503.04)
  27. // x2, y2 (1915.79, 670.72)
  28. // x3, y3 (2873.68, 503.04)
  29. // x4, y4 (3831.57, 0.00)
  30. //
  31. //********************************************************************
  32.  
  33.  
  34. double angtorad (double angle, double pi);
  35. double distance_earth (double angle, int mps, double earth_gravity);
  36. double distance_moon (double angle, int mps, double moon_gravity);
  37. double distance_mars (double angle, int mps, double mars_gravity);
  38. double height_earth (double radian, int mps, double earth_gravity, double earthx);
  39. double height_mars (double radian, int mps, double mars_gravity, double marsx);
  40. double height_moon (double radian, int mps, double moon_gravity, double moonx);
  41. int main ()
  42. {
  43. int mps;
  44. double angle;
  45.  
  46. cout << " *** Program 3 Planetary Trajectory Simulator *** " << endl;
  47. cout << endl;
  48. cout << " Enter the speed of launch (mps) ";
  49. cin >> mps;
  50. cout << " Enter the angle of launch (degrees) " ;
  51. cin >> angle;
  52. cout << endl;
  53.  
  54. double pi = 3.1415927;
  55. double radian = pi * ( angle / 180);
  56. double earth_gravity = 9.81;
  57. double moon_gravity = 1.62;
  58. double mars_gravity = 3.69;
  59. double earthx = distance_earth (angtorad(angle,pi),mps,earth_gravity);
  60. double marsx = distance_mars (angtorad(angle,pi),mps,mars_gravity);
  61. double moonx = distance_moon (angtorad(angle,pi),mps,moon_gravity);
  62.  
  63. cout << " You have entered " << mps << " mps for the speed and " << angle << " degrees for the angle." << endl << endl;
  64. cout << " " << angle << " degrees is equal to " << angtorad(angle, pi) << " radian(s)." << endl << endl << endl;
  65. cout << " The distance traveled on Earth = " << distance_earth (angtorad(angle,pi),mps,earth_gravity) << " meters --";
  66. cout << " Max Height = " << height_earth (angtorad(angle,pi), mps, earth_gravity, earthx) << endl;
  67. cout << " The distance traveled on Mars = " << distance_mars (angtorad(angle,pi),mps,mars_gravity) << " meters -- ";
  68. cout << " Max Height = " << height_mars (angtorad(angle,pi), mps, mars_gravity, marsx) << endl;
  69. cout << " The distance traveled on The Moon = " << distance_moon (angtorad(angle,pi),mps,moon_gravity)<< " meters ";
  70. cout << " Max Height = " << height_moon (angtorad(angle,pi), mps, moon_gravity, moonx) << endl;
  71.  
  72. return 0;
  73. }
  74. double angtorad (double angle, double pi)
  75. {
  76. double radian;
  77. radian = pi * (angle / 180);
  78. return radian;
  79. }
  80. double distance_earth (double angle, int mps, double earth_gravity)
  81. {
  82. double earth_distance;
  83. earth_distance = sin(angle + angle)*(mps*mps) / earth_gravity;
  84. return earth_distance;
  85. }
  86. double distance_moon (double angle, int mps, double moon_gravity)
  87. {
  88. double moon_distance;
  89. moon_distance = sin(angle + angle)*(mps*mps) / moon_gravity;
  90. return moon_distance;
  91. }
  92. double distance_mars (double angle, int mps, double mars_gravity)
  93. {
  94. double mars_distance;
  95. mars_distance = sin(angle + angle)*(mps*mps) / mars_gravity;
  96. return mars_distance;
  97. }
  98. double height_earth (double radian, int mps, double earth_gravity, double earthx)
  99. {
  100. double max_height_earth;
  101. max_height_earth = (earthx*(tan(radian)))-((earth_gravity*(earthx*earthx)) / (2*((mps*(cos(radian)))*(mps*(cos(radian))))));
  102. return max_height_earth;
  103. }
  104. double height_mars (double radian, int mps, double mars_gravity, double marsx)
  105. {
  106. double max_height_mars;
  107. max_height_mars = (marsx*(tan(radian)))-((mars_gravity*(marsx*marsx)) / (2*((mps*(cos(radian)))*(mps*(cos(radian))))));
  108. return max_height_mars;
  109. }
  110. double height_moon (double radian, int mps, double moon_gravity, double moonx)
  111. {
  112. double max_height_moon;
  113. max_height_moon = (moonx*(tan(radian)))-((moon_gravity*(moonx*moonx)) / (2*((mps*(cos(radian)))*(mps*(cos(radian))))));
  114. return max_height_moon;
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 52
Reputation: Skeen is an unknown quantity at this point 
Solved Threads: 1
Skeen's Avatar
Skeen Skeen is offline Offline
Junior Poster in Training
 
0
  #10
29 Days Ago
Well I'm getting Height = 0.000224
No matter what I'm doing (using the numbers you gave up in the start).

You said the output were supposed to be around 670, how do you know that? - Just checking
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC