-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrajectory_Calculation.c
94 lines (63 loc) · 3.02 KB
/
Trajectory_Calculation.c
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
92
93
94
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
#include<unistd.h>
double toRadians(double inRadians);
double maxHeight(double initialVelocity, double launchAngle);
double projectileRange(double initialVelocity, double sinLaunchAngle, double cosLaunchAngle);
double projectileTime(double initialVelocity, double sinLaunchAngle);
double trajectoryValue(double tanLaunchAngle, double initialVelocity, double cosLaunchAngle);
#define ACC_GRAV 9.81
#define PI 3.14159265
int main() {
double launchAngle, initialVelocity, trajectory, timeOfFlight, maximumHeight, range, sinLaunchAngle, cosLaunchAngle, tanLaunchAngle;
printf("Please Enter Angle of Projection(In degrees) : ");
scanf("%lf", &launchAngle);
sleep(2);
printf("Please Enter Initial Velocity(In m/s) : ");
scanf("%lf", &initialVelocity);
sinLaunchAngle = sin(toRadians(launchAngle));
cosLaunchAngle = cos(toRadians(launchAngle));
tanLaunchAngle = tan(toRadians(launchAngle));
maximumHeight = maxHeight(initialVelocity, sinLaunchAngle);
range = projectileRange(initialVelocity, sinLaunchAngle, cosLaunchAngle);
timeOfFlight = projectileTime(initialVelocity, sinLaunchAngle);
trajectory = trajectoryValue(tanLaunchAngle, initialVelocity, cosLaunchAngle);
system("cls");
printf("Computing launch angle...\n");
sleep(3);
printf("The Launch Angle is : %.2lf degrees\n", launchAngle);
sleep(3);
printf("Computing Maximum height..\n");
sleep(3);
printf("The Maximum Height is : %.2lf meters\n", maximumHeight);
sleep(3);
printf("Computing projectile range...\n");
sleep(3);
printf("The Projectile Range is : %.2lf meters\n", range);
sleep(3);
printf("Computing Time of flight...\n");
sleep(3);
printf("The Projectile Time of Flight is : %.2lf seconds\n", timeOfFlight);
sleep(3);
printf("Equating the final trajectory path...\n");
sleep(3);
printf("The Final Trajectory of Path is y = x * %0.2lf - %0.2lfx^2 \n", tanLaunchAngle, ACC_GRAV/(2 * pow(initialVelocity, 2) * pow(cosLaunchAngle, 2)));
sleep(3);
}
double toRadians(double inLaunchAngleDegrees) {
return inLaunchAngleDegrees * (PI / 180);
}
double maxHeight(double initialVelocity, double sinLaunchAngle) {
return pow((initialVelocity * sinLaunchAngle), 2) / (2 * ACC_GRAV);
}
double projectileRange(double initialVelocity, double sinLaunchAngle, double cosLaunchAngle) {
return ((pow(initialVelocity, 2)) * 2 * sinLaunchAngle * cosLaunchAngle) / ACC_GRAV;
}
double projectileTime(double initialVelocity, double sinLaunchAngle) {
return (2 * initialVelocity * sinLaunchAngle) / ACC_GRAV;
}
double trajectoryValue(double tanLaunchAngle, double initialVelocity, double cosLaunchAngle) {
return (tanLaunchAngle - (ACC_GRAV / 2 * (pow(initialVelocity, 2)) * (pow(cosLaunchAngle, 2))));
}