mirror of
https://github.com/christiaangoossens/Planetary-Orbit-Simulator
synced 2025-07-06 11:00:47 +00:00
Fixed all bugs, prepare for formatting.
This commit is contained in:
@ -41,6 +41,7 @@ public class Main {
|
||||
Object jupiter = new Object("Jupiter", 1898.13E24, AU.convertToMeter(new Vector3d(-5.172279968303672E+00,1.591564562098799E+00,1.090553487095606E-01)), AU.convertToMetersPerSecond(new Vector3d(-2.306423668033420E-03,-6.856869314900905E-03,8.012916249248967E-05)));
|
||||
Object saturn = new Object("Saturn", 5.68319E26, AU.convertToMeter(new Vector3d(-3.710637850378867E+00,-9.289569433157130E+00,3.091990731378936E-01)), AU.convertToMetersPerSecond(new Vector3d(4.874750391005278E-03,-2.086615906689840E-03,-1.574898601194673E-04)));
|
||||
Object venus = new Object("Venus", 48.685E23, AU.convertToMeter(new Vector3d(-7.130901319004951E-01,-5.719763212192740E-02,4.040076577877051E-02)), AU.convertToMetersPerSecond(new Vector3d(1.525993024372452E-03,-2.024175581604569E-02,-3.656582385749146E-04)));
|
||||
Object mars = new Object("Mars", 6.4185E23, AU.convertToMeter(new Vector3d(-1.644664047074283E+00,1.714211195991345E-01,4.385749324150048E-02)), AU.convertFromMetersPerSecond(new Vector3d(-9.128062787682906E-04, -1.271783289037382E-02, -2.442517367300464E-04)));
|
||||
|
||||
/**
|
||||
* Object listing
|
||||
|
@ -56,7 +56,11 @@ public class Simulator {
|
||||
/**
|
||||
* The round has started
|
||||
*/
|
||||
System.out.println("Round " + (Simulator.round + 1) + " started!");
|
||||
if(SimulatorConfig.logConsole) {
|
||||
if(SimulatorConfig.skipConsole == -1 || Simulator.round % SimulatorConfig.skipConsole == 0 || Simulator.round == 1) {
|
||||
System.out.println("Round " + Simulator.round + " started!");
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < objects.length; i++) {
|
||||
objects[i].updatePosition(time);
|
||||
|
@ -5,7 +5,7 @@ public class SimulatorConfig {
|
||||
* Time settings
|
||||
*/
|
||||
|
||||
public static int rounds = 526100 * 35; // Amount of rounds to run the simulator for
|
||||
public static int rounds = 526100 * 250; // Amount of rounds to run the simulator for
|
||||
public static double time = 60; // Time steps in seconds
|
||||
|
||||
/**
|
||||
@ -15,13 +15,6 @@ public class SimulatorConfig {
|
||||
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 = 1000; // 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
|
||||
*/
|
||||
@ -30,4 +23,10 @@ public class SimulatorConfig {
|
||||
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 = 1440; // 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
|
||||
|
||||
/**
|
||||
* Console settings
|
||||
*/
|
||||
public static boolean logConsole = false;
|
||||
public static int skipConsole = 100000;
|
||||
}
|
||||
|
@ -10,10 +10,10 @@ public class AOP {
|
||||
Vector3d eccentricity = new Vector3d(0,0,0);
|
||||
eccentricity.sub(perihelion, aphelion);
|
||||
|
||||
if (perihelion.getY() > ascendingNode.getY()) {
|
||||
return ascendingNode.angle(eccentricity);
|
||||
} else {
|
||||
if (eccentricity.getZ() < 0) {
|
||||
return (2 * Math.PI) - ascendingNode.angle(eccentricity);
|
||||
} else {
|
||||
return ascendingNode.angle(eccentricity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ public class ObjectProcessor {
|
||||
public double aphelionDistance = -1;
|
||||
public double perihelionDistance = -1;
|
||||
|
||||
public Object thisObject;
|
||||
public Object referenceObject;
|
||||
private Object thisObject;
|
||||
private Object referenceObject;
|
||||
|
||||
public Vector3d startingPosition;
|
||||
public double lastStartDistance = -1;
|
||||
public double beforeLastStartDistance = -1;
|
||||
private Vector3d startingPosition;
|
||||
private double lastStartDistance = -1;
|
||||
private double beforeLastStartDistance = -1;
|
||||
|
||||
public Node ascendingNode;
|
||||
public Node descendingNode;
|
||||
@ -29,12 +29,17 @@ public class ObjectProcessor {
|
||||
public Node absoluteMax;
|
||||
public Node absoluteMin;
|
||||
|
||||
public Node carryOverNode;
|
||||
public int carryOverBit;
|
||||
private Node carryOverNode;
|
||||
private int carryOverBit;
|
||||
|
||||
public double referenceZ;
|
||||
|
||||
public HashMap<Integer, Vector3d[]> history = new HashMap<>();
|
||||
private HashMap<Integer, Vector3d[]> history = new HashMap<>();
|
||||
|
||||
private double lastMaxRound = -1;
|
||||
private double lastMinRound = -1;
|
||||
|
||||
private boolean skipNodes = false;
|
||||
|
||||
public void setStartingPosition(Vector3d position) {
|
||||
this.startingPosition = position;
|
||||
@ -108,23 +113,11 @@ public class ObjectProcessor {
|
||||
}
|
||||
|
||||
if (this.thisObject.position.getZ() > this.absoluteMax.getZ()) {
|
||||
/**
|
||||
* If the next maximum is more than 50 timesteps removed from the last, we've a problem
|
||||
*/
|
||||
if (Simulator.round > this.absoluteMax.round + (SimulatorConfig.time * 500)) {
|
||||
System.out.println("ERROR: I already have a maximum (" + this.absoluteMax + "), but a new one (" + this.thisObject.position + ") has presented itself.");
|
||||
}
|
||||
this.absoluteMax = new Node(this.thisObject.position);
|
||||
this.absoluteMax.setRound(Simulator.round);
|
||||
}
|
||||
|
||||
if (this.thisObject.position.getZ() < this.absoluteMin.getZ()) {
|
||||
/**
|
||||
* If the next minimum is more than 50 timesteps removed from the last, we've a problem
|
||||
*/
|
||||
if (Simulator.round > this.absoluteMin.round + (SimulatorConfig.time * 500)) {
|
||||
System.out.println("ERROR: I already have a minimum (" + this.absoluteMin + "), but a new one (" + this.thisObject.position + ") has presented itself.");
|
||||
}
|
||||
this.absoluteMin = new Node(this.thisObject.position);
|
||||
this.absoluteMin.setRound(Simulator.round);
|
||||
}
|
||||
@ -149,7 +142,9 @@ public class ObjectProcessor {
|
||||
Node result = this.findNode(this.absoluteMin, this.carryOverNode);
|
||||
|
||||
if (!result.empty()) {
|
||||
System.out.println("INFO:: Found descending node in round " + result.round + "\n");
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Found descending node in round " + result.round + "\n");
|
||||
}
|
||||
this.descendingNode = result;
|
||||
}
|
||||
} else {
|
||||
@ -157,7 +152,9 @@ public class ObjectProcessor {
|
||||
Node result = this.findNode(this.carryOverNode, this.absoluteMax);
|
||||
|
||||
if (!result.empty()) {
|
||||
System.out.println("INFO:: Found ascending node in round " + result.round + "\n");
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Found ascending node in round " + result.round + "\n");
|
||||
}
|
||||
this.ascendingNode = result;
|
||||
}
|
||||
}
|
||||
@ -181,7 +178,9 @@ public class ObjectProcessor {
|
||||
Node result = this.findNode(this.absoluteMin, this.absoluteMax);
|
||||
|
||||
if (!result.empty()) {
|
||||
System.out.println("INFO:: Found ascending node in round " + result.round + "\n");
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Found ascending node in round " + result.round + "\n");
|
||||
}
|
||||
this.ascendingNode = result;
|
||||
}
|
||||
|
||||
@ -195,7 +194,9 @@ public class ObjectProcessor {
|
||||
Node result = this.findNode(this.absoluteMin, this.absoluteMax);
|
||||
|
||||
if (!result.empty()) {
|
||||
System.out.println("INFO:: Found descending node in round " + result.round + "\n");
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Found descending node in round " + result.round + "\n");
|
||||
}
|
||||
this.descendingNode = result;
|
||||
}
|
||||
|
||||
@ -208,9 +209,31 @@ public class ObjectProcessor {
|
||||
|
||||
private Node findNode(Node min, Node max) {
|
||||
this.referenceZ = (min.getZ() + max.getZ()) / 2;
|
||||
System.out.println("INFO:: Called node finder with min: " + min + " (round " + min.round + ") and max: " + max + " (round " + max.round + ") and a reference height of " + referenceZ);
|
||||
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Called node finder with min: " + min + " (round " + min.round + ") and max: " + max + " (round " + max.round + ") and a reference height of " + referenceZ);
|
||||
}
|
||||
|
||||
Node returnNode = new Node();
|
||||
|
||||
if (lastMaxRound == -1 || lastMaxRound == -1) {
|
||||
lastMinRound = min.round;
|
||||
lastMaxRound = max.round;
|
||||
} else {
|
||||
// You should compare these values to check.
|
||||
if (lastMaxRound < min.round && max.round < min.round && min.round == lastMinRound) {
|
||||
// max2 > max1 > (min1 = min2)
|
||||
System.out.println("WARNING:: This round's values for the nodes shouldn't be trusted. They are calculated incorrectly.");
|
||||
this.skipNodes = true;
|
||||
}
|
||||
|
||||
if (lastMinRound < max.round && min.round < max.round && max.round == lastMaxRound) {
|
||||
// (max1 = max2) > min1 > min2
|
||||
System.out.println("WARNING:: This round's values for the nodes shouldn't be trusted. They are calculated incorrectly.");
|
||||
this.skipNodes = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, Vector3d[]> entry : this.history.entrySet()) {
|
||||
Integer round = entry.getKey();
|
||||
Vector3d[] vectorArray = entry.getValue();
|
||||
@ -243,6 +266,10 @@ public class ObjectProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean checkNodes() {
|
||||
return !this.skipNodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the round check
|
||||
*/
|
||||
@ -259,7 +286,9 @@ public class ObjectProcessor {
|
||||
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.");
|
||||
if (SimulatorConfig.logConsole) {
|
||||
System.out.println("INFO:: Object " + this.thisObject.name + " has made a full rotation last round.");
|
||||
}
|
||||
}
|
||||
|
||||
beforeLastStartDistance = lastStartDistance;
|
||||
@ -300,6 +329,9 @@ public class ObjectProcessor {
|
||||
absoluteMax = new Node();
|
||||
absoluteMin = new Node();
|
||||
referenceZ = -1;
|
||||
lastMaxRound = -1;
|
||||
lastMinRound = -1;
|
||||
skipNodes = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,7 @@ import com.verictas.pos.simulator.dataWriter.WritingException;
|
||||
import com.verictas.pos.simulator.mathUtils.AOP;
|
||||
import com.verictas.pos.simulator.mathUtils.AU;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Processor {
|
||||
@ -15,6 +16,8 @@ public class Processor {
|
||||
public HashMap<String, Object> initialObjectValues = new HashMap<>();
|
||||
public HashMap<String, ObjectProcessor> objects = new HashMap<>();
|
||||
|
||||
public ArrayList<Double> arguments = new ArrayList<>();
|
||||
|
||||
public Processor(Object[] objects) throws ProcessingException, WritingException {
|
||||
/**
|
||||
* Initialize DataWriter
|
||||
@ -62,10 +65,10 @@ public class Processor {
|
||||
System.out.println("\n\n============== ROTATION DATA: " + objectName.toUpperCase() + ", ROUND " + (Simulator.round - 1) + " =============");
|
||||
|
||||
if (SimulatorConfig.outputUnit.equals("AU")) {
|
||||
System.out.println("Current position (AU): " + AU.convertFromMeter(objects.get(objectName).position) + "\n");
|
||||
System.out.println("Highest point (z-axis graph) (AU): " + AU.convertFromMeter(object.absoluteMax));
|
||||
System.out.println("Lowest point (z-axis graph) (AU): " + AU.convertFromMeter(object.absoluteMin));
|
||||
System.out.println("Calculated reference height (AU) : " + AU.convertFromMeter(object.referenceZ) + "\n");
|
||||
//System.out.println("Current position (AU): " + AU.convertFromMeter(objects.get(objectName).position) + "\n");
|
||||
//System.out.println("Highest point (z-axis graph) (AU): " + AU.convertFromMeter(object.absoluteMax));
|
||||
//System.out.println("Lowest point (z-axis graph) (AU): " + AU.convertFromMeter(object.absoluteMin));
|
||||
//System.out.println("Calculated reference height (AU) : " + AU.convertFromMeter(object.referenceZ) + "\n");
|
||||
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("Ascending node (AU): " + AU.convertFromMeter(object.ascendingNode));
|
||||
@ -79,15 +82,15 @@ public class Processor {
|
||||
System.out.println("WARNING:: Descending node not found.\n");
|
||||
}
|
||||
|
||||
System.out.println("Position during apastron (AU): " + AU.convertFromMeter(object.aphelion));
|
||||
//System.out.println("Position during apastron (AU): " + AU.convertFromMeter(object.aphelion));
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during apastron in km: " + object.aphelionDistance / 1000 + "\n");
|
||||
System.out.println("Position during periastron (AU): " + AU.convertFromMeter(object.perihelion));
|
||||
//System.out.println("Position during periastron (AU): " + AU.convertFromMeter(object.perihelion));
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during periastron in km: " + object.perihelionDistance / 1000 + "\n");
|
||||
} else {
|
||||
System.out.println("Current position (m): " + objects.get(objectName).position + "\n");
|
||||
System.out.println("Highest point (z-axis graph) (m): " + object.absoluteMax);
|
||||
System.out.println("Lowest point (z-axis graph) (m): " + object.absoluteMin);
|
||||
System.out.println("Calculated reference height (m) : " + object.referenceZ + "\n");
|
||||
//System.out.println("Current position (m): " + objects.get(objectName).position + "\n");
|
||||
//System.out.println("Highest point (z-axis graph) (m): " + object.absoluteMax);
|
||||
//System.out.println("Lowest point (z-axis graph) (m): " + object.absoluteMin);
|
||||
//System.out.println("Calculated reference height (m) : " + object.referenceZ + "\n");
|
||||
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("Ascending node (m): " + object.ascendingNode);
|
||||
@ -101,15 +104,20 @@ public class Processor {
|
||||
System.out.println("WARNING:: Descending node not found.\n");
|
||||
}
|
||||
|
||||
System.out.println("Position during apastron (m): " + object.aphelion);
|
||||
//System.out.println("Position during apastron (m): " + object.aphelion);
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during apastron in km: " + object.aphelionDistance / 1000 + "\n");
|
||||
System.out.println("Position during periastron (m): " + object.perihelion);
|
||||
//System.out.println("Position during periastron (m): " + object.perihelion);
|
||||
System.out.println("Distance from (the) " + SimulatorConfig.sunName + " during periastron in km: " + object.perihelionDistance / 1000 + "\n");
|
||||
}
|
||||
|
||||
if (object.ascendingNode != null) {
|
||||
System.out.println("Argument of periapsis (radians): " + AOP.calculate(object.ascendingNode, object.perihelion, object.aphelion));
|
||||
System.out.println("Argument of periapsis (degrees): " + Math.toDegrees(AOP.calculate(object.ascendingNode, object.perihelion, object.aphelion)));
|
||||
|
||||
if (object.checkNodes()) {
|
||||
arguments.add(Math.toDegrees(AOP.calculate(object.ascendingNode, object.perihelion, object.aphelion)));
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println("ERROR:: Can't calculate the argument of periapsis because the ascending node is missing.");
|
||||
}
|
||||
@ -158,6 +166,18 @@ public class Processor {
|
||||
public void close() throws ProcessingException {
|
||||
try {
|
||||
this.writer.save();
|
||||
System.out.println("RESULTS: " + arguments);
|
||||
|
||||
// CALCULATE AVERAGE
|
||||
|
||||
double sum = 0;
|
||||
for (int i = 0; i < arguments.size(); i++){
|
||||
sum = sum + arguments.get(i);
|
||||
}
|
||||
// calculate average
|
||||
double average = sum / arguments.size();
|
||||
|
||||
System.out.println("AVERAGE: " + average);
|
||||
} catch(WritingException e) {
|
||||
throw new ProcessingException("An error occurred during creation of the file writer: " + e.toString());
|
||||
}
|
||||
|
Reference in New Issue
Block a user