-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolarBody.java
More file actions
263 lines (240 loc) · 10.7 KB
/
SolarBody.java
File metadata and controls
263 lines (240 loc) · 10.7 KB
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
import java.util.Scanner;
/**
* This class contains premade values and situations for gravitational objects.
* It already contains several important sol system values.
* This class also allows for easy reference to starting positions.
* @author Matthew Williams, Yulia Kosharych
* @version 2018-05-16
**/
public class SolarBody{
// mass* = mass of the body (kg)
// v* = initial velocity of body (km/h)
// solDis* = distance from Sol (km)
// rad* = radius of body (km)
// universal constants
public static double G = 8.64960768*Math.pow(10, -13);
public static double au = 1.49597870700*Math.pow(10,8);
// values for common objects
public static String nameSol = "Sol";
public static double massSol = 1.989*Math.pow(10, 30);
public static double solDisSol = 0;
public static double vSol = 0;
public static double radSol = 695508;
public static String nameEarth = "Earth";
public static double massEarth = 5.972*Math.pow(10, 24);
public static double solDisEarth = au;
public static double vEarth = BodyMaths.circleVelocityG(massSol,solDisEarth);
public static double radEarth = 6371;
public static String nameLuna = "Luna";
public static double massLuna = 7.342*Math.pow(10, 22);
public static double earthDisLuna = 384402;
public static double solDisLuna = solDisEarth+earthDisLuna;
public static double vLuna = vEarth+BodyMaths.circleVelocityG(massEarth,earthDisLuna);
public static double radLuna = 1737;
public static String nameJupiter = "Jupiter";
public static double massJupiter = 1.898*Math.pow(10, 27);
public static double solDisJupiter = 5.2*au;
public static double vJupiter = BodyMaths.circleVelocityG(massSol,solDisJupiter);
public static double radJupiter = 69911;
public static String nameCallisto = "Callisto";
public static double massCallisto = 1.076*Math.pow(10, 23);
public static double jupDisCallisto = 1880000;
public static double solDisCallisto = solDisJupiter+jupDisCallisto;
public static double vCallisto = vJupiter+BodyMaths.circleVelocityG(massSol, solDisJupiter);
public static double radCallisto = 2410.3;
public static double disHorseshoe = SolarBody.solDisJupiter-BodyMaths.L1(SolarBody.solDisJupiter, SolarBody.massSol, SolarBody.massJupiter);
public String name; // name of the body
public double mass; // mass of the body (kg) strictly positive
public double solDis; // distance from Sol (km) strictly positive
public double vInitial; // initial velocity of body (km/h) positive/negative
public double rad; // radius of body (km) strictly positive
public double theta; // starting angle (rad) positive/negative
//replace velocity location or theta location with string location in constructor be able to select one of them. keep at beginning if removing both
// all other variables allow for adaption when set to a negative value
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* This method constructs a Solarbody object
* @param name String name of the body
* @param mass double mass of the body (kg)
* @param solDis double distance from Sol (km)
* @param vInitial double initial velocity of body (km/h)
* @param rad double radius of body (km)
* @param theta double starting angle (rad)
* @version 2018-05-16
**/
public SolarBody(String name, double mass, double solDis, double vInitial, double rad, double theta){
this.name=name;
this.mass=mass;
this.solDis=solDis;
this.vInitial=vInitial;
this.rad=rad;
this.theta=theta;
}//constructor
/**
* This method constructs a Solarbody with only a name and input values on all other variables
* @param name String name of the body
* @version 2018-05-16
**/
public SolarBody(String name){
this.name=name;
this.mass=-1;
this.solDis=-1;
setVelocity();
this.rad=-1;
setTheta();
}//input constructor
/**
* This method constructs a Solarbody object with user input for the starting angle
* @param mass double mass of the body (kg)
* @param solDis double distance from Sol (km)
* @param vInitial double initial velocity of body (km/h)
* @param rad double radius of body (km)
* @param name String name of the body
* @version 2018-05-16
**/
public SolarBody(double mass, double solDis, double vInitial, double rad, String name){
this.name=name;
this.mass=mass;
this.solDis=solDis;
this.vInitial=vInitial;
this.rad=rad;
setTheta();
}
/**
* This method constructs a Solarbody object with user input for the initial velcity
* @param mass double mass of the body (kg)
* @param solDis double distance from Sol (km)
* @param name String name of the body
* @param rad double radius of body (km)
* @param theta double starting angle (rad)
* @version 2018-05-16
**/
public SolarBody(double mass, double solDis, String name, double rad, double theta){
this.name=name;
this.mass=mass;
this.solDis=solDis;
setVelocity();
this.rad=rad;
this.theta=theta;
}//select a velocity constructor
/**
* This method constructs a Solarbody object with user input for the initial velocity and starting angle
* @param name String name of the body
* @param mass double mass of the body (kg)
* @param solDis double distance from Sol (km)
* @param rad double radius of body (km)
* @version 2018-05-16
**/
public SolarBody(String name, double mass, double solDis, double rad){
this.name=name;
this.mass=mass;
this.solDis=solDis;
setVelocity();
this.rad=rad;
setTheta();
}//select theta and velocity constructor
// premade starting objects that can be chosen
public static SolarBody Sol = new SolarBody(nameSol, massSol, solDisSol, vSol, radSol, 0);
public static SolarBody Jupiter = new SolarBody(nameJupiter, massJupiter, solDisJupiter, vJupiter, radJupiter, 0);
public static SolarBody Callisto = new SolarBody(nameCallisto, massCallisto, solDisCallisto, vCallisto, radCallisto, 0);
public static SolarBody Earth = new SolarBody(nameEarth, massEarth, solDisEarth, vEarth, radEarth, 0);
public static SolarBody Luna = new SolarBody(nameLuna, massLuna, solDisLuna, vLuna, radLuna, 0);
public static SolarBody SE_L4 = new SolarBody("SE_L4", -1, solDisEarth, vEarth, 0, Math.PI/3);
public static SolarBody PlanetX = new SolarBody("PlanetX", massEarth, solDisEarth, vEarth, radEarth, -Math.PI);
public static SolarBody Greeks = new SolarBody("Greeks", -1, solDisJupiter, vJupiter, 0, Math.PI/3);
public static SolarBody Trojans = new SolarBody("Trojans", 1000, solDisJupiter, vJupiter, 0, -Math.PI/3);
public static SolarBody Horseshoe = new SolarBody("Horseshoe orbit", 10, disHorseshoe, BodyMaths.circleVelocityG(SolarBody.massSol,disHorseshoe), 0, -Math.PI/2);
public static SolarBody IrregularTadpole = new SolarBody("Irregular Tadpole", 100, solDisJupiter+Math.pow(10, 7), vJupiter, 0, -Math.PI/3);
public static SolarBody Tadpole = new SolarBody("Tadpole", 100, solDisJupiter+Math.pow(10, 7), vJupiter-600, 0, -Math.PI/3);
/**
* This method sets the mass to 0 to show the path the body would take without influencing any other bodies as well as changing the name to reflect the change
* @version 2018-05-18
**/
public void setPath(){
this.mass=0;
this.name=this.name+"'s path";
}//setPath()
/**
* This method sets the theta value for an object
* @version 2018-05-18
**/
public void setTheta(){
Scanner kb = new Scanner(System.in);
System.out.println("desired theta for "+this.name+" in pi radians");
this.theta=kb.nextDouble()*Math.PI;
}//setTheta()
/**
* This method sets the velocity to a desired power of 10 from user input
* @version 2018-05-18
**/
public void setVelocity(){
Scanner kb = new Scanner(System.in);
System.out.println("desired initial velocity for "+this.name+" in km/h");
double vInit = kb.nextDouble();
System.out.print("times 10^");
double power = Math.pow(10, kb.nextDouble());
this.vInitial=vInit*power;
System.out.println("initial velcity = "+this.vInitial);
}//setVelocity()
/**
* This method sets the starting distance to a desired power of 10 from user input
* @version 2018-05-18
**/
public void setDis(){
Scanner kb = new Scanner(System.in);
System.out.println("desired initial distance for "+this.name+" in km");
double dis = kb.nextDouble();
System.out.print("times 10^");
double power = Math.pow(10, kb.nextDouble());
this.solDis=dis*power;
System.out.println("initial distance = "+this.solDis);
}//setDis()
/**
* This method sets the starting number of AUs from user input
* @version 2018-05-18
**/
public void setDisAU(){
Scanner kb = new Scanner(System.in);
System.out.println("desired initial distance for "+this.name+" in AUs");
double dis = kb.nextDouble();
this.solDis=dis*au;
System.out.println("initial distance = "+this.solDis);
}//setDisAU()
/**
* This method sets the name from user input
* @version 2018-05-18
**/
public void setName(String name){
// Scanner kb = new Scanner(System.in);
// System.out.println("name for the body");
// String name = kb.nextString();
this.name=name;
System.out.println("new name:"+this.name);
}//setnane()
/**
* This method adds to the starting distance to a desired power of 10 from user input
* @version 2018-05-18
**/
public void addDis(){
Scanner kb = new Scanner(System.in);
System.out.println("desired additional distance for "+this.name+" in km");
double dis = kb.nextDouble();
System.out.print("times 10^");
double power = Math.pow(10, kb.nextDouble());
this.solDis+=dis*power;
System.out.println("initial distance = "+this.solDis);
}//setDis()
/**
* This method adds to the starting velocity to a desired power of 10 from user input
* @version 2018-05-18
**/
public void addVel(){
Scanner kb = new Scanner(System.in);
System.out.println("desired additional velcity for "+this.name+" in km/h");
double vel = kb.nextDouble();
System.out.print("times 10^");
double power = Math.pow(10, kb.nextDouble());
this.vInitial+=vel*power;
System.out.println("initial velocity = "+this.solDis);
}//setDis()
}//class