Not working
This commit is contained in:
@ -1,8 +1,80 @@
|
||||
import codedraw.CodeDraw;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class Simulation {
|
||||
|
||||
// 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 = 2 * AU; // the size of the square region in space
|
||||
public static final int NUMBER_OF_BODIES = 22;
|
||||
public static final double OVERALL_SYSTEM_MASS = 20 * SUN_MASS; // kilograms
|
||||
|
||||
public static void main(String[] args) {
|
||||
//TODO: please use this class to run your simulation
|
||||
CodeDraw cd = new CodeDraw();
|
||||
Body[] bodies = new Body[NUMBER_OF_BODIES];
|
||||
|
||||
Random random = new Random(2022);
|
||||
|
||||
for (int i = 0; i < Simulation.NUMBER_OF_BODIES; i++) {
|
||||
bodies[i] = new Body(
|
||||
Math.abs(random.nextGaussian()) * Simulation.OVERALL_SYSTEM_MASS / Simulation.NUMBER_OF_BODIES,
|
||||
new Vector(
|
||||
0.2 * random.nextGaussian() * Simulation.AU,
|
||||
0.2 * random.nextGaussian() * Simulation.AU,
|
||||
0.2 * random.nextGaussian() * Simulation.AU
|
||||
),
|
||||
new Vector(
|
||||
0 + random.nextGaussian() * 5e3,
|
||||
0 + random.nextGaussian() * 5e3,
|
||||
0 + random.nextGaussian() * 5e3
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
long seconds = 0;
|
||||
while (true) {
|
||||
seconds++;
|
||||
|
||||
/*
|
||||
BodyLinkedList mergedBodies = new BodyLinkedList();
|
||||
for (Body b1 : bodies) {
|
||||
BodyLinkedList colliding = bodies.removeCollidingWith(b1);
|
||||
for (Body b2 : colliding) {
|
||||
b1 = b1.merge(b2);
|
||||
}
|
||||
mergedBodies.addLast(b1);
|
||||
}
|
||||
bodies = mergedBodies;
|
||||
*/
|
||||
Octree octree = new Octree(new Vector(AU), SECTION_SIZE);
|
||||
for (Body body : bodies) {
|
||||
octree.add(body);
|
||||
}
|
||||
octree.applyForces(bodies, 1);
|
||||
|
||||
if ((seconds % 3600) == 0) {
|
||||
cd.clear(Color.BLACK);
|
||||
for (Body body : bodies) {
|
||||
body.draw(cd);
|
||||
}
|
||||
cd.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user