Skip to content

Commit

Permalink
collide is aware of fixed positions of the nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
rioj7 authored Dec 30, 2023
1 parent c3e73cf commit c3fece0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/collide.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export default function(radius) {
ri,
ri2;

// Remove effect of other forces on fixed positions.
for (i = 0; i < n; ++i) {
node = nodes[i];
if (node.fx !== null) node.vx = 0;
if (node.fy !== null) node.vy = 0;
}

for (var k = 0; k < iterations; ++k) {
tree = quadtree(nodes, x, y).visitAfter(prepare);
for (i = 0; i < n; ++i) {
Expand All @@ -50,10 +57,14 @@ export default function(radius) {
if (x === 0) x = jiggle(random), l += x * x;
if (y === 0) y = jiggle(random), l += y * y;
l = (r - (l = Math.sqrt(l))) / l * strength;
node.vx += (x *= l) * (r = (rj *= rj) / (ri2 + rj));
node.vy += (y *= l) * r;
data.vx -= x * (r = 1 - r);
data.vy -= y * r;
x *= l
y *= l
r = (rj *= rj) / (ri2 + rj)
if (node.fx == null) node.vx += x * r;
if (node.fy == null) node.vy += y * r;
r = 1 - r
if (data.fx == null) data.vx -= x * r;
if (data.fy == null) data.vy -= y * r;
}
}
return;
Expand Down

0 comments on commit c3fece0

Please sign in to comment.