}
protected void recurseRepulsion(Cell cell, Vector3 delta) {
LinLog box = (LinLog) this.box;
boolean is3D = box.is3D();
Energies energies = box.getEnergies();
int deg = neighbours.size();
if (intersection(cell)) {
if (cell.isLeaf()) {
Iterator<? extends Particle> i = cell.getParticles();
while (i.hasNext()) {
LinLogNodeParticle node = (LinLogNodeParticle) i.next();
if (node != this) {
delta.set(node.pos.x - pos.x, node.pos.y - pos.y, is3D ? node.pos.z
- pos.z : 0);
//double len = delta.normalize();
double len = delta.length();
if (len > 0) {
double degFactor = box.edgeBased ? deg * node.neighbours.size() : 1;
double factor = 1;
double r = box.r;
factor = -degFactor * (Math.pow(len, r-2)) * node.weight * weight * box.rFactor;
if(factor < -box.maxR) { factor = -box.maxR; }
energies.accumulateEnergy(factor); // TODO check this
delta.scalarMult(factor);
disp.add(delta);
repE += factor;
}
}
}
} else {
int div = cell.getSpace().getDivisions();
for (int i = 0; i < div; i++)
recurseRepulsion(cell.getSub(i), delta);
}
} else {
if (cell != this.cell) {
GraphCellData bary = (GraphCellData) cell.getData();
double dist = bary.distanceFrom(pos);
double size = cell.getSpace().getSize();
if ((!cell.isLeaf())
&& ((size / dist) > box.getBarnesHutTheta())) {
int div = cell.getSpace().getDivisions();
for (int i = 0; i < div; i++)
recurseRepulsion(cell.getSub(i), delta);
} else {
if (bary.weight != 0) {
delta.set(bary.center.x - pos.x, bary.center.y - pos.y,
is3D ? bary.center.z - pos.z : 0);
//double len = delta.normalize();
double len = delta.length();
if (len > 0) {
double degFactor = box.edgeBased ? deg * bary.degree : 1;
double factor = 1;
double r = box.r;
factor = -degFactor * (Math.pow(len, r-2)) * bary.weight * weight * box.rFactor;
if(factor < -box.maxR) { factor = -box.maxR; }
energies.accumulateEnergy(factor); // TODO check this
delta.scalarMult(factor);
disp.add(delta);
repE += factor;
}
}