Created Matrix Logic
parent
0deca8ffbe
commit
21b1b02854
@ -0,0 +1,9 @@
|
||||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="simulator:jar">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/simulator_jar</output-path>
|
||||
<root id="archive" name="simulator.jar">
|
||||
<element id="module-output" name="simulator" />
|
||||
<element id="extracted-dir" path="$PROJECT_DIR$/vecmath-1.5.2.jar" path-in-jar="/" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
@ -0,0 +1,3 @@
|
||||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="Christiaan" />
|
||||
</component>
|
@ -1,7 +1,7 @@
|
||||
<component name="libraryTable">
|
||||
<library name="vecmath-1.5.1">
|
||||
<library name="vecmath-1.5.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/" />
|
||||
<root url="jar://$PROJECT_DIR$/vecmath-1.5.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
@ -0,0 +1,124 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Palette2">
|
||||
<group name="Swing">
|
||||
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
|
||||
</item>
|
||||
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
|
||||
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
|
||||
<initial-values>
|
||||
<property name="text" value="Button" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="RadioButton" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="CheckBox" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
|
||||
<initial-values>
|
||||
<property name="text" value="Label" />
|
||||
</initial-values>
|
||||
</item>
|
||||
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
|
||||
<preferred-size width="150" height="-1" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
|
||||
<preferred-size width="150" height="50" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||
<preferred-size width="200" height="200" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
|
||||
</item>
|
||||
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
|
||||
<preferred-size width="-1" height="20" />
|
||||
</default-constraints>
|
||||
</item>
|
||||
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
|
||||
</item>
|
||||
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
|
||||
</item>
|
||||
</group>
|
||||
</component>
|
||||
</project>
|
@ -0,0 +1,2 @@
|
||||
java -jar simulator.jar
|
||||
pause
|
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.verictas.pos.simulator.Main
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.verictas.pos.simulator.Main
|
||||
|
@ -1,16 +1,19 @@
|
||||
package com.verictas.pos.simulator;
|
||||
|
||||
import javax.vecmath.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Hello World!");
|
||||
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(10E8, new Vector3f(1,2,3), new Vector3f(0,4,3));
|
||||
Object object2 = new Object(20E4, new Vector3f(2,38,2), new Vector3f(3,4,5));
|
||||
// Make a list of all the objects
|
||||
Object[] objects = {object1, object2, object3, object4};
|
||||
|
||||
System.out.println(object1.toString());
|
||||
System.out.println(object2.toString());
|
||||
System.out.println(object1.getForceOnObject(object2));
|
||||
// Start the simulation
|
||||
Simulator.run(2, objects);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.verictas.pos.simulator;
|
||||
import javax.vecmath.*;
|
||||
import com.verictas.pos.simulator.mathUtils.Vector3fMatrix;
|
||||
|
||||
public class Simulator {
|
||||
public static void run(int rounds, Object[] objects) {
|
||||
|
||||
/**
|
||||
* Log a debug message to the console to signal the simulation has started
|
||||
*/
|
||||
System.out.println("========== Simulation Started ==========\n");
|
||||
|
||||
/**
|
||||
* Start the rounds loop
|
||||
*/
|
||||
for(int t = 0; t < rounds; t++) {
|
||||
/**
|
||||
* The round has started
|
||||
*/
|
||||
System.out.println("Round " + (t + 1) + " started!");
|
||||
|
||||
/**
|
||||
* Define the forces matrix for this round
|
||||
*/
|
||||
Vector3fMatrix matrix = new Vector3fMatrix(objects.length,objects.length);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Vector3f 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the matrix for this round
|
||||
*/
|
||||
System.out.println("\n");
|
||||
System.out.println(matrix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log that the simulation has finished
|
||||
*/
|
||||
System.out.println("========== Simulation Finished ==========");
|
||||
}
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package com.verictas.pos.simulator.mathUtils;
|
||||
|
||||
import javax.vecmath.GMatrix;
|
||||
import javax.vecmath.Vector3f;
|
||||
|
||||
public class Vector3fMatrix 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) {
|
||||
// Change the size to suit Vector3f
|
||||
super(n, m * 3);
|
||||
this.setZero();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of the matrix in the amount of vectors (e.g. a 1 x 3 vector matrix gets converted to a 1 x 9 storage matrix).
|
||||
* @param n The amount of rows
|
||||
* @param m The amount of columns expressed in vectors (1 vector = 3 values).
|
||||
*/
|
||||
public void setSizeInVectors(int n, int m) {
|
||||
this.setSize(n, m * 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a function for putting the matrix into String form for visualisation.
|
||||
* @return String
|
||||
*/
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer(this.getNumRow() * this.getNumCol() * 8);
|
||||
|
||||
for(int n = 0; n < this.getNumRow(); ++n) {
|
||||
for(int m = 0; m < this.getNumCol(); ++m) {
|
||||
if ((m + 1) == 1 || m % 3 == 0) {
|
||||
// If m is 1 or a multiple of 4, begin the bracket.
|
||||
buffer.append("(").append(this.getElement(n, m)).append(", ");
|
||||
} else if ((m + 1) % 3 == 0) {
|
||||
// If m is a multiple of 3, close the bracket
|
||||
buffer.append(this.getElement(n, m)).append(")\t\t");
|
||||
} else {
|
||||
buffer.append(this.getElement(n, m)).append(", ");
|
||||
}
|
||||
}
|
||||
|
||||
buffer.append("\n");
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a translator from the vector positions (e.g. the second vector starts at position 1) to the matrix positions (the second vector starts at position 3).
|
||||
* @param n The vector positions row
|
||||
* @param m The vector positions column
|
||||
* @return void
|
||||
*/
|
||||
private int[] translatePosition(int n, int m) {
|
||||
return new int[]{n, m * 3};
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a way to set a vector into a certain position in the matrix
|
||||
* @param settable The vector you want to put in the matrix
|
||||
* @param n The row to insert into
|
||||
* @param m The column to insert into
|
||||
*/
|
||||
public void setPosition(Vector3f settable, int n, int m) {
|
||||
int[] position = translatePosition(n, m);
|
||||
n = position[0];
|
||||
m = position[1];
|
||||
|
||||
this.setElement(n, m, settable.x);
|
||||
this.setElement(n, m + 1, settable.y);
|
||||
this.setElement(n, m + 2, settable.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public Vector3f 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);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue