diff --git a/simulator/.idea/workspace.xml b/simulator/.idea/workspace.xml index d04d1ab..02f2090 100644 --- a/simulator/.idea/workspace.xml +++ b/simulator/.idea/workspace.xml @@ -30,8 +30,8 @@ - - + + @@ -40,8 +40,8 @@ - - + + @@ -52,8 +52,8 @@ - - + + @@ -61,17 +61,13 @@ - - + + - - + + - - - - @@ -100,10 +96,11 @@ @@ -154,6 +151,8 @@ + + @@ -203,12 +202,36 @@ + + + + + + + + + + + - - @@ -481,7 +504,7 @@ - + @@ -489,9 +512,10 @@ + - + @@ -504,9 +528,8 @@ - - + @@ -534,120 +557,117 @@ - - + + - + - - + + - - - - - - - - - + - + + + - - - - + - - - + + + + + - + - - + + - + - - - + + + + + - + + - - - - - - + + + - + + + + + + + + + - - + + - - + + - - + + - + - - + + - - - - - - + + diff --git a/simulator/out/artifacts/simulator_jar/simulator.jar b/simulator/out/artifacts/simulator_jar/simulator.jar index 0abd52d..3da95b7 100644 Binary files a/simulator/out/artifacts/simulator_jar/simulator.jar and b/simulator/out/artifacts/simulator_jar/simulator.jar differ 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 025aeb4..ca4a983 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 bc59a54..aa8cdcb 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 3f14b2c..b2b5765 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/mathUtils/Vector3dMatrix.class b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.class new file mode 100644 index 0000000..770a165 Binary files /dev/null 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/mathUtils/Vector3fMatrix.class b/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.class deleted file mode 100644 index 0e95b38..0000000 Binary files a/simulator/out/production/simulator/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.class and /dev/null differ diff --git a/simulator/src/com/verictas/pos/simulator/Main.java b/simulator/src/com/verictas/pos/simulator/Main.java index 22e59b7..828b178 100644 --- a/simulator/src/com/verictas/pos/simulator/Main.java +++ b/simulator/src/com/verictas/pos/simulator/Main.java @@ -5,10 +5,10 @@ import javax.vecmath.*; public class Main { public static void main(String[] args) { - Object object1 = new Object(1000, new Vector3f(1,2,3), new Vector3f(0,4,3)); - Object object2 = new Object(200, new Vector3f(2,38,2), new Vector3f(3,4,5)); - Object object3 = new Object(200, new Vector3f(2,-20,2), new Vector3f(3,4,5)); - Object object4 = new Object(200, new Vector3f(2,4,2), new Vector3f(3,4,5)); + 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)); // Make a list of all the objects Object[] objects = {object1, object2, object3, object4}; diff --git a/simulator/src/com/verictas/pos/simulator/Object.java b/simulator/src/com/verictas/pos/simulator/Object.java index 9b7c965..d47dd1c 100644 --- a/simulator/src/com/verictas/pos/simulator/Object.java +++ b/simulator/src/com/verictas/pos/simulator/Object.java @@ -4,8 +4,8 @@ import java.lang.*; public class Object { public double mass; - public Vector3f position; - public Vector3f speed; + public Vector3d position; + public Vector3d speed; private double gravitationalConstant = 6.67384E-11; /** @@ -14,7 +14,7 @@ public class Object { * @param position The position vector of the object * @param speed The speed vector of the object */ - public Object(double mass, Vector3f position, Vector3f speed) { + public Object(double mass, Vector3d position, Vector3d speed) { this.mass = mass; this.position = position; this.speed = speed; @@ -24,7 +24,7 @@ public class Object { * Sets the speed vector of an object * @param speed Current speed vector */ - public void setSpeed(Vector3f speed) { + public void setSpeed(Vector3d speed) { this.speed = speed; } @@ -32,7 +32,7 @@ public class Object { * Sets the position vector of an object. * @param position Current position vector */ - public void setPosition(Vector3f position) { + public void setPosition(Vector3d position) { this.position = position; } @@ -47,22 +47,22 @@ public class Object { /** * Calculates the force of the passed object on the current object. * @param secondObject The passed object - * @return Vector3f The gravitational force + * @return Vector3d The gravitational force */ - public Vector3f getForceOnObject(Object secondObject) { + public Vector3d getForceOnObject(Object secondObject) { double scale = gravitationalConstant * ((this.mass * secondObject.mass) / Math.pow(getDistance(secondObject).length(), 3.0)); - Vector3f force = getDistance(secondObject); - force.scale((float) scale); + Vector3d force = getDistance(secondObject); + force.scale(scale); return force; } /** * Get the vector distance between the current position vector and the position vector of the passed object. * @param secondObject The passed object. - * @return Vector3f The distance vector + * @return Vector3d The distance vector */ - private Vector3f getDistance(Object secondObject) { - Vector3f distance = new Vector3f(0,0,0); // Empty + private Vector3d getDistance(Object secondObject) { + Vector3d distance = new Vector3d(0,0,0); // Empty distance.sub(this.position, secondObject.position); return distance; } diff --git a/simulator/src/com/verictas/pos/simulator/Simulator.java b/simulator/src/com/verictas/pos/simulator/Simulator.java index 7ca08b3..41ed4d2 100644 --- a/simulator/src/com/verictas/pos/simulator/Simulator.java +++ b/simulator/src/com/verictas/pos/simulator/Simulator.java @@ -1,6 +1,6 @@ package com.verictas.pos.simulator; import javax.vecmath.*; -import com.verictas.pos.simulator.mathUtils.Vector3fMatrix; +import com.verictas.pos.simulator.mathUtils.Vector3dMatrix; public class Simulator { public static void run(int rounds, Object[] objects) { @@ -22,7 +22,7 @@ public class Simulator { /** * Define the forces matrix for this round */ - Vector3fMatrix matrix = new Vector3fMatrix(objects.length,objects.length); + Vector3dMatrix matrix = new Vector3dMatrix(objects.length,objects.length); for(int i = 0; i < objects.length; i++) { /** @@ -36,7 +36,7 @@ public class Simulator { break; } - Vector3f force = objects[i].getForceOnObject(objects[o]); + Vector3d force = objects[i].getForceOnObject(objects[o]); matrix.setPosition(force, i, o); System.out.println("Force " + (i + 1) + " on " + (o + 1) + " - " + force); diff --git a/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java b/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java similarity index 55% rename from simulator/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java rename to simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java index 9730cd1..f0cdfa3 100644 --- a/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java +++ b/simulator/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java @@ -1,15 +1,15 @@ package com.verictas.pos.simulator.mathUtils; import javax.vecmath.GMatrix; -import javax.vecmath.Vector3f; +import javax.vecmath.Vector3d; -public class Vector3fMatrix extends GMatrix { +public class Vector3dMatrix extends GMatrix { /** * Creates a new matrix with some helper functions for use with Vector3f. The created matrix will be empty. * @param n The number of rows. * @param m The number of columns. */ - public Vector3fMatrix(int n, int m) { + public Vector3dMatrix(int n, int m) { // Change the size to suit Vector3f super(n, m * 3); this.setZero(); @@ -66,7 +66,7 @@ public class Vector3fMatrix extends GMatrix { * @param n The row to insert into * @param m The column to insert into */ - public void setPosition(Vector3f settable, int n, int m) { + public void setPosition(Vector3d settable, int n, int m) { int[] position = translatePosition(n, m); n = position[0]; m = position[1]; @@ -80,16 +80,69 @@ public class Vector3fMatrix extends GMatrix { * Provides a way to get a vector from a certain position in the matrix * @param n The row to get from * @param m The column to get from - * @return Vector3f The vector in that position + * @return Vector3d The vector in that position */ - public Vector3f getPosition(int n, int m) { + public Vector3d getPosition(int n, int m) { int[] position = translatePosition(n, m); n = position[0]; m = position[1]; - float x = (float) this.getElement(n, m); - float y = (float) this.getElement(n, m + 1); - float z = (float) this.getElement(n, m + 2); - return new Vector3f(x, y, z); + double x = this.getElement(n, m); + double y = this.getElement(n, m + 1); + double z = this.getElement(n, m + 2); + return new Vector3d(x, y, z); + } + + /** + * Provides a way to calculate the result vector of a certain row + * @param row The row to calculate the total of + * @return Vector3d + */ + public Vector3d getRowTotal(int row) { + double[] rowTotal = new double[this.getNumCol()]; + this.getRow(row, rowTotal); + + // Create an empty vector to store the result + Vector3d resultVector = new Vector3d(0,0,0); + + for(int i = 0; i < this.getNumCol(); i = i + 3) { + // For every third entry (including 0). + double x = this.getElement(row, i); + double y = this.getElement(row, i + 1); + double z = this.getElement(row, i + 2); + resultVector.add(new Vector3d(x, y, z)); + } + + System.out.println(resultVector); + return resultVector; + } + + /** + * Provides a way to calculate the result vector of a certain column + * @param column The column to calculate the total of + * @return Vector3d + */ + public Vector3d getColumnTotal(int column) { + double[] columnTotal = new double[this.getNumRow()]; + + // Translate the column number to the correct vector column + int[] position = translatePosition(0, column); + column = position[1]; + + this.getColumn(column, columnTotal); + + // Create an empty vector to store the result + Vector3d resultVector = new Vector3d(0,0,0); + + for(int i = 0; i < this.getNumRow(); i++) { + // For every entry (including 0). + double x = this.getElement(i, column); + double y = this.getElement(i, column + 1); + double z = this.getElement(i, column + 2); + resultVector.add(new Vector3d(x, y, z)); + } + + System.out.println(resultVector); + return resultVector; } } \ No newline at end of file