diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 0042750..a07b8bb 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -28,10 +28,10 @@
-
-
-
-
+
+
+
+
@@ -58,47 +58,23 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+
-
+
@@ -202,31 +178,31 @@
-
+
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
diff --git a/simulator/.idea/workspace.xml b/simulator/.idea/workspace.xml
index 2c791f4..f291e4e 100644
--- a/simulator/.idea/workspace.xml
+++ b/simulator/.idea/workspace.xml
@@ -27,21 +27,21 @@
-
+
-
-
+
+
-
+
-
-
+
+
@@ -49,25 +49,28 @@
-
-
+
+
-
-
-
-
-
+
+
+
-
-
+
+
-
-
+
+
+
+
+
+
+
@@ -97,18 +100,21 @@
-
-
+
+
+
+
+
-
-
-
-
+
+
+
+
@@ -151,8 +157,9 @@
-
+
+
@@ -209,11 +216,10 @@
-
-
+
@@ -481,33 +487,33 @@
-
-
+
+
-
-
-
-
+
-
+
+
+
+
@@ -524,7 +530,7 @@
-
+
@@ -533,6 +539,270 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -557,6 +827,11 @@
+
+
+
+
+
@@ -585,6 +860,11 @@
+
+
+
+
+
@@ -610,48 +890,68 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
-
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class
index ca4a983..26319cc 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Main.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class
index aa8cdcb..d8f74f8 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Object.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class b/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class
index b2b5765..5cf14b6 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/Simulator.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class b/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class
new file mode 100644
index 0000000..90a9cc5
Binary files /dev/null and b/simulator/out/production/simulator/com/verictas/pos/simulator/SimulatorConfig.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.class b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.class
index 770a165..503b6d3 100644
Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.class and b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.class differ
diff --git a/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class b/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class
new file mode 100644
index 0000000..1a8f96e
Binary files /dev/null and b/simulator/out/production/simulator/com/verictas/pos/simulator/nBabel.class differ
diff --git a/simulator/src/com/verictas/pos/simulator/Main.java b/simulator/src/com/verictas/pos/simulator/Main.java
index 56c7ee8..11ff5b1 100644
--- a/simulator/src/com/verictas/pos/simulator/Main.java
+++ b/simulator/src/com/verictas/pos/simulator/Main.java
@@ -21,21 +21,18 @@ public class Main {
/**
* Object definitions
*/
- Object object1 = new Object(1000, new Vector3d(1,2,3), new Vector3d(0,4,3));
- Object object2 = new Object(200, new Vector3d(2,38,2), new Vector3d(3,4,5));
- Object object3 = new Object(200, new Vector3d(2,-20,2), new Vector3d(3,4,5));
- Object object4 = new Object(200, new Vector3d(2,4,2), new Vector3d(3,4,5));
+ Object object1 = new Object(1/6.67384E-11, new Vector3d(1,0,0), new Vector3d(0,0,0));
+ Object object2 = new Object(1, new Vector3d(0,0,0), new Vector3d(0,0,0));
/**
* Object listing
*/
- Object[] objects = {object1, object2, object3, object4};
+ Object[] objects = {object1, object2};
/**
- * Run the simulator for the specified amount of rounds
+ * Run the simulator for the specified objects
*/
- int rounds = 2;
- Simulator.run(rounds, objects);
+ Simulator.run(objects);
}
}
diff --git a/simulator/src/com/verictas/pos/simulator/Object.java b/simulator/src/com/verictas/pos/simulator/Object.java
index d47dd1c..31d1a5a 100644
--- a/simulator/src/com/verictas/pos/simulator/Object.java
+++ b/simulator/src/com/verictas/pos/simulator/Object.java
@@ -6,6 +6,10 @@ public class Object {
public double mass;
public Vector3d position;
public Vector3d speed;
+
+ public Vector3d acceleration;
+ public Vector3d oldAcceleration;
+
private double gravitationalConstant = 6.67384E-11;
/**
@@ -27,6 +31,19 @@ public class Object {
public void setSpeed(Vector3d speed) {
this.speed = speed;
}
+ public void setSpeed(double[] speed) {
+ this.speed = new Vector3d(speed[0], speed[1], speed[2]);
+ }
+
+ /**
+ * Gets the speed into a double[3]
+ * @return double[3]
+ */
+ public double[] getSpeed() {
+ double[] v = new double[3];
+ this.speed.get(v);
+ return v;
+ }
/**
* Sets the position vector of an object.
@@ -35,6 +52,57 @@ public class Object {
public void setPosition(Vector3d position) {
this.position = position;
}
+ public void setPosition(double[] position) {
+ this.position = new Vector3d(position[0], position[1], position[2]);
+ }
+
+ /**
+ * Gets the position into a double[3]
+ * @return double[3]
+ */
+ public double[] getPosition() {
+ double[] r = new double[3];
+ this.position.get(r);
+ return r;
+ }
+
+ /**
+ * Sets the acceleration vector of an object
+ * @param acceleration Current acceleration vector
+ */
+ public void setAcceleration(Vector3d acceleration) { this.acceleration = acceleration; }
+ public void setAcceleration(double[] acceleration) {
+ this.acceleration = new Vector3d(acceleration[0], acceleration[1], acceleration[2]);
+ }
+
+ /**
+ * Gets the acceleration into a double[3]
+ * @return double[3]
+ */
+ public double[] getAcceleration() {
+ double[] a = new double[3];
+ this.acceleration.get(a);
+ return a;
+ }
+
+ /**
+ * Sets the acceleration vector of an object
+ * @param acceleration Current acceleration vector
+ */
+ public void setOldAcceleration(Vector3d acceleration) { this.acceleration = acceleration; }
+ public void setOldAcceleration(double[] acceleration) {
+ this.oldAcceleration = new Vector3d(acceleration[0], acceleration[1], acceleration[2]);
+ }
+
+ /**
+ * Gets the acceleration into a double[3]
+ * @return double[3]
+ */
+ public double[] getOldAcceleration() {
+ double[] a = new double[3];
+ this.oldAcceleration.get(a);
+ return a;
+ }
/**
* Changes an object into readable form
@@ -61,9 +129,67 @@ public class Object {
* @param secondObject The passed object.
* @return Vector3d The distance vector
*/
- private Vector3d getDistance(Object secondObject) {
+ public Vector3d getDistance(Object secondObject) {
Vector3d distance = new Vector3d(0,0,0); // Empty
distance.sub(this.position, secondObject.position);
return distance;
}
+
+ /**
+ * Updates the position based on dt
+ * @param dt The difference in time
+ */
+ public void updatePosition(double dt) {
+ // Write the vectors to double[3]
+ double[] r = this.getPosition();
+ double[] v = this.getSpeed();
+ double[] a = this.getAcceleration();
+
+ for (int i = 0; i != 3; i++){
+ double dt2 = dt * dt;
+ r[i] += v[i] * dt + 0.5 * a[i] * dt2;
+ }
+
+ // Write the doubles into the vectors to save them
+ setPosition(r);
+ setSpeed(v);
+ setAcceleration(a);
+ }
+
+ /**
+ * Updates the speed based on dt
+ * @param dt The difference in speed
+ */
+ public void updateSpeed(double dt) {
+ // Write the vectors to double[3]
+ double[] v = this.getSpeed();
+ double[] a = this.getAcceleration();
+ double[] aold = this.getOldAcceleration();
+
+ for (int i = 0; i != 3; i++){
+ v[i] += 0.5 * dt *(a[i] + aold[i]);
+ }
+
+ setSpeed(v);
+ setAcceleration(a);
+ setOldAcceleration(aold);
+ }
+
+ /**
+ * Updates the acceleration based on dt
+ */
+ public void updateAcceleration() {
+ this.oldAcceleration = this.acceleration;
+ }
+
+ /**
+ * Enacts a certain force on the object
+ * @param force The force in N.
+ */
+ public void enactForceOnObject(Vector3d force) {
+ double factor = 1/this.mass;
+ Vector3d acceleration = force;
+ acceleration.scale(factor);
+ this.acceleration = acceleration;
+ }
}
diff --git a/simulator/src/com/verictas/pos/simulator/Simulator.java b/simulator/src/com/verictas/pos/simulator/Simulator.java
index 41ed4d2..ef836f3 100644
--- a/simulator/src/com/verictas/pos/simulator/Simulator.java
+++ b/simulator/src/com/verictas/pos/simulator/Simulator.java
@@ -3,57 +3,56 @@ import javax.vecmath.*;
import com.verictas.pos.simulator.mathUtils.Vector3dMatrix;
public class Simulator {
- public static void run(int rounds, Object[] objects) {
+ public static void run(Object[] objects) {
+
+ /**
+ * Get variables from the config
+ */
+
+ int rounds = SimulatorConfig.rounds;
/**
* Log a debug message to the console to signal the simulation has started
*/
System.out.println("========== Simulation Started ==========\n");
+ /**
+ * Define the forces matrix for this round
+ */
+ Vector3dMatrix matrix = new Vector3dMatrix(objects.length,objects.length);
+
+ accelerate(objects, matrix);
+
/**
* Start the rounds loop
*/
- for(int t = 0; t < rounds; t++) {
+ for(int t = 0; t != rounds; t++) {
/**
* The round has started
*/
- System.out.println("Round " + (t + 1) + " started!");
-
+ System.out.println("\nRound " + (t + 1) + " started!");
/**
- * Define the forces matrix for this round
+ * Define the initial values
*/
- Vector3dMatrix matrix = new Vector3dMatrix(objects.length,objects.length);
+ double time = SimulatorConfig.time;
for(int i = 0; i < objects.length; i++) {
- /**
- * For every object: calculate the force upon it.
- */
- for (int o = 0; o < objects.length; o++) {
- /**
- * Loop through all other objects
- */
- if (o == i) {
- break;
- }
-
- Vector3d force = objects[i].getForceOnObject(objects[o]);
- matrix.setPosition(force, i, o);
- 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("Object " + (i+1) + " was at " + objects[i].position);
+ objects[i].updatePosition(time);
+ objects[i].updateAcceleration();
+ System.out.println("Object " + (i+1) + " is at " + objects[i].position);
}
+ accelerate(objects, matrix);
+
/**
* Print the matrix for this round
*/
- System.out.println("\n");
- System.out.println(matrix);
+
+ for(int i = 0; i < objects.length; i++) {
+ objects[i].updateSpeed(time);
+ }
+
}
/**
@@ -61,4 +60,49 @@ public class Simulator {
*/
System.out.println("========== Simulation Finished ==========");
}
+
+ public static void accelerate(Object[] objects, Vector3dMatrix matrix) {
+ // Loop
+ for(int i = 0; i < objects.length; i++) {
+ /**
+ * For every object: calculate the force upon it.
+ */
+
+ // Reset acceleration
+ objects[i].setAcceleration(new Vector3d(0, 0, 0));
+
+ for (int o = 0; o < objects.length; o++) {
+ /**
+ * Loop through all other objects
+ */
+ if (o == i) {
+ break;
+ }
+
+ Vector3d force = objects[i].getForceOnObject(objects[o]);
+ matrix.setPosition(force, i, o);
+ 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("\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);
+ objects[i].enactForceOnObject(forceOnI);
+ }
+ }
}
diff --git a/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java
new file mode 100644
index 0000000..f10afe6
--- /dev/null
+++ b/simulator/src/com/verictas/pos/simulator/SimulatorConfig.java
@@ -0,0 +1,6 @@
+package com.verictas.pos.simulator;
+
+public class SimulatorConfig {
+ public static int rounds = 2;
+ public static double time = 1;
+}
diff --git a/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java b/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java
index f0cdfa3..1d43106 100644
--- a/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java
+++ b/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java
@@ -113,7 +113,6 @@ public class Vector3dMatrix extends GMatrix {
resultVector.add(new Vector3d(x, y, z));
}
- System.out.println(resultVector);
return resultVector;
}
@@ -142,7 +141,6 @@ public class Vector3dMatrix extends GMatrix {
resultVector.add(new Vector3d(x, y, z));
}
- System.out.println(resultVector);
return resultVector;
}
}
\ No newline at end of file
diff --git a/simulator/src/com/verictas/pos/simulator/nBabel.java b/simulator/src/com/verictas/pos/simulator/nBabel.java
new file mode 100644
index 0000000..da03435
--- /dev/null
+++ b/simulator/src/com/verictas/pos/simulator/nBabel.java
@@ -0,0 +1,4 @@
+package com.verictas.pos.simulator;
+
+public class nBabel {
+}