Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
4e81f4b3cd | |||
0259be8338
|
@ -51,6 +51,12 @@ public class Octree {
|
|||||||
if (root == null) return;
|
if (root == null) return;
|
||||||
root.draw(cd);
|
root.draw(cd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumberOfBalancedRegions() {
|
||||||
|
if (root == null || !(root instanceof OctreeNode r)) return 0;
|
||||||
|
|
||||||
|
return r.getNumberOfBalancedRegions();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class OctreeItem {
|
abstract class OctreeItem {
|
||||||
@ -149,6 +155,26 @@ class OctreeNode extends OctreeItem {
|
|||||||
((octNum & 4) != 0) ? -1 : 1)
|
((octNum & 4) != 0) ? -1 : 1)
|
||||||
.times(this.size / 4));
|
.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 {
|
class OctreeLeaf extends OctreeItem {
|
||||||
|
@ -22,8 +22,8 @@ public class Simulation {
|
|||||||
|
|
||||||
// set some system parameters
|
// set some system parameters
|
||||||
public static final double SECTION_SIZE = 2 * AU; // the size of the square region in space
|
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 int NUMBER_OF_BODIES = 10000;
|
||||||
public static final double OVERALL_SYSTEM_MASS = 20 * SUN_MASS; // kilograms
|
public static final double OVERALL_SYSTEM_MASS = 2000 * SUN_MASS; // kilograms
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
CodeDraw cd = new CodeDraw();
|
CodeDraw cd = new CodeDraw();
|
||||||
@ -51,22 +51,12 @@ public class Simulation {
|
|||||||
while (true) {
|
while (true) {
|
||||||
seconds++;
|
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);
|
Octree octree = new Octree(new Vector(0, 0, 0), SECTION_SIZE);
|
||||||
for (Body body : bodies) {
|
for (Body body : bodies) {
|
||||||
octree.add(body);
|
octree.add(body);
|
||||||
}
|
}
|
||||||
octree.applyForces(bodies, 1);
|
System.out.println(octree.getNumberOfBalancedRegions());
|
||||||
|
octree.applyForces(bodies, 100);
|
||||||
|
|
||||||
if ((seconds % 60) == 0) {
|
if ((seconds % 60) == 0) {
|
||||||
cd.clear(Color.BLACK);
|
cd.clear(Color.BLACK);
|
||||||
|
Reference in New Issue
Block a user