Aufgabenblatt 4

This commit is contained in:
Anton Ertl
2022-04-25 10:15:53 +00:00
7 changed files with 469 additions and 0 deletions

125
angabe/Aufgabenblatt4.md Normal file
View File

@ -0,0 +1,125 @@
# Aufgabenblatt 4
## Allgemeine Anmerkungen
Ihre Lösung für dieses Aufgabenblatt ist bis Montag, 2.5. 11h durch `git commit` und `push`
abzugeben. Mit der Angabe werden die Dateien `CosmicSystem.java`, `Drawable.java`,
`NamedBodyForcePair.java`, `HierarchicalSystem.java`, `Simulation4.java` und `Aufgabe4Test.java`
mitgeliefert.
Wenn Sie zusätzlich zu den gefragten Klassen weitere Klassen definieren, achten Sie darauf, dass
die Klassennamen mit `My` beginnen, um Konflikte mit späteren Aufgabenblättern zu vermeiden.
## Ziel
Ziel der Aufgabe ist die Anwendung der Konzepte: Interfaces, dynamisches Binden, toString()
(siehe Skriptum Seite 75-84).
## Beschreibung der gegebenen Dateien
- [CosmicSystem](../src/CosmicSystem.java) ist ein gegebenes Interface, das von den Klassen
`NamedBodyForcePair` und `HierarchicalSystem` implementiert wird. Mithilfe dieses lässt sich somit eine
Hierarchie von Systemen und Subsystemen beschreiben. Unser Sonnensystem ist ein Beispiel eines Systems,
das mehrere Teilsysteme beinhaltet. Ein solches Teilsystem ist beispielsweise das System Erde und Erdmond.
Ein anderes Teilsystem wäre Jupiter mit seinen Monden. Verändern Sie dieses Interface nicht.
- [Drawable](../src/Drawable.java) wird von `CosmicSystem` verwendet. Verändern Sie dieses Interface
nicht.
- [NamedBodyForcePair](../src/NamedBodyForcePair.java) ist das Gerüst für eine Klassendefinition.
Die Klasse implementiert `CosmicSystem` und repräsentiert einen einzelnen benannten Himmelskörper
(z.B. "Mars") zusammen mit der auf ihn wirkenden Kraft.
- [HierarchicalSystem](../src/HierarchicalSystem.java) ist das Gerüst für eine Klassendefinition.
Die Klasse implementiert `CosmicSystem`und repräsentiert ein System von Himmelskörpern (z.B.
Sonnensystem) bestehend aus einem zentralen Himmelskörper und beliebig vielen Untersystemen in
dessen Orbit. Für alle Himmelskörper werden die Kräfte, die auf diese jeweils wirken, mitverwaltet.
- [Simulation4](../src/Simulation4.java) ist ein Gerüst für eine ausführbare Klasse. Hier soll
die Simulation analog zur Klasse `Simulation` implementiert werden (damit Sie Ihre [ursprüngliche
Datei](../src/Simulation.java) nicht überschreiben müssen).
- [Aufgabe4Test](../src/Aufgabe4Test.java) ist eine vorgegebene Klasse, die Sie zum Testen Ihrer
Implementierung verwenden sollten. Bei einer fehlerfreien Implementierung sollten bei der
Ausführung dieser Klasse keine Exceptions geworfen werden und alle Tests als erfolgreich ("successful")
ausgegeben werden. Entfernen Sie die Kommentarzeichen, um diese Klasse verwenden zu können. Sie
müssen diese Klasse nicht weiter verändern, können aber eigene Testfälle hinzufügen.
## Aufgaben
Ihre Aufgaben sind folgende:
**1. Implementierung von `CosmicSystem` in `NamedBodyForcePair`:**
Fügen Sie in der Klasse `Body` eine öffentliche Methode `massCenter()` hinzu, die die
Position des Himmelskörpers liefert.
Definieren Sie die Klasse `NamedBodyForcePair` so, dass sie das Interface `CosmicSystem`
implementiert. Die Methoden `getMass()` und `getMassCenter()` geben lediglich die Masse bzw.
Position des Himmelskörpers zurück.
**2. Implementierung von `CosmicSystem` in `HierarchicalSystem`:**
Definieren Sie die Klasse `HierarchicalSystem` so, dass sie das Interface `CosmicSystem` implementiert.
Die Klasse repräsentiert ein hierarchisch aufgebautes kosmisches System von Himmelskörpern.
Ein solches System besteht aus einem zentralen Himmelskörper und beliebig vielen weiteren
kosmischen Systemen, die sich im Orbit um diesen zentralen Himmelskörper befinden. Neben der
Spezifikationen in `CosmicSystem` beachten Sie bitte folgende spezielle Anforderungen und Hinweise
für die Implementierung:
- `toString()`: diese Methode soll eine textuelle Beschreibung der Hierarchie von Himmelskörpern
und Subsystemen liefern. Dafür wird der Namen des zentralen Himmelskörpers eines Systems
gefolgt von den Objekten im Orbit jeweils in {}-Klammern repräsentiert. Beispiel:
`"Sun {Mercury, Venus, Earth {Moon} , Mars {Deimos, Phobos} , Vesta, Pallas, Hygiea, Ceres}"`
- `numberOfBodies()`: diese Methode liefert die Gesamtanzahl aller Himmelskörper (nicht Systeme)
im System bzw. Himmelskörper, das heißt alle Objekte vom Typ `NamedBodyForcePair`. Das oben genannte
Beispiel-System besteht z.B. aus 12 Himmelskörpern, das Mars-System im Orbit der Sonne jedoch nur
aus 3.
- `getMass()`: diese Methode liefert die Summe der Massen aller Himmelskörper im System.
- `getMassCenter()`: diese Methode liefert den Schwerpunkt aller Himmelskörper im System. Dieser
entspricht dem mit den Massen gewichteten Mittelwert aller Positionen, es müssen daher alle Positionen
mit der jeweiligen Masse multipliziert und aufsummiert werden und das Resultat durch die Summe aller
Massen dividiert werden. Nutzen Sie dafür die bereits implementierten Rechenoperationen in `Vector3`.
- `addForceFrom(Body b)` aktualisiert für jedes `NamedBodyForcePair`-Objekt in `this` die Kraft,
indem die von `b` auf das `NamedBodyForcePair`-Objekt ausgeübte Kraft zur Kraft hinzuaddiert wird.
- `addForceTo(CosmicSystem cs)` aktualisiert für jedes `NamedBodyForcePair`-Objekt in `cs` die
Kraft, indem alle Kräfte die von Körpern aus `this` auf das `NamedBodyForcePair`-Objekt
ausgeübt werden, zur Kraft im Objekt hinzuaddiert werden. Beispiel: Die
Anweisung `cs.addForce(cs)` aktualisiert alle wechselseitigen im System `cs` wirkenden Kräfte.
- `update()` führt auf Basis der gespeicherten Kräfte alle Bewegungen im System `this` durch und
setzt danach alle Kräfte wieder auf den null-Vektor zurück.
- `getBodies()` liefert eine Liste (Typ: `BodyLinkedList`) mit allen Himmelskörpern aus `this`.
**3. Implementierung von `Simulation4`:**
Implementieren Sie die Simulationsschleife unter Verwendung eines Objekts vom Typ
`HierachicalSystem`. Alle Berechnungen sollen mittels Methoden von `CosmicSystem` durchgeführt
werden.
### Hinweise: ###
- Nutzen Sie für die Implementierung dieser Methoden Rekursion sowie das Konzept des _dynamischen Bindens_.
Da `NamedBodyForcePair` und `HierarchicalSystem` Untertypen von `CosmicSystem` sind, haben sie
jeweils eine eigene Implementierung der in `CosmicSystem` definierten Methoden und es wird zur
Laufzeit entschieden, von welchem dynamischen Typ ein Objekt ist und welche Methode somit ausgeführt
wird. Sie dürfen hier keine Typumwandlungen (Casts) und auch nicht die Methoden `getClass()` und
`instanceOf()` verwenden.
- Es ist möglich, aber nicht verlangt, `addForceTo(CosmicSystem cs)` ohne Verwendung von
`getBodies()` zu implementieren. Dazu kann in `addForceTo(CosmicSystem cs)` der Zugriff auf
die eizelnen Körper in `cs` dadurch erreicht werden, dass `this` für alle seine Himmelskörper
und Untersysteme `addForceTo(cs)` aufruft. Wird beim rekursiven Abstieg ein einzelner Himmelskörper
erreicht (Blattknoten) ruft dieser `cs.addForceFrom(this)` auf.
- Achten Sie bei der Berechnung der Kräfte in `addForceFrom(Body b)` darauf, dass die Kraft nicht
verändert wird, wenn `this` und `b` derselbe Himmelskörper sind.
#### _Punkteaufteilung_
- Implementierung von `CosmicSystem` in `NamedBodyForcePair`: 1.5 Punkte
- Implementierung von `CosmicSystem` in `HierarchicalSystem`: 2.5 Punkte
- Implementierung von `Simulation4`: 1 Punkte
- Gesamt: 5 Punkte

