Finish AB4
This commit is contained in:
@ -8,41 +8,36 @@ public class Aufgabe4Test {
|
|||||||
private NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2;
|
private NamedBodyForcePair sun2, mercury2, venus2, earth2, moon2, mars2, deimos2, phobos2, vesta2, pallas2, hygiea2, ceres2;
|
||||||
|
|
||||||
public void resetBodies() {
|
public void resetBodies() {
|
||||||
sun2 = new NamedBodyForcePair(SolSystem4.SUN);
|
sun2 = new NamedBodyForcePair(SolSystem4.SUN_NAMED);
|
||||||
earth2 = new NamedBodyForcePair(SolSystem4.EARTH);
|
earth2 = new NamedBodyForcePair(SolSystem4.EARTH_NAMED);
|
||||||
moon2 = new NamedBodyForcePair(SolSystem4.MOON);
|
moon2 = new NamedBodyForcePair(SolSystem4.MOON_NAMED);
|
||||||
mars2 = new NamedBodyForcePair(SolSystem4.MARS);
|
mars2 = new NamedBodyForcePair(SolSystem4.MARS_NAMED);
|
||||||
deimos2 = new NamedBodyForcePair(SolSystem4.DEIMOS);
|
deimos2 = new NamedBodyForcePair(SolSystem4.DEIMOS_NAMED);
|
||||||
phobos2 = new NamedBodyForcePair(SolSystem4.PHOBOS);
|
phobos2 = new NamedBodyForcePair(SolSystem4.PHOBOS_NAMED);
|
||||||
mercury2 = new NamedBodyForcePair(SolSystem4.MERCURY);
|
mercury2 = new NamedBodyForcePair(SolSystem4.MERCURY_NAMED);
|
||||||
venus2 = new NamedBodyForcePair(SolSystem4.VENUS);
|
venus2 = new NamedBodyForcePair(SolSystem4.VENUS_NAMED);
|
||||||
vesta2 = new NamedBodyForcePair(SolSystem4.VESTA);
|
vesta2 = new NamedBodyForcePair(SolSystem4.VESTA_NAMED);
|
||||||
pallas2 = new NamedBodyForcePair(SolSystem4.PALLAS);
|
pallas2 = new NamedBodyForcePair(SolSystem4.PALLAS_NAMED);
|
||||||
hygiea2 = new NamedBodyForcePair(SolSystem4.HYGIEA);
|
hygiea2 = new NamedBodyForcePair(SolSystem4.HYGIEA_NAMED);
|
||||||
ceres2 = new NamedBodyForcePair(SolSystem4.CERES);
|
ceres2 = new NamedBodyForcePair(SolSystem4.CERES_NAMED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEP2() {
|
public void testEP2() {
|
||||||
assertEquals(2, 3);
|
|
||||||
//TODO: uncomment for testing
|
|
||||||
/*
|
|
||||||
//test classes HierarchicalSystem and NamedBodyForcePair
|
//test classes HierarchicalSystem and NamedBodyForcePair
|
||||||
|
|
||||||
// create 12 bodies
|
Body sun1 = new Body(SolSystem4.SUN);
|
||||||
Body sun1, earth1, moon1, mars1, deimos1, phobos1, mercury1, venus1, vesta1, pallas1, hygiea1, ceres1;
|
Body earth1 = new Body(SolSystem4.EARTH);
|
||||||
sun1 = new Body(1.989E30, new Vector3(0.0, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0));
|
Body moon1 = new Body(SolSystem4.MOON);
|
||||||
earth1 = new Body(5.972E24, new Vector3(-6.13135922534815E10, -1.383789852227691E11, 2.719682263474911E7), new Vector3(26832.720535473603, -11948.23168764519, 1.9948243075997851));
|
Body mars1 = new Body(SolSystem4.MARS);
|
||||||
moon1 = new Body(7.349E22, new Vector3(-6.132484773775896E10, -1.387394951280871E11, 1.701046736294776E7), new Vector3(27916.62329282941, -12020.39526008238, -94.89703264508708));
|
Body deimos1 = new Body(SolSystem4.DEIMOS);
|
||||||
mars1 = new Body(6.41712E23, new Vector3(-1.7923193702925848E11, 1.726665823982123E11, 7.991673845249474E9), new Vector3(-15925.78496403673, -15381.16179928219, 68.67560910598857));
|
Body phobos1 = new Body(SolSystem4.PHOBOS);
|
||||||
deimos1 = new Body(1.8E20, new Vector3(-1.792255010450533E11, 1.726891122683271E11, 7.990659337380297E9), new Vector3(-17100.476719804457, -15020.348656808, 631.2927851249581));
|
Body mercury1 = new Body(SolSystem4.MERCURY);
|
||||||
phobos1 = new Body(1.08E20, new Vector3(-1.792253482539647E11, 1.72661109673625E11, 7.987848354800322E9), new Vector3(-14738.203714241401, -13671.17675223948, -411.0012490555253));
|
Body venus1 = new Body(SolSystem4.VENUS);
|
||||||
mercury1 = new Body(3.301E23, new Vector3(-5.167375560011926E10, -4.217574885682655E10, 1.14808913958168E9), new Vector3(21580.25398577148, -34951.03632847389, -4835.225596525241));
|
Body vesta1 = new Body(SolSystem4.VESTA);
|
||||||
venus1 = new Body(4.86747E24, new Vector3(-3.123150865740532E10, 1.0395568504115701E11, 3.173401325838074E9), new Vector3(-33748.180519629335, -10014.25141045021, 1809.94488874165));
|
Body pallas1 = new Body(SolSystem4.PALLAS);
|
||||||
vesta1 = new Body(2.5908E20, new Vector3(-3.337493557929893E11, -4.7147908276077385E10, 4.1923010146878105E10), new Vector3(4440.54247538484, -19718.49074006637, 48.06573124543601));
|
Body hygiea1 = new Body(SolSystem4.HYGIEA);
|
||||||
pallas1 = new Body(2.14E20, new Vector3(4.3452066613895575E11, -2.057319365171432E11, 1.0549957423213101E11), new Vector3(5058.947582097117, 11184.45711782372, -8183.524138259704));
|
Body ceres1 = new Body(SolSystem4.CERES);
|
||||||
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};
|
Body[] bodies = new Body[]{sun1, mercury1, venus1, earth1, moon1, mars1, deimos1, phobos1, vesta1, pallas1, hygiea1, ceres1};
|
||||||
Vector3[] forceOnBody = new Vector3[bodies.length];
|
Vector3[] forceOnBody = new Vector3[bodies.length];
|
||||||
@ -57,6 +52,7 @@ public class Aufgabe4Test {
|
|||||||
assertEquals(2, earthSystem.numberOfBodies());
|
assertEquals(2, earthSystem.numberOfBodies());
|
||||||
assertEquals(12, solarSystem.numberOfBodies());
|
assertEquals(12, solarSystem.numberOfBodies());
|
||||||
|
|
||||||
|
System.out.println(solarSystem);
|
||||||
assertTrue(solarSystem.toString().contains("Mars"));
|
assertTrue(solarSystem.toString().contains("Mars"));
|
||||||
assertTrue(solarSystem.toString().contains("Deimos"));
|
assertTrue(solarSystem.toString().contains("Deimos"));
|
||||||
assertTrue(solarSystem.toString().contains("Moon"));
|
assertTrue(solarSystem.toString().contains("Moon"));
|
||||||
@ -110,6 +106,5 @@ public class Aufgabe4Test {
|
|||||||
for (int i = 0; i < bodies.length; i++) {
|
for (int i = 0; i < bodies.length; i++) {
|
||||||
assertEquals(0, bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()));
|
assertEquals(0, bodies[i].massCenter().distanceTo(pairs[i].getMassCenter()));
|
||||||
}
|
}
|
||||||
*/ //TODO: uncomment
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,10 @@ public class Body {
|
|||||||
* Hint: see simulation loop in Simulation.java to find out how this is done.
|
* Hint: see simulation loop in Simulation.java to find out how this is done.
|
||||||
*/
|
*/
|
||||||
public Vector3 gravitationalForce(Body b) {
|
public Vector3 gravitationalForce(Body b) {
|
||||||
|
if (b == this) return new Vector3();
|
||||||
Vector3 direction = b.massCenter.minus(massCenter);
|
Vector3 direction = b.massCenter.minus(massCenter);
|
||||||
double distance = direction.length();
|
double distance = direction.length();
|
||||||
|
if (distance == 0) return new Vector3();
|
||||||
direction.normalize();
|
direction.normalize();
|
||||||
double force = Simulation.G * mass * b.mass / (distance * distance);
|
double force = Simulation.G * mass * b.mass / (distance * distance);
|
||||||
return direction.times(force);
|
return direction.times(force);
|
||||||
@ -76,6 +78,10 @@ public class Body {
|
|||||||
return mass;
|
return mass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vector3 massCenter() {
|
||||||
|
return massCenter;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean collidesWith(Body body) {
|
public boolean collidesWith(Body body) {
|
||||||
return this.distanceTo(body) < this.radius() + body.radius();
|
return this.distanceTo(body) < this.radius() + body.radius();
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,113 @@
|
|||||||
|
import codedraw.CodeDraw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair')
|
* A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair')
|
||||||
* and an arbitrary number of subsystems (of type 'CosmicSystem') in its orbit.
|
* and an arbitrary number of subsystems (of type 'CosmicSystem') in its orbit.
|
||||||
* This class implements 'CosmicSystem'.
|
* This class implements 'CosmicSystem'.
|
||||||
*/
|
*/
|
||||||
public class HierarchicalSystem /* TODO: add clause */ {
|
public class HierarchicalSystem implements CosmicSystem {
|
||||||
|
|
||||||
// TODO: define missing parts of this class.
|
private final NamedBodyForcePair central;
|
||||||
|
private final CosmicSystem[] orbit;
|
||||||
|
private final CosmicSystem[] all;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this system with a name and a central body.
|
* Initializes this system with a name and a central body.
|
||||||
*/
|
*/
|
||||||
public HierarchicalSystem(NamedBodyForcePair central, CosmicSystem... inOrbit) {
|
public HierarchicalSystem(NamedBodyForcePair central, CosmicSystem... inOrbit) {
|
||||||
// TODO: implement constructor.
|
this.central = central;
|
||||||
|
this.orbit = inOrbit;
|
||||||
|
this.all = new CosmicSystem[this.orbit.length + 1];
|
||||||
|
this.all[0] = central;
|
||||||
|
System.arraycopy(this.orbit, 0, this.all, 1, this.orbit.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector3 getMassCenter() {
|
||||||
|
double mass = this.getMass();
|
||||||
|
Vector3 massCenter = new Vector3();
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
massCenter.add(sys.getMassCenter().times(sys.getMass() / mass));
|
||||||
|
}
|
||||||
|
return massCenter;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMass() {
|
||||||
|
double mass = 0;
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
mass += sys.getMass();
|
||||||
|
}
|
||||||
|
return mass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int numberOfBodies() {
|
||||||
|
int num = 0;
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
num += sys.numberOfBodies();
|
||||||
|
}
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double distanceTo(CosmicSystem cs) {
|
||||||
|
return this.getMassCenter().distanceTo(cs.getMassCenter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addForceFrom(Body b) {
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
sys.addForceFrom(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addForceTo(CosmicSystem cs) {
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
sys.addForceTo(cs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BodyLinkedList getBodies() {
|
||||||
|
BodyLinkedList list = new BodyLinkedList();
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
for (Body b : sys.getBodies()) {
|
||||||
|
list.addFirst(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
sys.update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(CodeDraw cd) {
|
||||||
|
for (CosmicSystem sys : all) {
|
||||||
|
sys.draw(cd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append(central.getName());
|
||||||
|
|
||||||
|
sb.append(" {");
|
||||||
|
boolean first = true;
|
||||||
|
for (CosmicSystem sys : orbit) {
|
||||||
|
if (!first) sb.append(", ");
|
||||||
|
sb.append(sys.toString());
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
sb.append("}");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,93 @@
|
|||||||
|
import codedraw.CodeDraw;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A body with a name and an associated force. The leaf node of
|
* A body with a name and an associated force. The leaf node of
|
||||||
* a hierarchical cosmic system. This class implements 'CosmicSystem'.
|
* a hierarchical cosmic system. This class implements 'CosmicSystem'.
|
||||||
*/
|
*/
|
||||||
public class NamedBodyForcePair /* TODO: add clause */ {
|
public class NamedBodyForcePair implements CosmicSystem {
|
||||||
|
|
||||||
// TODO: define missing parts of this class.
|
private final String name;
|
||||||
|
private final Body body;
|
||||||
|
private final Vector3 force = new Vector3();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes this with name, mass, current position and movement. The associated force
|
* Initializes this with name, mass, current position and movement. The associated force
|
||||||
* is initialized with a zero vector.
|
* is initialized with a zero vector.
|
||||||
*/
|
*/
|
||||||
public NamedBodyForcePair(String name, double mass, Vector3 massCenter, Vector3 currentMovement) {
|
public NamedBodyForcePair(String name, double mass, Vector3 massCenter, Vector3 currentMovement) {
|
||||||
// TODO: implement constructor.
|
this(name, new Body(mass, massCenter, currentMovement));
|
||||||
|
}
|
||||||
|
|
||||||
|
public NamedBodyForcePair(String name, Body b) {
|
||||||
|
this.body = b;
|
||||||
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NamedBodyForcePair(NamedBodyForcePair other) {
|
public NamedBodyForcePair(NamedBodyForcePair other) {
|
||||||
// TODO
|
this(other.name, new Body(other.body));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Body getBody() {
|
||||||
|
return body;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the body.
|
* Returns the name of the body.
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// TODO: implement method.
|
return name;
|
||||||
return "";
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Vector3 getMassCenter() {
|
||||||
|
return body.massCenter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getMass() {
|
||||||
|
return body.mass();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int numberOfBodies() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double distanceTo(CosmicSystem cs) {
|
||||||
|
return getMassCenter().distanceTo(cs.getMassCenter());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addForceFrom(Body b) {
|
||||||
|
force.add(body.gravitationalForce(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addForceTo(CosmicSystem cs) {
|
||||||
|
cs.addForceFrom(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BodyLinkedList getBodies() {
|
||||||
|
BodyLinkedList list = new BodyLinkedList();
|
||||||
|
list.addFirst(body);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
body.move(force);
|
||||||
|
force.set(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void draw(CodeDraw cd) {
|
||||||
|
body.draw(cd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,47 +7,45 @@ import java.awt.*;
|
|||||||
*/
|
*/
|
||||||
public class Simulation4 {
|
public class Simulation4 {
|
||||||
|
|
||||||
// gravitational constant
|
public static final double SECTION_SIZE = 10 * Simulation.AU;
|
||||||
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.
|
* The main simulation method using instances of other classes.
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// simulation
|
|
||||||
CodeDraw cd = new CodeDraw();
|
CodeDraw cd = new CodeDraw();
|
||||||
|
|
||||||
// create solar system with 12 bodies
|
NamedBodyForcePair sun = new NamedBodyForcePair(SolSystem4.SUN_NAMED);
|
||||||
NamedBodyForcePair sun = new NamedBodyForcePair(SolSystem4.SUN);
|
NamedBodyForcePair earth = new NamedBodyForcePair(SolSystem4.EARTH_NAMED);
|
||||||
NamedBodyForcePair earth = new NamedBodyForcePair(SolSystem4.EARTH);
|
NamedBodyForcePair moon = new NamedBodyForcePair(SolSystem4.MOON_NAMED);
|
||||||
NamedBodyForcePair moon = new NamedBodyForcePair(SolSystem4.MOON);
|
NamedBodyForcePair mars = new NamedBodyForcePair(SolSystem4.MARS_NAMED);
|
||||||
NamedBodyForcePair mars = new NamedBodyForcePair(SolSystem4.MARS);
|
NamedBodyForcePair deimos = new NamedBodyForcePair(SolSystem4.DEIMOS_NAMED);
|
||||||
NamedBodyForcePair deimos = new NamedBodyForcePair(SolSystem4.DEIMOS);
|
NamedBodyForcePair phobos = new NamedBodyForcePair(SolSystem4.PHOBOS_NAMED);
|
||||||
NamedBodyForcePair phobos = new NamedBodyForcePair(SolSystem4.PHOBOS);
|
NamedBodyForcePair mercury = new NamedBodyForcePair(SolSystem4.MERCURY_NAMED);
|
||||||
NamedBodyForcePair mercury = new NamedBodyForcePair(SolSystem4.MERCURY);
|
NamedBodyForcePair venus = new NamedBodyForcePair(SolSystem4.VENUS_NAMED);
|
||||||
NamedBodyForcePair venus = new NamedBodyForcePair(SolSystem4.VENUS);
|
NamedBodyForcePair vesta = new NamedBodyForcePair(SolSystem4.VESTA_NAMED);
|
||||||
NamedBodyForcePair vesta = new NamedBodyForcePair(SolSystem4.VESTA);
|
NamedBodyForcePair pallas = new NamedBodyForcePair(SolSystem4.PALLAS_NAMED);
|
||||||
NamedBodyForcePair pallas = new NamedBodyForcePair(SolSystem4.PALLAS);
|
NamedBodyForcePair hygiea = new NamedBodyForcePair(SolSystem4.HYGIEA_NAMED);
|
||||||
NamedBodyForcePair hygiea = new NamedBodyForcePair(SolSystem4.HYGIEA);
|
NamedBodyForcePair ceres = new NamedBodyForcePair(SolSystem4.CERES_NAMED);
|
||||||
NamedBodyForcePair ceres = new NamedBodyForcePair(SolSystem4.CERES);
|
|
||||||
|
|
||||||
//TODO: implementation of this method according to 'Aufgabenblatt4.md'.
|
CosmicSystem earthSystem = new HierarchicalSystem(earth, moon);
|
||||||
|
CosmicSystem marsSystem = new HierarchicalSystem(mars, deimos, phobos);
|
||||||
|
CosmicSystem sol = new HierarchicalSystem(sun, mercury, venus, earthSystem, marsSystem, vesta, pallas, hygiea, ceres);
|
||||||
|
|
||||||
|
long seconds = 0;
|
||||||
|
while (true) {
|
||||||
|
seconds++;
|
||||||
|
|
||||||
|
for (Body b : sol.getBodies()) {
|
||||||
|
sol.addForceFrom(b);
|
||||||
|
}
|
||||||
|
sol.update();
|
||||||
|
|
||||||
|
if ((seconds % 3600) == 0) {
|
||||||
|
cd.clear(Color.BLACK);
|
||||||
|
sol.draw(cd);
|
||||||
|
cd.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,27 @@
|
|||||||
public class SolSystem4 {
|
public class SolSystem4 {
|
||||||
public static final NamedBodyForcePair SUN = new NamedBodyForcePair("Sun", 1.989E30, new Vector3(0.0, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0));
|
public static final Body SUN = new Body(1.989E30, new Vector3(0.0, 0.0, 0.0), new Vector3(0.0, 0.0, 0.0));
|
||||||
public static final NamedBodyForcePair EARTH = new NamedBodyForcePair("Earth", 5.972E24, new Vector3(-6.13135922534815E10, -1.383789852227691E11, 2.719682263474911E7), new Vector3(26832.720535473603, -11948.23168764519, 1.9948243075997851));
|
public static final Body EARTH = new Body(5.972E24, new Vector3(-6.13135922534815E10, -1.383789852227691E11, 2.719682263474911E7), new Vector3(26832.720535473603, -11948.23168764519, 1.9948243075997851));
|
||||||
public static final NamedBodyForcePair MOON = new NamedBodyForcePair("Moon", 7.349E22, new Vector3(-6.132484773775896E10, -1.387394951280871E11, 1.701046736294776E7), new Vector3(27916.62329282941, -12020.39526008238, -94.89703264508708));
|
public static final Body MOON = new Body(7.349E22, new Vector3(-6.132484773775896E10, -1.387394951280871E11, 1.701046736294776E7), new Vector3(27916.62329282941, -12020.39526008238, -94.89703264508708));
|
||||||
public static final NamedBodyForcePair MARS = new NamedBodyForcePair("Mars", 6.41712E23, new Vector3(-1.7923193702925848E11, 1.726665823982123E11, 7.991673845249474E9), new Vector3(-15925.78496403673, -15381.16179928219, 68.67560910598857));
|
public static final Body MARS = new Body(6.41712E23, new Vector3(-1.7923193702925848E11, 1.726665823982123E11, 7.991673845249474E9), new Vector3(-15925.78496403673, -15381.16179928219, 68.67560910598857));
|
||||||
public static final NamedBodyForcePair DEIMOS = new NamedBodyForcePair("Deimos", 1.8E20, new Vector3(-1.792255010450533E11, 1.726891122683271E11, 7.990659337380297E9), new Vector3(-17100.476719804457, -15020.348656808, 631.2927851249581));
|
public static final Body DEIMOS = new Body(1.8E20, new Vector3(-1.792255010450533E11, 1.726891122683271E11, 7.990659337380297E9), new Vector3(-17100.476719804457, -15020.348656808, 631.2927851249581));
|
||||||
public static final NamedBodyForcePair PHOBOS = new NamedBodyForcePair("Phobos", 1.08E20, new Vector3(-1.792253482539647E11, 1.72661109673625E11, 7.987848354800322E9), new Vector3(-14738.203714241401, -13671.17675223948, -411.0012490555253));
|
public static final Body PHOBOS = new Body(1.08E20, new Vector3(-1.792253482539647E11, 1.72661109673625E11, 7.987848354800322E9), new Vector3(-14738.203714241401, -13671.17675223948, -411.0012490555253));
|
||||||
public static final NamedBodyForcePair MERCURY = new NamedBodyForcePair("Mercury", 3.301E23, new Vector3(-5.167375560011926E10, -4.217574885682655E10, 1.14808913958168E9), new Vector3(21580.25398577148, -34951.03632847389, -4835.225596525241));
|
public static final Body MERCURY = new Body(3.301E23, new Vector3(-5.167375560011926E10, -4.217574885682655E10, 1.14808913958168E9), new Vector3(21580.25398577148, -34951.03632847389, -4835.225596525241));
|
||||||
public static final NamedBodyForcePair VENUS = new NamedBodyForcePair("Venus", 4.86747E24, new Vector3(-3.123150865740532E10, 1.0395568504115701E11, 3.173401325838074E9), new Vector3(-33748.180519629335, -10014.25141045021, 1809.94488874165));
|
public static final Body VENUS = new Body(4.86747E24, new Vector3(-3.123150865740532E10, 1.0395568504115701E11, 3.173401325838074E9), new Vector3(-33748.180519629335, -10014.25141045021, 1809.94488874165));
|
||||||
public static final NamedBodyForcePair VESTA = new NamedBodyForcePair("Vesta", 2.5908E20, new Vector3(-3.337493557929893E11, -4.7147908276077385E10, 4.1923010146878105E10), new Vector3(4440.54247538484, -19718.49074006637, 48.06573124543601));
|
public static final Body VESTA = new Body(2.5908E20, new Vector3(-3.337493557929893E11, -4.7147908276077385E10, 4.1923010146878105E10), new Vector3(4440.54247538484, -19718.49074006637, 48.06573124543601));
|
||||||
public static final NamedBodyForcePair PALLAS = new NamedBodyForcePair("Pallas", 2.14E20, new Vector3(4.3452066613895575E11, -2.057319365171432E11, 1.0549957423213101E11), new Vector3(5058.947582097117, 11184.45711782372, -8183.524138259704));
|
public static final Body PALLAS = new Body(2.14E20, new Vector3(4.3452066613895575E11, -2.057319365171432E11, 1.0549957423213101E11), new Vector3(5058.947582097117, 11184.45711782372, -8183.524138259704));
|
||||||
public static final NamedBodyForcePair HYGIEA = new NamedBodyForcePair("Hygiea", 8.32E19, new Vector3(-3.983943433707043E11, 2.325833000024021E11, -2.233667695713672E10), new Vector3(-6931.864585548552, -15686.8108598699, -690.5791992347208));
|
public static final Body HYGIEA = new Body(8.32E19, new Vector3(-3.983943433707043E11, 2.325833000024021E11, -2.233667695713672E10), new Vector3(-6931.864585548552, -15686.8108598699, -690.5791992347208));
|
||||||
public static final NamedBodyForcePair CERES = new NamedBodyForcePair("Ceres", 9.394E20, new Vector3(3.781372641419032E11, 1.96718960466285E11, -6.366459168068592E10), new Vector3(-8555.324226752316, 14718.33755980907, 2040.230135060142));
|
public static final Body CERES = new Body(9.394E20, new Vector3(3.781372641419032E11, 1.96718960466285E11, -6.366459168068592E10), new Vector3(-8555.324226752316, 14718.33755980907, 2040.230135060142));
|
||||||
|
|
||||||
|
public static final NamedBodyForcePair SUN_NAMED = new NamedBodyForcePair("Sun", SUN);
|
||||||
|
public static final NamedBodyForcePair EARTH_NAMED = new NamedBodyForcePair("Earth", EARTH);
|
||||||
|
public static final NamedBodyForcePair MOON_NAMED = new NamedBodyForcePair("Moon", MOON);
|
||||||
|
public static final NamedBodyForcePair MARS_NAMED = new NamedBodyForcePair("Mars", MARS);
|
||||||
|
public static final NamedBodyForcePair DEIMOS_NAMED = new NamedBodyForcePair("Deimos", DEIMOS);
|
||||||
|
public static final NamedBodyForcePair PHOBOS_NAMED = new NamedBodyForcePair("Phobos", PHOBOS);
|
||||||
|
public static final NamedBodyForcePair MERCURY_NAMED = new NamedBodyForcePair("Mercury", MERCURY);
|
||||||
|
public static final NamedBodyForcePair VENUS_NAMED = new NamedBodyForcePair("Venus", VENUS);
|
||||||
|
public static final NamedBodyForcePair VESTA_NAMED = new NamedBodyForcePair("Vesta", VESTA);
|
||||||
|
public static final NamedBodyForcePair PALLAS_NAMED = new NamedBodyForcePair("Pallas", PALLAS);
|
||||||
|
public static final NamedBodyForcePair HYGIEA_NAMED = new NamedBodyForcePair("Hygiea", HYGIEA);
|
||||||
|
public static final NamedBodyForcePair CERES_NAMED = new NamedBodyForcePair("Ceres", CERES);
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,16 @@ public class Vector3 {
|
|||||||
this(other.x, other.y, other.z);
|
this(other.x, other.y, other.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set(double v) {
|
||||||
|
set(v, v, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(double x, double y, double z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the sum of this vector and vector 'v'.
|
* Returns the sum of this vector and vector 'v'.
|
||||||
*/
|
*/
|
||||||
@ -33,6 +43,12 @@ public class Vector3 {
|
|||||||
return new Vector3(x + v.x, y + v.y, z + v.z);
|
return new Vector3(x + v.x, y + v.y, z + v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void add(Vector3 v) {
|
||||||
|
this.x += v.x;
|
||||||
|
this.y += v.y;
|
||||||
|
this.z += v.z;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the product of this vector and 'd'.
|
* Returns the product of this vector and 'd'.
|
||||||
*/
|
*/
|
||||||
@ -47,6 +63,12 @@ public class Vector3 {
|
|||||||
return new Vector3(x - v.x, y - v.y, z - v.z);
|
return new Vector3(x - v.x, y - v.y, z - v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sub(Vector3 v) {
|
||||||
|
this.x -= v.x;
|
||||||
|
this.y -= v.y;
|
||||||
|
this.z -= v.z;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Euclidean distance of this vector
|
* Returns the Euclidean distance of this vector
|
||||||
* to the specified vector 'v'.
|
* to the specified vector 'v'.
|
||||||
@ -77,11 +99,11 @@ public class Vector3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getScreenX(CodeDraw cd) {
|
public double getScreenX(CodeDraw cd) {
|
||||||
return cd.getWidth() * (this.x + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
|
return cd.getWidth() * (this.x + Simulation4.SECTION_SIZE / 2) / Simulation4.SECTION_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getScreenY(CodeDraw cd) {
|
public double getScreenY(CodeDraw cd) {
|
||||||
return cd.getWidth() * (this.y + Simulation.SECTION_SIZE / 2) / Simulation.SECTION_SIZE;
|
return cd.getWidth() * (this.y + Simulation4.SECTION_SIZE / 2) / Simulation4.SECTION_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +111,7 @@ public class Vector3 {
|
|||||||
* in the canvas associated with 'cd'. The z-coordinate is not used.
|
* in the canvas associated with 'cd'. The z-coordinate is not used.
|
||||||
*/
|
*/
|
||||||
public void drawAsFilledCircle(CodeDraw cd, double radius) {
|
public void drawAsFilledCircle(CodeDraw cd, double radius) {
|
||||||
radius = cd.getWidth() * radius / Simulation.SECTION_SIZE;
|
radius = cd.getWidth() * radius / Simulation4.SECTION_SIZE;
|
||||||
cd.fillCircle(getScreenX(cd), getScreenY(cd), Math.max(radius, 1.5));
|
cd.fillCircle(getScreenX(cd), getScreenY(cd), Math.max(radius, 1.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user