This repository has been archived by the owner on Dec 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathacceleration_travel.cpp
426 lines (261 loc) · 7.46 KB
/
acceleration_travel.cpp
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// distanace = (1/2) a t^2
// a should be converted to m/s
// also need to account for half the time being in deceleration, we can just have const acceleration to the half way point.
// create a corordinate system (2d) where all the planets lie
// pick a t = 0 position for the planet position.
// allow for an "advanced" mode that would let you put in corordinates.
// we can assume mose orbits are spherical, so velocity is a function of radius
// Days are the base unit this program uses
#include <iostream>
#include <cmath>
#define PI 3.14159265
#include <vector>
const double msun = 1.989e30; //mass of the sun
const double G = 6.6743e-11; //gravitational constant
const double t_0 = 1e150; //time = 0. Large to make initial planet conditions somewhat random
const double g = 9.808e-3; //value of 1g of acceleration in km/s^2
const double c = 299792.458; //the speed of light in km/s
double mercuryloc(t,o){
double T = 88; //orbital period in days
double d = 57e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double venusloc(t,o){
double T = 224.7; //orbital period in days
double d = 108.2e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
}
double earthloc(t,o){
double T = 365.25; //orbital period in days
double d = 149.6e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
}
double marsloc(t,o){
double T = 687; //orbital period in days
double d = 228e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double jupiterloc(t,o){
double T = 4331; //orbital period in days
double d = 778.5e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double saturnloc(t,o){
double T = 10747; //orbital period in days
double d = 1432e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double uranusloc(t,o){
double T = 30589; //orbital period in days
double d = 2867e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double neptuneloc(t,o){
double T = 59800; //orbital period in days
double d = 4515e6; //distance from sun
double v = sqrt ((G * msun)/d);
double y = d * sin ((t/2*PI)T);
double x = d * cos((t/2*PI)/T);
if (o == "x") {
return x;
}
else if (o == "y") {
return y;
}
else if (o == "v") {
return v;
}
else {
return;
}
}
double calculate(x0,xf,y0,yf,a){
double dist = sqrt((xf-x0)*(xf-x0)+(yf-y0)*(yf-y0); //distance between points
double distfab = dist/2; //distance to flip and burn
double ak = a * g; //acceleration in km/s
double c0 = sqrt(x0*x0+y0*y0); //distance from dest to sun
double cf = sqrt(xf*xf+yf*yf); //dist from final to sun
// d = 0.d5 * a * t^2 . t^2 = d/(0.25 * c)
double time = 2 * sqrt(dist/a); //calculate the time in seconds
return time;
}
int main(){
std::cout << "Pick Starting Location \n \"Mercury\" \n \"Venus\" \n \"Earth\" \n \"Mars\" \n \"Jupiter\" \n \"Saturn\" \n \"Uranus\" \n \"Neptune\" \n Coordinate Input \n";
std::cin >> start; //get starting location
std::cout << "Pick Ending Location \n \"Mercury\" \n \"Venus\" \n \"Earth\" \n \"Mars\" \n \"Jupiter\" \n \"Saturn\" \n \"Uranus\" \n \"Neptune\" \n Coordinate Input \n";
std::cin >> end; //get ending locetion
std::cout << "How long in days has it been since t_0 \n";
std::cin >> t; //take time from begining
int t = t + t_0; //take into account initial conditions
std::cout << "What is the acceleration in gs \n";
std::cin >> a; //get the acceleration value
//function calls to put variables into main
if (start == "Mercury"){
stx = mercuryloc(t,x); //begining x position
sty = mercuryloc(t,y); //begining y position
stv = mecruryloc(t,v); //initial velocity
}
else if (start == "Venus"){
stx = venusloc(t,x); //begining x position
sty = venusloc(t,y); //begining y position
stv = venusloc(t,v); //initial velocity
}
else if (start == "Earth"){
stx = earthloc(t,x); //begining x position
sty = earthloc(t,y); //begining y position
stv = earthloc(t,v); //initial velocity
}
else if (start == "Mars"){
stx = marsloc(t,x); //begining x position
sty = marsloc(t,y); //begining y position
stv = marsloc(t,v); //initial velocity
}
else if (start == "Jupiter"){
stx = jupiterloc(t,x); //begining x position
sty = jupiterloc(t,y); //begining y position
stv = jupiterloc(t,v); //initial velocity
}
else if (start == "Saturn"){
stx = saturnloc(t,x); //begining x position
sty = saturnloc(t,y); //begining y position
stv = saturnloc(t,v); //initial velocity
}
else if (start == "Uranus"){
stx = uranusloc(t,x); //begining x position
sty = uranusloc(t,y); //begining y position
stv = uranusloc(t,v); //initial velocity
}
else if (start == "Neptune"){
stx = neptuneloc(t,x); //begining x position
sty = neptuneloc(t,y); //begining y position
stv = neptuneloc(t,v); //initial velocity
}
else if (start == "Coordinate Input"){
cout << "What are the coordinates of your object in x followed by y"; //get user input
cin >> double stx;
cin >> double sty;
double stv = 0;
}
else if (end == "Mercury"){
enx = mercuryloc(t,x); //begining x position
eny = mercuryloc(t,y); //begining y position
env = mecruryloc(t,v); //initial velocity
}
else if (end == "Venus"){
enx = venusloc(t,x); //begining x position
eny = venusloc(t,y); //begining y position
env = venusloc(t,v); //initial velocity
}
else if (end == "Earth"){
enx = earthloc(t,x); //begining x position
eny = earthloc(t,y); //begining y position
env = earthloc(t,v); //initial velocity
}
else if (end == "Mars"){
enx = marsloc(t,x); //begining x position
eny = marsloc(t,y); //begining y position
env = marsloc(t,v); //initial velocity
}
else if (end == "Jupiter"){
enx = jupiterloc(t,x); //begining x position
eny = jupiterloc(t,y); //begining y position
env = jupiterloc(t,v); //initial velocity
}
else if (end == "Saturn"){
enx = saturnloc(t,x); //begining x position
eny = saturnloc(t,y); //begining y position
env = saturnloc(t,v); //initial velocity
}
else if (end == "Uranus"){
enx = uranusloc(t,x); //begining x position
eny = uranusloc(t,y); //begining y position
env = uranusloc(t,v); //initial velocity
}
else if (end == "Neptune"){
enx = neptuneloc(t,x); //begining x position
eny = neptuneloc(t,y); //begining y position
env = neptuneloc(t,v); //initial velocity
else if (end == "Coordinate Input"){
cout << "What are the coordinates of your object in x followed by y"; //get user input
cin >> double enx;
cin >> double eny;
double stv = 0;
}
double sec = calculate(stx,enx,sty,eny,a); //get the time in seconds for the function
double days = sec / 86400; //time in days for the journey
std::cout << "The journey will take " << days << " to complete.\n"; //tell the user
}