mirror of
https://github.com/christiaangoossens/Planetary-Orbit-Simulator
synced 2025-07-03 18:10:47 +00:00
October 2016 Revision
This commit is contained in:
@ -23,12 +23,21 @@ public class Main {
|
||||
/**
|
||||
* Object definitions
|
||||
*/
|
||||
Object sun = new Object("Sun", 1.988544E30, AU.convertToMeter(new Vector3d(3.621484938699030E-03,3.203347049968909E-03,-1.609087138389905E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.730306264794065E-06,6.909301960615850E-06,3.332250766613383E-08)));
|
||||
|
||||
/**
|
||||
* Definitions for the ecliptic plane
|
||||
*/
|
||||
//Object sun = new Object("Sun", 1.988544E30, AU.convertToMeter(new Vector3d(3.621484938699030E-03,3.203347049968909E-03,-1.609087138389905E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.730306264794065E-06,6.909301960615850E-06,3.332250766613383E-08)));
|
||||
//Object venus = new Object("Venus", 48.685E23, AU.convertToMeter(new Vector3d(-3.786926829662159E-01,-6.122709221027441E-01,1.346180701578967E-02)), AU.convertToMetersPerSecond(new Vector3d(1.703979708314098E-02,-1.075790617185284E-02,-1.130972411646143E-03)));
|
||||
Object earth = new Object("Earth", 5.97219E24, AU.convertToMeter(new Vector3d(1.000272608326749E+00,-1.305632418724720E-01,-1.614384880329670E-04)), AU.convertToMetersPerSecond(new Vector3d(2.003180730888720E-03,1.698793770993201E-02,5.869001824818362E-08)));
|
||||
// Object mars = new Object("Mars", 6.4185E23, AU.convertToMeter(new Vector3d(8.638055532014732E-01,-1.094520306989018E+00,-4.427515002554464E-02)), AU.convertToMetersPerSecond(new Vector3d(1.154235320339802E-02,9.839355267552327E-03,-7.723750026136471E-05)));
|
||||
// Object jupiter = new Object("Jupiter", 1898.13E24, AU.convertToMeter(new Vector3d(-5.440309619306835E+00,-2.383659935837559E-01,1.226571001615609E-01)), AU.convertToMetersPerSecond(new Vector3d(2.422143907277735E-04,-7.182284468246539E-03,2.440789748210396E-05)));
|
||||
Object moon = new Object("The Moon", 734.9E20, AU.convertToMeter(new Vector3d(1.002390058141768E+00,-1.318677081380600E-01,-1.051759034600983E-04)), AU.convertToMetersPerSecond(new Vector3d(2.294349896503608E-03,1.752303034437222E-02,-5.522655228080146E-05)));
|
||||
//Object earth = new Object("Earth", 5.97219E24, AU.convertToMeter(new Vector3d(1.000272608326749E+00,-1.305632418724720E-01,-1.614384880329670E-04)), AU.convertToMetersPerSecond(new Vector3d(2.003180730888720E-03,1.698793770993201E-02,5.869001824818362E-08)));
|
||||
//Object mars = new Object("Mars", 6.4185E23, AU.convertToMeter(new Vector3d(8.638055532014732E-01,-1.094520306989018E+00,-4.427515002554464E-02)), AU.convertToMetersPerSecond(new Vector3d(1.154235320339802E-02,9.839355267552327E-03,-7.723750026136471E-05)));
|
||||
//Object jupiter = new Object("Jupiter", 1898.13E24, AU.convertToMeter(new Vector3d(-5.440309619306835E+00,-2.383659935837559E-01,1.226571001615609E-01)), AU.convertToMetersPerSecond(new Vector3d(2.422143907277735E-04,-7.182284468246539E-03,2.440789748210396E-05)));
|
||||
//Object moon = new Object("The Moon", 734.9E20, AU.convertToMeter(new Vector3d(1.002390058141768E+00,-1.318677081380600E-01,-1.051759034600983E-04)), AU.convertToMetersPerSecond(new Vector3d(2.294349896503608E-03,1.752303034437222E-02,-5.522655228080146E-05)));
|
||||
|
||||
// 1 januari startdag
|
||||
Object sun = new Object("Sun", 1.988544E30, AU.convertToMeter(new Vector3d(3.737881713150281E-03,1.402397586692506E-03,-1.612700291840256E-04)), AU.convertToMetersPerSecond(new Vector3d(8.619338996535534E-07,6.895607793642275E-06,-2.794074909231784E-08)));
|
||||
Object earth = new Object("Earth", 5.97219E24, AU.convertToMeter(new Vector3d(-1.630229002588497E-01,9.704723344534316E-01,-1.955367328932975E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.723383356491747E-02,-2.969134550063944E-03,-4.433758674928828E-07)));
|
||||
Object moon = new Object("The Moon", 734.9E20, AU.convertToMeter(new Vector3d(-1.657103868749121E-01,9.706382026425473E-01,-1.879812512691582E-04)), AU.convertToMetersPerSecond(new Vector3d(-1.728100931961937E-02,-3.525371122447976E-03,4.909148618073602E-05)));
|
||||
|
||||
/**
|
||||
* Object listing
|
||||
@ -36,6 +45,7 @@ public class Main {
|
||||
|
||||
Object[] objects = {sun, earth, moon};
|
||||
|
||||
|
||||
/**
|
||||
* Run the simulator for the specified objects
|
||||
*/
|
||||
|
@ -10,11 +10,6 @@ public class Object {
|
||||
public Vector3d acceleration;
|
||||
public Vector3d oldAcceleration;
|
||||
|
||||
public Vector3d aphelion;
|
||||
public Vector3d perihelion;
|
||||
public double aphelionDistance = 0;
|
||||
public double perihelionDistance = 0;
|
||||
|
||||
public String name;
|
||||
|
||||
private double gravitationalConstant = 6.67384E-11;
|
||||
@ -145,6 +140,17 @@ public class Object {
|
||||
return distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vector distance between the current position vector and a given position.
|
||||
* @param position The position vector you want the distance to.
|
||||
* @return Vector3d The distance vector
|
||||
*/
|
||||
public Vector3d getDistance(Vector3d position) {
|
||||
Vector3d distance = new Vector3d(0,0,0); // Empty
|
||||
distance.sub(this.position, position);
|
||||
return distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the position based on dt
|
||||
* @param dt The difference in time
|
||||
@ -202,38 +208,4 @@ public class Object {
|
||||
acceleration.scale(factor);
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the aphelion & perihelion
|
||||
* @param sun
|
||||
*/
|
||||
public void processAphelionAndPerihelion(Object sun) {
|
||||
double sunDistance = this.getDistance(sun).length();
|
||||
|
||||
/**
|
||||
* Set the defaults
|
||||
*/
|
||||
|
||||
if (this.aphelionDistance == 0) {
|
||||
this.aphelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
if (this.perihelionDistance == 0) {
|
||||
this.perihelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the aphelion or perihelion should be changed
|
||||
*/
|
||||
|
||||
if (sunDistance > aphelionDistance) {
|
||||
this.aphelion = position;
|
||||
this.aphelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
if (sunDistance < perihelionDistance) {
|
||||
this.perihelion = position;
|
||||
this.perihelionDistance = sunDistance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package com.verictas.pos.simulator;
|
||||
import javax.vecmath.*;
|
||||
|
||||
import com.verictas.pos.simulator.dataWriter.DataWriter;
|
||||
import com.verictas.pos.simulator.dataWriter.WritingException;
|
||||
import com.verictas.pos.simulator.mathUtils.Vector3dMatrix;
|
||||
import com.verictas.pos.simulator.processor.ProcessingException;
|
||||
import com.verictas.pos.simulator.processor.Processor;
|
||||
|
||||
public class Simulator {
|
||||
public static void run(Object[] objects) {
|
||||
@ -28,18 +29,10 @@ public class Simulator {
|
||||
/**
|
||||
* Define the forces matrix and the DataWriter
|
||||
*/
|
||||
Vector3dMatrix matrix = new Vector3dMatrix(objects.length,objects.length);
|
||||
Vector3dMatrix matrix = new Vector3dMatrix(objects.length, objects.length);
|
||||
|
||||
try {
|
||||
DataWriter writer = new DataWriter();
|
||||
|
||||
/**
|
||||
* Write begin values
|
||||
*/
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
writer.write(objects[i], objects[0]);
|
||||
}
|
||||
Processor processor = new Processor(objects);
|
||||
|
||||
/**
|
||||
* Start the leap frog integration!
|
||||
@ -54,7 +47,8 @@ public class Simulator {
|
||||
/**
|
||||
* The round has started
|
||||
*/
|
||||
System.out.println("\nRound " + (t + 1) + " started!");
|
||||
//System.out.println("\nRound " + (t + 1) + " started!");
|
||||
System.out.println("Round " + (t + 1) + " started!");
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
objects[i].updatePosition(time);
|
||||
@ -65,15 +59,13 @@ public class Simulator {
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
objects[i].updateSpeed(time);
|
||||
writer.write(objects[i], objects[0]);
|
||||
|
||||
/**
|
||||
* Do some processing to get the aphelion & perihelion
|
||||
*/
|
||||
|
||||
objects[i].processAphelionAndPerihelion(objects[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the processing on the objects
|
||||
*/
|
||||
processor.process(objects);
|
||||
|
||||
/**
|
||||
* The round has ended
|
||||
*/
|
||||
@ -82,23 +74,16 @@ public class Simulator {
|
||||
/**
|
||||
* Log that the simulation has finished and save info to file
|
||||
*/
|
||||
writer.save();
|
||||
processor.close();
|
||||
System.out.println("========== Simulation Finished ==========");
|
||||
|
||||
// TEST
|
||||
|
||||
System.out.println("\n\n============== Simulation data =============");
|
||||
System.out.println("Position during aphelion: " + objects[1].aphelion);
|
||||
System.out.println("Distance from the sun during aphelion in km: " + objects[1].aphelionDistance);
|
||||
System.out.println("Position during perihelion: " + objects[1].perihelion);
|
||||
System.out.println("Distance from the sun during perihelion in km: " + objects[1].perihelionDistance);
|
||||
System.out.println("===========================================\n\n");
|
||||
|
||||
/**
|
||||
* Display information about the program runtime
|
||||
*/
|
||||
long stopTime = System.currentTimeMillis();
|
||||
System.out.println("Simulation took: " + (stopTime - startTime) + "ms");
|
||||
} catch(ProcessingException e) {
|
||||
e.printStackTrace();
|
||||
} catch(WritingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -124,27 +109,27 @@ public class Simulator {
|
||||
|
||||
Vector3d force = objects[i].getForceOnObject(objects[o]);
|
||||
matrix.setPosition(force, i, o);
|
||||
System.out.println("Force " + (i + 1) + " on " + (o + 1) + " - " + force);
|
||||
//System.out.println("Force " + (i + 1) + " on " + (o + 1) + " - " + force);
|
||||
|
||||
/**
|
||||
* Also put in the opposite force
|
||||
*/
|
||||
force.scale(-1);
|
||||
matrix.setPosition(force, o, i);
|
||||
System.out.println("Force " + (o + 1) + " on " + (i + 1) + " - " + force);
|
||||
//System.out.println("Force " + (o + 1) + " on " + (i + 1) + " - " + force);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println("\n");
|
||||
System.out.println(matrix);
|
||||
//System.out.println("\n");
|
||||
//System.out.println(matrix);
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
/**
|
||||
* Progress forces on the object
|
||||
*/
|
||||
Vector3d forceOnI = matrix.getColumnTotal(i);
|
||||
System.out.println("All forces on " + (i + 1) + " - " + forceOnI);
|
||||
//System.out.println("All forces on " + (i + 1) + " - " + forceOnI);
|
||||
objects[i].enactForceOnObject(forceOnI);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,33 @@
|
||||
package com.verictas.pos.simulator;
|
||||
|
||||
public class SimulatorConfig {
|
||||
// The amount of rounds and the time step
|
||||
public static int rounds = 525960;
|
||||
public static double time = 60; // in seconds
|
||||
/**
|
||||
* Time settings
|
||||
*/
|
||||
|
||||
// Set the skipLines integer to skip lines (for example: every 5th line is written) in the output file (for smaller files), if this is set to 1, it has no effect and all lines will be written.
|
||||
public static int skipLines = 5;
|
||||
public static int rounds = 526100 * 35 * 60; // Amount of rounds to run the simulator for
|
||||
public static double time = 1; // Time steps in seconds
|
||||
|
||||
/**
|
||||
* Object settings
|
||||
*/
|
||||
|
||||
public static String sunName = "Sun"; // The name of the sun to calculate values TO
|
||||
public static String[] objectNames = { "Earth" }; // The name of the object(s) your want to calculate the values OF
|
||||
|
||||
/**
|
||||
* Ascending & descending node detection
|
||||
*/
|
||||
|
||||
public static double z = -22439680.6; // Reference z height for the used system in meters
|
||||
public static double zThreshold = 100; // Threshold value to specify the maximum value (in meters) the z difference can be to be considered close to the reference plane (To eliminate all bending points that are to far away from the z-axis to count as nodes)
|
||||
|
||||
/**
|
||||
* Output preferences
|
||||
*/
|
||||
|
||||
public static String outputUnit = "AU"; // Preferred output unit preference (AU => AU/day, m => m/s)
|
||||
public static int outputNumbers = 0; // Preferred way of outputting numbers: (0 => comma for decimals, dot in large numbers OR 1 => comma for large numbers, dot with decimals)
|
||||
public static int skipLines = 2629743; // Set the skipLines integer to skip lines (for example: every 5th line is written) in the output file (for smaller files), if this is set to 1, it has no effect and all lines will be written.
|
||||
public static boolean skipUnnecessary = true; // Skip the unnecessary objects in the export
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
package com.verictas.pos.simulator.dataWriter;
|
||||
|
||||
import com.verictas.pos.simulator.Object;
|
||||
import com.verictas.pos.simulator.Simulator;
|
||||
import com.verictas.pos.simulator.SimulatorConfig;
|
||||
import com.verictas.pos.simulator.mathUtils.AU;
|
||||
import com.verictas.pos.simulator.processor.ObjectProcessor;
|
||||
|
||||
import javax.vecmath.Vector3d;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.*;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class DataWriter {
|
||||
private FileWriter writer = null;
|
||||
@ -22,11 +26,22 @@ public class DataWriter {
|
||||
|
||||
private int counter = 0;
|
||||
|
||||
/**
|
||||
* Decimal formatter
|
||||
*/
|
||||
|
||||
public DecimalFormat formatter = new DecimalFormat();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @throws WritingException
|
||||
*/
|
||||
public DataWriter() throws WritingException {
|
||||
|
||||
/**
|
||||
* Prepare the locale
|
||||
*/
|
||||
|
||||
try {
|
||||
/**
|
||||
* Define the save path
|
||||
@ -48,8 +63,33 @@ public class DataWriter {
|
||||
* Open a file to write to and write the header
|
||||
*/
|
||||
this.writer = new FileWriter(path);
|
||||
this.writer.write("Object" + DELIMITER + "Position (m)" + DELIMITER + "Position (AU)" + DELIMITER+ "Distance from the sun (m)" + DELIMITER + "Speed (m/s)" + DELIMITER + "Speed (AU/day)" + DELIMITER + "Old Acceleration" + DELIMITER + "Acceleration" + DELIMITER + "Mass" + NEW_LINE);
|
||||
|
||||
/**
|
||||
* Write the lines with information about the columns
|
||||
*/
|
||||
|
||||
if (SimulatorConfig.outputUnit.equals("AU")) {
|
||||
this.writer.write("Object" + DELIMITER + "X (AU)" + DELIMITER + "Y (AU)" + DELIMITER + "Z (AU)" + DELIMITER + "VX (AU/day)" + DELIMITER + "VY (AU/day)" + DELIMITER + "VZ (AU/day)" + NEW_LINE);
|
||||
} else {
|
||||
this.writer.write("Object" + DELIMITER + "X (m)" + DELIMITER + "Y (m)" + DELIMITER + "Z (m)" + DELIMITER + "VX (m/s)" + DELIMITER + "VY (m/s)" + DELIMITER + "VZ (m/s)" + NEW_LINE);
|
||||
}
|
||||
|
||||
this.counter++;
|
||||
|
||||
/**
|
||||
* Configure the decimal formatter
|
||||
*/
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
if (SimulatorConfig.outputNumbers == 0) {
|
||||
symbols.setDecimalSeparator(',');
|
||||
symbols.setGroupingSeparator('.');
|
||||
} else {
|
||||
symbols.setDecimalSeparator('.');
|
||||
symbols.setGroupingSeparator(',');
|
||||
}
|
||||
this.formatter.setDecimalFormatSymbols(symbols);
|
||||
this.formatter.setMinimumFractionDigits(0);
|
||||
this.formatter.setMaximumFractionDigits(25);
|
||||
} catch(IOException e) {
|
||||
throw new WritingException("The destination file couldn't be created.");
|
||||
} catch(Exception e) {
|
||||
@ -88,20 +128,19 @@ public class DataWriter {
|
||||
String id = object.name;
|
||||
Vector3d position = object.position;
|
||||
Vector3d speed = object.speed;
|
||||
Vector3d oldAcceleration = object.oldAcceleration;
|
||||
Vector3d acceleration = object.acceleration;
|
||||
double mass = object.mass;
|
||||
Vector3d AUposition = AU.convertFromMeter(position);
|
||||
Vector3d AUspeed = AU.convertFromMetersPerSecond(speed);
|
||||
|
||||
if (this.writer == null) {
|
||||
throw new WritingException("The writer isn't defined yet");
|
||||
} else {
|
||||
try {
|
||||
if (this.counter % SimulatorConfig.skipLines == 0) {
|
||||
|
||||
// Calculate the distance to the sun
|
||||
double sunDistance = object.getDistance(reference).length();
|
||||
|
||||
this.writer.append(id + DELIMITER + position.toString() + DELIMITER + AU.convertFromMeter(position).toString() + DELIMITER + String.valueOf(sunDistance) + DELIMITER + speed.toString() + DELIMITER + AU.convertFromMetersPerSecond(speed).toString() + DELIMITER + oldAcceleration.toString() + DELIMITER + acceleration.toString() + DELIMITER + String.valueOf(mass) + NEW_LINE);
|
||||
if (SimulatorConfig.outputUnit.equals("AU")) {
|
||||
this.writer.append(id + DELIMITER + decimalFormatter(AUposition.getX()) + DELIMITER + decimalFormatter(AUposition.getY()) + DELIMITER + decimalFormatter(AUposition.getZ()) + DELIMITER + decimalFormatter(AUspeed.getX()) + DELIMITER + decimalFormatter(AUspeed.getY()) + DELIMITER + decimalFormatter(AUspeed.getZ()) + NEW_LINE);
|
||||
} else {
|
||||
this.writer.append(id + DELIMITER + decimalFormatter(position.getX()) + DELIMITER + decimalFormatter(position.getY()) + DELIMITER + decimalFormatter(position.getZ()) + DELIMITER + decimalFormatter(speed.getX()) + DELIMITER + decimalFormatter(speed.getY()) + DELIMITER + decimalFormatter(speed.getZ()) + NEW_LINE);
|
||||
}
|
||||
}
|
||||
this.counter++;
|
||||
} catch (Exception e) {
|
||||
@ -111,6 +150,10 @@ public class DataWriter {
|
||||
}
|
||||
}
|
||||
|
||||
private String decimalFormatter(double input) {
|
||||
return this.formatter.format(input);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the file to disk
|
||||
* @throws WritingException
|
||||
|
14
simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java
Normal file
14
simulator/src/com/verictas/pos/simulator/mathUtils/AOP.java
Normal file
@ -0,0 +1,14 @@
|
||||
package com.verictas.pos.simulator.mathUtils;
|
||||
|
||||
import javax.vecmath.Vector3d;
|
||||
|
||||
public class AOP {
|
||||
/**
|
||||
* Helper class for calculating the argument of periapsis
|
||||
*/
|
||||
public static double calculate(Vector3d ascendingNode, Vector3d perihelion, Vector3d aphelion) {
|
||||
Vector3d eccentricity = new Vector3d(0,0,0);
|
||||
eccentricity.sub(perihelion, aphelion);
|
||||
return ascendingNode.angle(eccentricity);
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package com.verictas.pos.simulator.mathUtils;
|
||||
|
||||
import javax.vecmath.Vector3d;
|
||||
|
||||
public class AU {
|
||||
public class AU {
|
||||
/**
|
||||
* Helper class for working with astronomical units
|
||||
*/
|
||||
|
@ -0,0 +1,184 @@
|
||||
package com.verictas.pos.simulator.processor;
|
||||
|
||||
import com.verictas.pos.simulator.Object;
|
||||
import com.verictas.pos.simulator.SimulatorConfig;
|
||||
import com.verictas.pos.simulator.mathUtils.AU;
|
||||
|
||||
import javax.vecmath.Vector3d;
|
||||
|
||||
public class ObjectProcessor {
|
||||
public Vector3d aphelion;
|
||||
public Vector3d perihelion;
|
||||
public double aphelionDistance = -1;
|
||||
public double perihelionDistance = -1;
|
||||
|
||||
public Object thisObject;
|
||||
public Object referenceObject;
|
||||
|
||||
public Vector3d startingPosition;
|
||||
public double lastStartDistance = -1;
|
||||
public double beforeLastStartDistance = -1;
|
||||
|
||||
public Vector3d ascendingNode;
|
||||
public Vector3d descendingNode;
|
||||
|
||||
public double zAxisDistance = -1;
|
||||
public double pastzAxisDistance = -1;
|
||||
public Vector3d lastPos;
|
||||
|
||||
public void setStartingPosition(Vector3d position) {
|
||||
this.startingPosition = position;
|
||||
}
|
||||
|
||||
public void setObjectData(Object object) {
|
||||
this.thisObject = object;
|
||||
}
|
||||
|
||||
public void setReferenceObjectData(Object object) {
|
||||
this.referenceObject = object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the aphelion & perihelion
|
||||
*/
|
||||
public void processAphelionAndPerihelion() {
|
||||
double sunDistance = this.thisObject.getDistance(this.referenceObject).length();
|
||||
|
||||
/**
|
||||
* Set the defaults
|
||||
*/
|
||||
|
||||
if (this.aphelionDistance == -1) {
|
||||
this.aphelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
if (this.perihelionDistance == -1) {
|
||||
this.perihelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the aphelion or perihelion should be changed
|
||||
*/
|
||||
|
||||
if (sunDistance > aphelionDistance) {
|
||||
this.aphelion = this.thisObject.position;
|
||||
this.aphelionDistance = sunDistance;
|
||||
}
|
||||
|
||||
if (sunDistance < perihelionDistance) {
|
||||
this.perihelion = this.thisObject.position;
|
||||
this.perihelionDistance = sunDistance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ascending node
|
||||
*/
|
||||
|
||||
public void processNodes() {
|
||||
double zAxisDistance = Math.abs(this.thisObject.position.getZ() - SimulatorConfig.z);
|
||||
|
||||
if (this.pastzAxisDistance == -1) {
|
||||
this.pastzAxisDistance = zAxisDistance;
|
||||
}
|
||||
|
||||
if (this.pastzAxisDistance != -1 && this.zAxisDistance == -1) {
|
||||
this.zAxisDistance = zAxisDistance;
|
||||
}
|
||||
|
||||
if (this.zAxisDistance != -1 && this.pastzAxisDistance != 1) {
|
||||
if ((this.pastzAxisDistance > this.zAxisDistance && zAxisDistance > this.zAxisDistance) && (this.zAxisDistance < SimulatorConfig.zThreshold)) {
|
||||
if (SimulatorConfig.outputUnit.equals("AU")) {
|
||||
System.out.println("INFO:: Found a node within the threshold at " + AU.convertFromMeter(this.lastPos) + " (in AU) for object " + this.thisObject.name + "!");
|
||||
} else {
|
||||
System.out.println("INFO:: Found a node within the threshold at " + this.lastPos + " (in m) for object " + this.thisObject.name + "!");
|
||||
}
|
||||
|
||||
if ((this.lastPos.getZ() - this.thisObject.position.getZ()) < 0) {
|
||||
if (SimulatorConfig.z < 0) {
|
||||
// The reference plane is in negative z, so you have gone up!
|
||||
this.ascendingNode = this.lastPos;
|
||||
System.out.println("INFO:: Detected node as: ASCENDING NODE!");
|
||||
} else {
|
||||
// The reference plane is in positive z, so you have gone down!
|
||||
this.descendingNode = this.lastPos;
|
||||
System.out.println("INFO:: Detected node as: DESCENDING NODE!");
|
||||
}
|
||||
} else {
|
||||
if (SimulatorConfig.z < 0) {
|
||||
// The reference plane is in negative z, so you have gone down!
|
||||
this.descendingNode = this.lastPos;
|
||||
System.out.println("INFO:: Detected node as: DESCENDING NODE!");
|
||||
} else {
|
||||
// The reference plane is in positive z, so you have gone up!
|
||||
this.ascendingNode = this.lastPos;
|
||||
System.out.println("INFO:: Detected node as: ASCENDING NODE!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.pastzAxisDistance = this.zAxisDistance;
|
||||
this.zAxisDistance = zAxisDistance;
|
||||
}
|
||||
|
||||
this.lastPos = this.thisObject.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the round check
|
||||
*/
|
||||
public boolean processRoundCheck() {
|
||||
double startDistance = this.thisObject.getDistance(this.startingPosition).length();
|
||||
boolean fullRotation = false;
|
||||
|
||||
/**
|
||||
* Check if all are set and shuffle!
|
||||
*/
|
||||
|
||||
if (beforeLastStartDistance != -1 && lastStartDistance != -1) {
|
||||
// Ready to go!
|
||||
if (beforeLastStartDistance > lastStartDistance && startDistance > lastStartDistance) {
|
||||
// Last point was the closest to the starting position overall!
|
||||
fullRotation = true;
|
||||
System.out.println("INFO:: Object " + this.thisObject.name + " has made a full rotation last round.");
|
||||
}
|
||||
|
||||
beforeLastStartDistance = lastStartDistance;
|
||||
lastStartDistance = startDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if 1st distance is set and 2nd isn't set
|
||||
*/
|
||||
|
||||
if (beforeLastStartDistance != -1 && lastStartDistance == -1) {
|
||||
lastStartDistance = startDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the 1st distance isn't set
|
||||
*/
|
||||
if (beforeLastStartDistance == -1) {
|
||||
beforeLastStartDistance = startDistance;
|
||||
}
|
||||
|
||||
if(fullRotation) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
aphelionDistance = -1;
|
||||
perihelionDistance = -1;
|
||||
lastStartDistance = -1;
|
||||
beforeLastStartDistance = -1;
|
||||
aphelion = null;
|
||||
perihelion = null;
|
||||
ascendingNode = null;
|
||||
descendingNode = null;
|
||||
zAxisDistance = -1;
|
||||
lastPos = null;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.verictas.pos.simulator.processor;
|
||||
|
||||
public class ProcessingException extends Exception {
|
||||
public ProcessingException() { super(); }
|
||||
public ProcessingException(String message) { super(message); }
|
||||
public ProcessingException(String message, Throwable cause) { super(message, cause); }
|
||||
public ProcessingException(Throwable cause) { super(cause); }
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.verictas.pos.simulator.processor;
|
||||
|
||||
import com.verictas.pos.simulator.Object;
|
||||
import com.verictas.pos.simulator.SimulatorConfig;
|
||||
import com.verictas.pos.simulator.dataWriter.DataWriter;
|
||||
import com.verictas.pos.simulator.dataWriter.WritingException;
|
||||
import com.verictas.pos.simulator.mathUtils.AOP;
|
||||
import com.verictas.pos.simulator.mathUtils.AU;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Processor {
|
||||
private DataWriter writer;
|
||||
public HashMap<String, Object> initialObjectValues = new HashMap<>();
|
||||
public HashMap<String, ObjectProcessor> objects = new HashMap<>();
|
||||
|
||||
public Processor(Object[] objects) throws ProcessingException, WritingException {
|
||||
/**
|
||||
* Initialize DataWriter
|
||||
*/
|
||||
this.writer = new DataWriter();
|
||||
|
||||
/**
|
||||
* Store the initial values of all the objects in memory (and to a file) for later use
|
||||
*/
|
||||
this.initialObjectValues = objectArrayToHashMap(objects);
|
||||
|
||||
// Write initial values to file
|
||||
this.write(initialObjectValues);
|
||||
|
||||
/**
|
||||
* Create the object processing array
|
||||
*/
|
||||
for (Object object : initialObjectValues.values()) {
|
||||
this.objects.put(object.name, new ObjectProcessor());
|
||||
this.objects.get(object.name).setStartingPosition(object.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void process(Object[] objectArray) throws ProcessingException, WritingException {
|
||||
HashMap<String, Object> objects = objectArrayToHashMap(objectArray);
|
||||
|
||||
/**
|
||||
* Only do the processing for the asked planet(s)
|
||||
*/
|
||||
for(String objectName : SimulatorConfig.objectNames) {
|
||||
ObjectProcessor object = this.objects.get(objectName);
|
||||
|
||||
object.setObjectData(objects.get(objectName));
|
||||
object.setReferenceObjectData(objects.get(SimulatorConfig.sunName));
|
||||
|
||||
// Check if the object has gone round last round
|
||||
|
||||
boolean round = object.processRoundCheck();
|
||||
if (round) {
|
||||
// Object has gone full circle last round!
|
||||
System.out.println("\n\n============== ROTATION DATA: " + objectName.toUpperCase() + " =============");
|
||||
System.out.println("Current position (AU): " + AU.convertFromMeter(objects.get(objectName).position));
|
||||
System.out.println("Current position (m): " + objects.get(objectName).position + "\n");
|
||||
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("Ascending node (AU): " + AU.convertFromMeter(object.ascendingNode));
|
||||
System.out.println("Ascending node (m): " + object.ascendingNode + "\n");
|
||||
} else {
|
||||
if (object.descendingNode != null) {
|
||||
System.out.println("WARNING:: Ascending node not found. Because a descending node was found, you can assume the current position is the ascending node (or it is between the starting position and the current.\n");
|
||||
} else {
|
||||
System.out.println("WARNING:: Ascending node not found. Have you set the reference plane height correctly?\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (object.descendingNode != null) {
|
||||
System.out.println("Descending node (AU): " + AU.convertFromMeter(object.descendingNode));
|
||||
System.out.println("Descending node (m): " + object.descendingNode + "\n");
|
||||
} else {
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("WARNING:: Descending node not found. Because a ascending node was found, you can assume the current position is the descending node (or it is between the starting position and the current).\n");
|
||||
} else {
|
||||
System.out.println("WARNING:: Descending node not found. Have you set the reference plane height correctly?\n");
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("Position during apastron (AU): " + AU.convertFromMeter(object.aphelion));
|
||||
System.out.println("Position during apastron (m): " + object.aphelion);
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during apastron in m: " + object.aphelionDistance + "\n");
|
||||
System.out.println("Position during periastron (AU): " + AU.convertFromMeter(object.perihelion));
|
||||
System.out.println("Position during periastron (m): " + object.perihelion);
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during periastron in m: " + object.perihelionDistance + "\n");
|
||||
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("Argument of periapsis (range: 0 - PI): " + AOP.calculate(object.ascendingNode, object.perihelion, object.aphelion) + " rad");
|
||||
System.out.println("Argument of periapsis: " + Math.toDegrees(AOP.calculate(object.ascendingNode, object.perihelion, object.aphelion)) + " degrees");
|
||||
} else {
|
||||
if (object.descendingNode != null) {
|
||||
System.out.println("WARNING:: Ascending node not found. The argument is calculated with the current position as ascending node).\n");
|
||||
System.out.println("Argument of periapsis (range: 0 - PI): " + AOP.calculate(objects.get(objectName).position, object.perihelion, object.aphelion) + " rad");
|
||||
System.out.println("Argument of periapsis: " + Math.toDegrees(AOP.calculate(objects.get(objectName).position, object.perihelion, object.aphelion)) + " degrees");
|
||||
}
|
||||
System.out.println("ERROR:: Can't calculate the argument of periapsis because the ascending node is missing.");
|
||||
}
|
||||
|
||||
System.out.println("=======================================================================================\n\n");
|
||||
|
||||
object.reset();
|
||||
|
||||
// Reset starting position
|
||||
this.objects.get(objectName).setStartingPosition(objects.get(objectName).position);
|
||||
}
|
||||
|
||||
// Process values for this round
|
||||
object.processAphelionAndPerihelion();
|
||||
object.processNodes();
|
||||
|
||||
this.objects.put(objectName, object);
|
||||
}
|
||||
|
||||
this.write(objects);
|
||||
}
|
||||
|
||||
private void write(HashMap<String, Object> objects) throws ProcessingException, WritingException {
|
||||
if (SimulatorConfig.skipUnnecessary) {
|
||||
for (String name : SimulatorConfig.objectNames) {
|
||||
this.writer.write(objects.get(name), objects.get(SimulatorConfig.sunName));
|
||||
}
|
||||
} else {
|
||||
for (Object object : objects.values()) {
|
||||
this.writer.write(object, objects.get(SimulatorConfig.sunName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Object> objectArrayToHashMap(Object[] objects) {
|
||||
// Create the return map
|
||||
HashMap<String, Object> objectMap = new HashMap<>();
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
objectMap.put(objects[i].name, objects[i]);
|
||||
}
|
||||
|
||||
return objectMap;
|
||||
}
|
||||
|
||||
public void close() throws ProcessingException {
|
||||
try {
|
||||
this.writer.save();
|
||||
} catch(WritingException e) {
|
||||
throw new ProcessingException("An error occurred during creation of the file writer: " + e.toString());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user