205
src/Aufgabe4Test.java Normal file
View File

@ -0,0 +1,205 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
public class Aufgabe4Test {
public static void main(String[] args) {
//TODO: uncomment for testing
/*
//test classes HierachicalSystem and NamedBodyForcePair
// create 12 bodies
Body sun1, earth1, moon1, mars1, deimos1, phobos1, mercury1, venus1, vesta1, pallas1,
hygiea1, ceres1;
NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2,
pallas2, hygiea2, ceres2;
sun1 = new Body(1.989E30, new Vector3(0.0,0.0,0.0), new Vector3(0.0,0.0,
0.0));
earth1 = new Body(5.972E24, new Vector3(-6.13135922534815E10,-1.383789852227691E11,
2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851));
moon1 = new Body(7.349E22, new Vector3(-6.132484773775896E10,-1.387394951280871E11,
1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708));
mars1 = new Body(6.41712E23, new Vector3(-1.7923193702925848E11,1.726665823982123E11
,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857));
deimos1 = new Body(1.8E20, new Vector3(-1.792255010450533E11,1.726891122683271E11,
7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581));
phobos1 = new Body(1.08E20, new Vector3(-1.792253482539647E11,1.72661109673625E11,
7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253));
mercury1 = new Body(3.301E23, new Vector3(-5.167375560011926E10,
-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241));
venus1 = new Body(4.86747E24, new Vector3(-3.123150865740532E10,
1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165));
vesta1 = new Body(2.5908E20, new Vector3(-3.337493557929893E11,
-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601));
pallas1 = new Body(2.14E20, new Vector3(4.3452066613895575E11,-2.057319365171432E11,
1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704));
hygiea1 = new Body(8.32E19, new Vector3(-3.983943433707043E11,2.325833000024021E11,
-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208));
ceres1 = new Body(9.394E20, new Vector3(3.781372641419032E11,1.96718960466285E11,
-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142));
Body[] bodies = new Body[]{sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1,
vesta1, pallas1, hygiea1, ceres1};
Vector3[] forceOnBody = new Vector3[bodies.length];
// create the same 12 named body-force pairs
sun2 = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0)
, new Vector3(0.0,0.0,0.0));
earth2 = new NamedBodyForcePair("Earth",5.972E24,
new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851));
moon2 = new NamedBodyForcePair("Moon",7.349E22,
new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708));
mars2 = new NamedBodyForcePair("Mars",6.41712E23,
new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857));
deimos2 = new NamedBodyForcePair("Deimos",1.8E20,
new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581));
phobos2 = new NamedBodyForcePair("Phobos",1.08E20,
new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253));
mercury2 = new NamedBodyForcePair("Mercury",3.301E23,
new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241));
venus2 = new NamedBodyForcePair("Venus",4.86747E24,
new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165));
vesta2 = new NamedBodyForcePair("Vesta",2.5908E20,
new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601));
pallas2 = new NamedBodyForcePair("Pallas",2.14E20,
new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704));
hygiea2 = new NamedBodyForcePair("Hygiea",8.32E19,
new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208));
ceres2 = new NamedBodyForcePair("Ceres",9.394E20,
new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142));
NamedBodyForcePair[] pairs = new NamedBodyForcePair[] {sun2, mercury2, venus2, earth2,
moon2, mars2, deimos2, phobos2,
vesta2, pallas2, hygiea2, ceres2};
// check basic functions of 'HierachicalSystem'
System.out.println("Test1:");
CosmicSystem earthSystem = new HierarchicalSystem(earth2, moon2);
CosmicSystem marsSystem = new HierarchicalSystem(mars2, deimos2, phobos2);
CosmicSystem solarSystem = new HierarchicalSystem(sun2, mercury2, venus2, earthSystem,
marsSystem, vesta2, pallas2, hygiea2, ceres2);
testValue(earthSystem.numberOfBodies(), 2);
testValue(solarSystem.numberOfBodies(), 12);
System.out.println("Test2:");
System.out.println(solarSystem.toString());
testValue(solarSystem.toString().contains("Mars"), true);
testValue(solarSystem.toString().contains("Deimos"), true);
testValue(solarSystem.toString().contains("Moon"), true);
testValue(earthSystem.toString().contains("Moon"), true);
testValue(earthSystem.toString().contains("Earth"), true);
System.out.println("Test3:");
testValue(solarSystem.getMass(),1.9890118865556799E30);
System.out.println("Test4:");
BodyLinkedList bl = solarSystem.getBodies();
testValue(bl.size(),12);
HashSet<Body> set = new HashSet<>();
while(bl.size() > 0) {
set.add(bl.pollFirst());
}
testValue(set.size(), 12);
System.out.println("Test5:");
for (int seconds = 0; seconds < 50000; seconds++) {
// for each body (with index i): compute the total force exerted on it.
for (int i = 0; i < bodies.length; i++) {
forceOnBody[i] = new Vector3(0, 0, 0); // begin with zero
for (int j = 0; j < bodies.length; j++) {
if (i != j) {
pairs[i].addForceTo(pairs[j]);
Vector3 forceToAdd = bodies[i].gravitationalForce(bodies[j]);
forceOnBody[i] = forceOnBody[i].plus(forceToAdd);
}
}
}
// now forceOnBody[i] holds the force vector exerted on body with index i.
// for each body (with index i): move it according to the total force exerted on it.
for (int i = 0; i < bodies.length; i++) {
bodies[i].move(forceOnBody[i]);
pairs[i].update();
}
}
for (int i = 0; i < bodies.length; i++) {
testValue(bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()),0);
}
System.out.println("Test6:");
sun2 = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0)
, new Vector3(0.0,0.0,0.0));
earth2 = new NamedBodyForcePair("Earth",5.972E24,
new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851));
moon2 = new NamedBodyForcePair("Moon",7.349E22,
new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708));
mars2 = new NamedBodyForcePair("Mars",6.41712E23,
new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857));
deimos2 = new NamedBodyForcePair("Deimos",1.8E20,
new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581));
phobos2 = new NamedBodyForcePair("Phobos",1.08E20,
new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253));
mercury2 = new NamedBodyForcePair("Mercury",3.301E23,
new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241));
venus2 = new NamedBodyForcePair("Venus",4.86747E24,
new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165));
vesta2 = new NamedBodyForcePair("Vesta",2.5908E20,
new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601));
pallas2 = new NamedBodyForcePair("Pallas",2.14E20,
new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704));
hygiea2 = new NamedBodyForcePair("Hygiea",8.32E19,
new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208));
ceres2 = new NamedBodyForcePair("Ceres",9.394E20,
new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142));
pairs = new NamedBodyForcePair[] {sun2, mercury2, venus2, earth2,
moon2, mars2, deimos2, phobos2,
vesta2, pallas2, hygiea2, ceres2};
HierarchicalSystem hs = new HierarchicalSystem(sun2, mercury2, venus2,
new HierarchicalSystem(earth2, moon2), new HierarchicalSystem(mars2, deimos2,
phobos2), vesta2, pallas2, hygiea2, ceres2);
for (int seconds = 0; seconds < 50000; seconds++) {
hs.addForceTo(hs);
hs.update();
}
for (int i = 0; i < bodies.length; i++) {
testValue(bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()),0);
}
*/ //TODO: uncomment
}
public static void testComparison(Object first, Object second, boolean expected) {
boolean real = first == second;
if (real == expected) {
System.out.println("Successful comparison");
} else {
System.out.println("Comparison NOT successful! Expected value: " + expected + " / Given value: " + real);
}
}
public static void testValue(Object given, Object expected) {
if (given == expected) {
System.out.println("Successful test");
} else {
System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given);
}
}
public static void testValue(double given, double expected) {
if (given < expected + (expected + 1) / 1e12 && given > expected - (expected + 1) / 1e12) {
System.out.println("Successful test");
} else {
System.out.println("Test NOT successful! Expected value: " + expected + " / Given value: " + given);
}
}
}

41
src/CosmicSystem.java Normal file
View File

@ -0,0 +1,41 @@
// A representation of a system of bodies with associated forces. Provides methods
// for computing current mutual forces, updating the positions of bodies and drawing
// the bodies in a CodeDraw object.
//
public interface CosmicSystem extends Drawable {
// Returns a readable representation of this system.
String toString();
// Returns the mass center of this system.
Vector3 getMassCenter();
// Returns the overall mass of this system.
double getMass();
// Returns the overall number of bodies contained in this system.
int numberOfBodies();
// Returns the distance between the mass centers of 'this' and the specified system.
//Precondition: cs != null
double distanceTo(CosmicSystem cs);
// Adds the force that the specified body exerts on each of this systems bodies to each of this
// systems bodies.
// Precondition: b != null
void addForceFrom(Body b);
// Adds the force that this system exerts on each of the bodies of 'cs' to the bodies in 'cs'.
// For exact computations this means that for each body of 'this' its force on each body of
// 'cs' is added to this body of 'cs'.
// Precondition: cs != null
void addForceTo(CosmicSystem cs);
// Returns a list with all the bodies of 'this'. The order is not defined.
BodyLinkedList getBodies();
// Moves each of the bodies of 'this' according to the previously accumulated forces and
// resets all forces to zero.
void update();
}

