2 Commits

Author SHA1 Message Date
4e81f4b3cd Übungstest 7 2022-06-09 14:40:49 +02:00
0259be8338 Last fixes 2022-06-07 22:27:26 +02:00
2 changed files with 30 additions and 14 deletions

View File

@ -51,6 +51,12 @@ public class Octree {
if (root == null) return;
root.draw(cd);
}
public int getNumberOfBalancedRegions() {
if (root == null || !(root instanceof OctreeNode r)) return 0;
return r.getNumberOfBalancedRegions();
}
}
abstract class OctreeItem {
@ -149,6 +155,26 @@ class OctreeNode extends OctreeItem {
((octNum & 4) != 0) ? -1 : 1)
.times(this.size / 4));
}
private boolean isBalanced() {
for (OctreeItem i : children) {
if (!(i instanceof OctreeLeaf))
return false;
}
return true;
}
protected int getNumberOfBalancedRegions() {
if (isBalanced()) return 1;
int c = 0;
for (OctreeItem i : children) {
if (i instanceof OctreeNode n) {
c += n.getNumberOfBalancedRegions();
}
}
return c;
}
}
class OctreeLeaf extends OctreeItem {

View File

@ -22,8 +22,8 @@ public class Simulation {
// 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 = 220;
public static final double OVERALL_SYSTEM_MASS = 20 * SUN_MASS; // kilograms
public static final int NUMBER_OF_BODIES = 10000;
public static final double OVERALL_SYSTEM_MASS = 2000 * SUN_MASS; // kilograms
public static void main(String[] args) {
CodeDraw cd = new CodeDraw();
@ -51,22 +51,12 @@ public class Simulation {
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(0, 0, 0), SECTION_SIZE);
for (Body body : bodies) {
octree.add(body);
}
octree.applyForces(bodies, 1);
System.out.println(octree.getNumberOfBalancedRegions());
octree.applyForces(bodies, 100);
if ((seconds % 60) == 0) {
cd.clear(Color.BLACK);