Advertisement
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 {
- public static void main(String[] args) throws IOException {
- Scanner input = new Scanner(new File("EphemerisData.txt"));
- ArrayList<Double> motion = new ArrayList<Double>(); //contains data for apparent motion in RA (corrected by cos(DEC) = real motion in sky (in arcsec/min)
- ArrayList<Double> distances = new ArrayList<Double>(); //contains data for simulated distances of horseshoe asteroid to the Sun (in AU)
- //populates radii and motion ArrayLists with data from Ephemeris simulation
- while(input.hasNextLine()) {
- //When adding each new motion value in arcsec/min, it is automatically converted to AU/day by the convertMotion() method
- // motion.add(convertMotion(input.nextDouble()));
- motion.add(input.nextDouble());
- distances.add(input.nextDouble());
- }
- ArrayList<Double> modeledDistances = checkModel(motion, distances);
- 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);
- }
- input.close();
- }
- public static ArrayList<Double> checkModel(ArrayList<Double> motion, ArrayList<Double> distances) {
- // 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 e = 0.51485; //eccentricity of orbit
- double a = 0.99774; //semi-major axis (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);
- for(int i = 0; i < motion.size(); i++) {
- //total distance traveled in period to current day is iterative sum of ArrayList<BigDecimal> motion to current day
- //distanceSincePeriapsis += motion.get(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);
- theta += motion.get(i) * 1440 / 3600 * Math.PI / 180;
- //System.out.println(theta);
- distance = (a * (1 - Math.pow(e, 2))) / (1 + e * Math.cos(theta));
- modeledDistances.add(distance);
- }
- return modeledDistances;
- }
- public static double convertMotion(double motion) {
- //motion is given in arcsec/min. First, we must convert it to arcsec/day.
- double convertedMotion = motion;
- convertedMotion *= 1440; //There are 1440 minutes in 1 day. Now, we have motion in arcsec/day.
- convertedMotion = 1 / convertedMotion; //To convert from arcsec/day to parsec/day, we compute 1 / motion.
- convertedMotion *= 206265; //There are 206265 AU in 1 parsec. Hence, we multiply motion by 206265.
- return convertedMotion;
- }
- //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;
- } */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement