Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Princeton University Explorer Competition
- * Team: Sherlock Ohms */
- import java.util.Scanner;
- import java.util.ArrayList;
- import java.io.*;
- public class HorseshoeModelSimulation {
- static final double G = 6.67430 * Math.pow(10, -11); //Newton's gravitational constant
- static final double M_SOL = 1.989 * Math.pow(10, 30); //Mass of the Sun (Msol) in kg
- public static void main(String[] args) throws IOException {
- Scanner input = new Scanner(new File("CruithneData.txt"));
- ArrayList<Double> distances = new ArrayList<Double>(); //contains data for simulated distances of horseshoe asteroid to the Sun (in AU)
- double e, a;
- e = input.nextDouble(); //reads in eccentricity of asteroid
- a = input.nextDouble(); //reads in semi-major axis of asteroid (in AU)
- //populates radii ArrayList with data from Ephemeris simulation
- while(input.hasNextLine()) {
- distances.add(input.nextDouble());
- }
- ArrayList<Double> modeledDistances = checkModel(distances, a, e);
- double error;
- for(int i = 0; i < modeledDistances.size(); i++) {
- error = Math.abs(1 - (modeledDistances.get(i) / distances.get(i)));
- System.out.printf("%.4f %.4f %.4f%%\n", distances.get(i), modeledDistances.get(i), error * 100);
- }
- input.close();
- }
- public static ArrayList<Double> checkModel(ArrayList<Double> distances, double a, double e) {
- // Formula: r(theta) = [a * (1 - e^2)] / [1 + e * cos(theta)]
- ArrayList<Double> modeledDistances = new ArrayList<Double>(); //contains model's calculated distance between horseshoe asteroid and the Sun for each day
- double distance; //current distance between horseshoe asteroid and the Sun (in AU)
- double b = a * (Math.sqrt(1 - Math.pow(e, 2))); //semi-minor axis (in AU)
- double theta = 0; //true anomaly: angle between current position of the orbiting object and periapsis (which is the first day of data in the text file) (in radians)
- double distanceSincePeriapsis = 0; //distance traveled along orbit since periapsis (in AU)
- //use approximation of ellipse circumference
- double orbitCircumference = calcCircumference(a, b);
- double velocity; //current orbital velocity of asteroid
- for(int i = 0; i < distances.size(); i++) {
- //Now, to obtain the anomaly angle (in radians), we take the percentage of orbit completed and multiply it by 2 pi
- theta = (distanceSincePeriapsis / orbitCircumference) * (2 * Math.PI);
- distance = (a * (1 - Math.pow(e, 2))) / (1 + e * Math.cos(theta));
- modeledDistances.add(distance);
- //update distance traveled since periapsis using velocity
- velocity = calcVelocity(distances.get(i), a);
- distanceSincePeriapsis += velocity; //Since velocity is in AU/day, adding it to distanceSincePeriapsis updates distance traveled to current day
- }
- return modeledDistances;
- }
- //performs approximation of elliptical circumference given semi-major axis and semi-minor axis; +/- 5% of true circumference
- public static double calcCircumference(double a, double b) {
- double circumference = Math.PI;
- circumference *= (a + b);
- double tempMult = 3;
- tempMult *= Math.pow(a - b, 2);
- tempMult /= Math.pow(a + b, 2);
- double tempDivisorPart = Math.pow(a - b, 2) / Math.pow(a + b, 2);
- tempDivisorPart *= -3;
- tempDivisorPart += 4;
- tempMult /= (Math.sqrt(tempDivisorPart) + 10);
- tempMult += 1;
- circumference *= tempMult;
- return circumference;
- }
- //uses vis-visa equation to calculate orbital velocity of horseshoe asteroid
- public static double calcVelocity(double r, double a) {
- double rInMeters = convertAUToMeters(r);
- double aInMeters = convertAUToMeters(a);
- double velocity = Math.sqrt(G * M_SOL * ((2 / rInMeters) - (1 / aInMeters))); //yields velocity in m/s
- velocity = convertToAUPerDay(velocity);
- return velocity;
- }
- //given velocity in m/s, converts to AU/day
- public static double convertToAUPerDay(double velocity) {
- double convertedVelocity = velocity;
- //convert from m to AU
- convertedVelocity /= (1.496 * Math.pow(10, 11));
- //convert from /sec to /day
- convertedVelocity *= 60 * 60 * 24;
- return convertedVelocity;
- }
- //converts AU to meters
- public static double convertAUToMeters(double inAU) {
- return (inAU * (1.496 * Math.pow(10, 11)));
- }
- }
Add Comment
Please, Sign In to add comment