1
0
mirror of https://github.com/christiaangoossens/Planetary-Orbit-Simulator synced 2024-11-24 20:04:09 +00:00

Moved from Vector3f to Vector3d for precision + total calculations

This commit is contained in:
Christiaan Goossens 2016-07-07 08:39:29 +02:00
parent 21b1b02854
commit 215455f768
11 changed files with 183 additions and 110 deletions

View File

@ -30,8 +30,8 @@
<file leaf-file-name="Main.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<state relative-caret-position="102">
<caret line="6" column="44" selection-start-line="6" selection-start-column="44" selection-end-line="6" selection-end-column="44" />
<folding />
</state>
</provider>
@ -40,8 +40,8 @@
<file leaf-file-name="Simulator.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="595">
<caret line="35" column="30" selection-start-line="35" selection-start-column="30" selection-end-line="35" selection-end-column="30" />
<state relative-caret-position="501">
<caret line="55" column="39" selection-start-line="55" selection-start-column="39" selection-end-line="55" selection-end-column="39" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -52,8 +52,8 @@
<file leaf-file-name="Object.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="340">
<caret line="20" column="5" selection-start-line="20" selection-start-column="5" selection-end-line="20" selection-end-column="5" />
<state relative-caret-position="518">
<caret line="61" column="23" selection-start-line="61" selection-start-column="23" selection-end-line="61" selection-end-column="23" />
<folding>
<element signature="imports" expanded="true" />
</folding>
@ -61,17 +61,13 @@
</provider>
</entry>
</file>
<file leaf-file-name="Vector3fMatrix.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java">
<file leaf-file-name="Vector3dMatrix.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1028">
<caret line="74" column="46" selection-start-line="74" selection-start-column="46" selection-end-line="74" selection-end-column="46" />
<state relative-caret-position="-323">
<caret line="5" column="45" selection-start-line="5" selection-start-column="45" selection-end-line="5" selection-end-column="45" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#810#811#0" expanded="true" />
<element signature="e#848#849#0" expanded="true" />
<element signature="e#2148#2149#0" expanded="true" />
<element signature="e#2190#2191#0" expanded="true" />
</folding>
</state>
</provider>
@ -100,10 +96,11 @@
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Matrix.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Vector3fMatrix.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/MatrixPosition.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java" />
<option value="$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java" />
</list>
</option>
</component>
@ -154,6 +151,8 @@
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="Scratches" />
<pane id="ProjectPane">
<subPane>
<PATH>
@ -203,12 +202,36 @@
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="src" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="simulator" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="mathUtils" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
@ -481,7 +504,7 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="false" />
<editor active="true" />
<layout>
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
@ -489,9 +512,10 @@
<window_info id="Palette&#9;" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Documentation" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="FLOATING" visible="false" show_stripe_button="true" weight="0.48125" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" x="1312" y="663" width="586" height="345" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.17124736" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.17124736" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Designer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
@ -504,9 +528,8 @@
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Documentation" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="FLOATING" visible="false" show_stripe_button="true" weight="0.48125" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" x="1312" y="663" width="586" height="345" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
@ -532,6 +555,44 @@
<option name="FILTER_TARGETS" value="false" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="578">
<caret line="35" column="30" selection-start-line="35" selection-start-column="30" selection-end-line="35" selection-end-column="30" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1173">
<caret line="74" column="46" selection-start-line="74" selection-start-column="46" selection-end-line="74" selection-end-column="46" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
@ -550,14 +611,7 @@
</state>
</provider>
</entry>
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Tuple3f.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2074">
<caret line="129" column="22" selection-start-line="129" selection-start-column="22" selection-end-line="129" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Tuple3f.class" />
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="0">
@ -569,85 +623,51 @@
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Math.java" />
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/utils/Maths.java" />
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/utils/Math.java" />
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Tuple3f.class">
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Tuple3f.class" />
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Matrix.java" />
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/GMatrix.class" />
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Vector3f.class" />
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/MatrixPosition.java" />
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.2.jar!/javax/vecmath/GMatrix.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="129" column="22" selection-start-line="129" selection-start-column="22" selection-end-line="129" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Matrix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="374">
<caret line="22" column="1" selection-start-line="3" selection-start-column="28" selection-end-line="22" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/GMatrix.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="200">
<caret line="1010" column="8" selection-start-line="1010" selection-start-column="8" selection-end-line="1020" selection-end-column="31" />
<folding />
</state>
</provider>
</entry>
<entry file="jar://$PROJECT_DIR$/vecmath-1.5.1.jar!/javax/vecmath/Vector3f.class">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="51">
<caret line="15" column="11" selection-start-line="15" selection-start-column="11" selection-end-line="15" selection-end-column="11" />
<folding>
<element signature="e#436#437#0" expanded="true" />
<element signature="e#475#476#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/MatrixPosition.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="15" selection-start-line="9" selection-start-column="15" selection-end-line="9" selection-end-column="15" />
<state relative-caret-position="-1275">
<caret line="21" column="12" selection-start-line="21" selection-start-column="8" selection-end-line="21" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="323">
<caret line="19" column="0" selection-start-line="19" selection-start-column="0" selection-end-line="19" selection-end-column="0" />
<state relative-caret-position="102">
<caret line="6" column="44" selection-start-line="6" selection-start-column="44" selection-end-line="6" selection-end-column="44" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Simulator.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="595">
<caret line="35" column="30" selection-start-line="35" selection-start-column="30" selection-end-line="35" selection-end-column="30" />
<state relative-caret-position="501">
<caret line="55" column="39" selection-start-line="55" selection-start-column="39" selection-end-line="55" selection-end-column="39" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3fMatrix.java">
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/mathUtils/Vector3dMatrix.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1028">
<caret line="74" column="46" selection-start-line="74" selection-start-column="46" selection-end-line="74" selection-end-column="46" />
<state relative-caret-position="-323">
<caret line="5" column="45" selection-start-line="5" selection-start-column="45" selection-end-line="5" selection-end-column="45" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#810#811#0" expanded="true" />
<element signature="e#848#849#0" expanded="true" />
<element signature="e#2148#2149#0" expanded="true" />
<element signature="e#2190#2191#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/verictas/pos/simulator/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="340">
<caret line="20" column="5" selection-start-line="20" selection-start-column="5" selection-end-line="20" selection-end-column="5" />
<state relative-caret-position="518">
<caret line="61" column="23" selection-start-line="61" selection-start-column="23" selection-end-line="61" selection-end-column="23" />
<folding>
<element signature="imports" expanded="true" />
</folding>

View File

@ -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};

View File

@ -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;
}

View File

@ -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);

View File

@ -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;
}
}