10
src/Drawable.java Normal file
View File

@ -0,0 +1,10 @@
import codedraw.CodeDraw;
// An object that can be drawn in a CodeDraw canvas.
//
public interface Drawable {
//draws the object into the canvas 'cd'
//Precondition: cd != null
void draw(CodeDraw cd);
}

View File

@ -0,0 +1,14 @@
// A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair')
// and an arbitrary number of subsystems (of type 'HierarchicalSystem') in its orbit.
// This class implements 'CosmicSystem'.
//
public class HierarchicalSystem /* TODO: add clause */ {
// TODO: define missing parts of this class.
// Initializes this system with a name and a central body.
public HierarchicalSystem(NamedBodyForcePair central, CosmicSystem... inOrbit) {
// TODO: implement constructor.
}
}

View File

@ -0,0 +1,21 @@
// A body with a name and an associated force. The leaf node of
// a hierarchical cosmic system. This class implements 'CosmicSystem'.
//
public class NamedBodyForcePair /* TODO: add clause */ {
// TODO: define missing parts of this class.
// Initializes this with name, mass, current position and movement. The associated force
// is initialized with a zero vector.
public NamedBodyForcePair(String name, double mass, Vector3 massCenter, Vector3 currentMovement) {
// TODO: implement constructor.
}
// Returns the name of the body.
public String getName() {
// TODO: implement method.
return "";
}
}

