1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/*
/*
Symbols used:
G - Gravitational acceleration.
O - The angle at which the projectile is launched. Please note that O is a stand in for theta.
V - The initial velocity of the projectile.
Y - The starting altitude of the projectile.
D - The distance travelled by the projectile.
T - The time taken for the projectile to land.
F - The finishing velocity of the projectile.
H - The maximum altitude of the projectile.
*/
#include <iostream>
#include <cmath>
struct projectile_movement {
double g;
double O;
double v;
double y;
double d;
double t;
double f;
double h;
};
double findD(int i, int j, int m) { // d=(v*cos(O)/g)*(v*sin(O)+sqrt(v*sin(O)^2)+2gy)
projectile_movement distancetrav;
distancetrav.g=9.806; // The projectile will gain 9.806 m/s^2 from gravity.
distancetrav.O=i; // The projectile will be launched at this angle (90*).
distancetrav.v=j; // The projectile will be launched at this speed (10m/s).
distancetrav.y=m; // The projectile will start at this altitude (10 metres).
distancetrav.t=0; // So far the projectile has not moved.
distancetrav.d=((distancetrav.v*cos(distancetrav.O)/distancetrav.g)*
(distancetrav.v*sin(distancetrav.O+sqrt(distancetrav.v*sin(pow(distancetrav.O,2)))
+2*(distancetrav.g*distancetrav.y))));
// Thank you, C++, for your very easy structure access...
return distancetrav.d;
}
double findT(int i, int j, int m) { // t=(d/(v*cos(O)))
projectile_movement distancetrav;
distancetrav.g=9.806;
distancetrav.O=i;
distancetrav.v=j;
distancetrav.y=m;
distancetrav.d=findD(i, j, m);
distancetrav.t=(distancetrav.d/(distancetrav.v*cos(distancetrav.O)));
return distancetrav.t;
}
/*
double findF(int i, int j, int m) { //
projectile_movement distancetrav;
distancetrav.g=9.806;
distancetrav.O=i;
distancetrav.v=j;
distancetrav.y=m;
distancetrav.d=findD(i, j, m);
distancetrav.t=findT(i, j, m);
distancetrav.f=?;
return distancetrav.f;
}
double findH(int i, int j, int m) { //
}
*/
using namespace std;
int main() {
int i, j, m, n;
cout << "Enter angle of trajectory (between -90 and 90): ";
cin >> i;
cin.ignore();
cout << "\nEnter starting altitude: ";
cin >> j;
cin.ignore();
cout << "\nEnter starting velocity: ";
cin >> m;
cin.ignore();
cout << "Distance travelled by projectile: " << findD(i, j, m) << endl;
cout << "Duration of projectile flight: " << findT(i, j, m) << endl;
/* cout << "Finishing velocity of projectile: " << findF(i, j, m) << endl;
cout << "Maximum height the projectile could reach: " << findH(i, j, m) << endl; */
cin.get();
return 0;
}
|