1
0
mirror of https://github.com/christiaangoossens/Planetary-Orbit-Simulator synced 2025-07-02 01:40:47 +00:00

First tests with java maths

This commit is contained in:
2016-07-05 14:49:37 +02:00
parent 9c56112d05
commit 0deca8ffbe
8 changed files with 473 additions and 19 deletions

View File

@ -1,8 +1,16 @@
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(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));
System.out.println(object1.toString());
System.out.println(object2.toString());
System.out.println(object1.getForceOnObject(object2));
}
}

View File

@ -0,0 +1,41 @@
package com.verictas.pos.simulator;
import javax.vecmath.*;
import java.lang.*;
public class Object {
public double mass;
public Vector3f position;
public Vector3f speed;
private double gravitationalConstant = 6.67384E-11;
public Object(double mass, Vector3f position, Vector3f speed) {
this.mass = mass;
this.position = position;
this.speed = speed;
}
public void setSpeed(Vector3f speed) {
this.speed = speed;
}
public void setPosition(Vector3f position) {
this.position = position;
}
public String toString() {
return "Mass: " + this.mass + " & Position: " + this.position + " & Speed: " + this.speed;
}
public Vector3f 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);
return force;
}
private Vector3f getDistance(Object secondObject) {
Vector3f distance = new Vector3f(0,0,0); // Empty
distance.sub(this.position, secondObject.position);
return distance;
}
}