53
src/Simulation4.java Normal file
View File

@ -0,0 +1,53 @@
import codedraw.CodeDraw;
import java.awt.*;
// Simulates the formation of a massive solar system.
//
public class Simulation4 {
// gravitational constant
public static final double G = 6.6743e-11;
// one astronomical unit (AU) is the average distance of earth to the sun.
public static final double AU = 150e9; // meters
// one light year
public static final double LY = 9.461e15; // meters
// some further constants needed in the simulation
public static final double SUN_MASS = 1.989e30; // kilograms
public static final double SUN_RADIUS = 696340e3; // meters
public static final double EARTH_MASS = 5.972e24; // kilograms
public static final double EARTH_RADIUS = 6371e3; // meters
// set some system parameters
public static final double SECTION_SIZE = 10 * AU; // the size of the square region in space
// all quantities are based on units of kilogram respectively second and meter.
// The main simulation method using instances of other classes.
public static void main(String[] args) {
// simulation
CodeDraw cd = new CodeDraw();
// create solar system with 12 bodies
NamedBodyForcePair sun = new NamedBodyForcePair("Sun",1.989E30, new Vector3(0.0,0.0,0.0), new Vector3(0.0,0.0,0.0));
NamedBodyForcePair earth = new NamedBodyForcePair("Earth",5.972E24, new Vector3(-6.13135922534815E10,-1.383789852227691E11,2.719682263474911E7), new Vector3(26832.720535473603,-11948.23168764519,1.9948243075997851));
NamedBodyForcePair moon = new NamedBodyForcePair("Moon",7.349E22, new Vector3(-6.132484773775896E10,-1.387394951280871E11,1.701046736294776E7), new Vector3(27916.62329282941,-12020.39526008238,-94.89703264508708));
NamedBodyForcePair mars = new NamedBodyForcePair("Mars",6.41712E23, new Vector3(-1.7923193702925848E11,1.726665823982123E11,7.991673845249474E9), new Vector3(-15925.78496403673,-15381.16179928219,68.67560910598857));
NamedBodyForcePair deimos = new NamedBodyForcePair("Deimos",1.8E20, new Vector3(-1.792255010450533E11,1.726891122683271E11,7.990659337380297E9), new Vector3(-17100.476719804457,-15020.348656808,631.2927851249581));
NamedBodyForcePair phobos = new NamedBodyForcePair("Phobos",1.08E20, new Vector3(-1.792253482539647E11,1.72661109673625E11,7.987848354800322E9), new Vector3(-14738.203714241401,-13671.17675223948,-411.0012490555253));
NamedBodyForcePair mercury = new NamedBodyForcePair("Mercury",3.301E23, new Vector3(-5.167375560011926E10,-4.217574885682655E10,1.14808913958168E9), new Vector3(21580.25398577148,-34951.03632847389,-4835.225596525241));
NamedBodyForcePair venus = new NamedBodyForcePair("Venus",4.86747E24, new Vector3(-3.123150865740532E10,1.0395568504115701E11,3.173401325838074E9), new Vector3(-33748.180519629335,-10014.25141045021,1809.94488874165));
NamedBodyForcePair vesta = new NamedBodyForcePair("Vesta",2.5908E20, new Vector3(-3.337493557929893E11,-4.7147908276077385E10,4.1923010146878105E10), new Vector3(4440.54247538484,-19718.49074006637,48.06573124543601));
NamedBodyForcePair pallas = new NamedBodyForcePair("Pallas",2.14E20, new Vector3(4.3452066613895575E11,-2.057319365171432E11,1.0549957423213101E11), new Vector3(5058.947582097117,11184.45711782372,-8183.524138259704));
NamedBodyForcePair hygiea = new NamedBodyForcePair("Hygiea",8.32E19, new Vector3(-3.983943433707043E11,2.325833000024021E11,-2.233667695713672E10), new Vector3(-6931.864585548552,-15686.8108598699,-690.5791992347208));
NamedBodyForcePair ceres = new NamedBodyForcePair("Ceres",9.394E20, new Vector3(3.781372641419032E11,1.96718960466285E11,-6.366459168068592E10), new Vector3(-8555.324226752316,14718.33755980907,2040.230135060142));
//TODO: implementation of this method according to 'Aufgabenblatt4.md'.
}
}