Module

Hylograph.Forces.ThreeD.ManyBody

Package
purescript-hylograph-forces
Repository
afcondon/purescript-hylograph-forces

The many-body force in three dimensions: every node attracts or repels every other, with the far field approximated by Barnes-Hut over an octree.

Ported from d3-force-3d 3.0.6, manyBody.js (MIT, Copyright 2017 Vasco Asturiano; itself from d3-force, ISC, Mike Bostock); see LICENSE. The shape is Hylograph.Forces.ManyBody's: build the tree, turn it into a chain of clusters in d3's visiting order, walk the chain once per node.

Where d3-force-3d is more than d3-force with a third coordinate, in accumulate:

  • the summed strength of a cube with octants is scaled by Math.sqrt(4 / 8) ("according to number of dimensions"), at every level of the tree, so a far cluster pulls with a fraction of its nodes' strength that shrinks with its depth from the leaves; and
  • a child's centre is read as q.x || 0 (zero where it is NaN).

#Config Source

type Config :: Row Type -> Typetype Config row = { distanceMax :: Number, distanceMin :: Number, strength :: Node row -> Number, theta :: Number }

forceManyBody settings. strength is asked once per node when the force is initialized; negative repels.

#defaultConfig Source

defaultConfig :: forall row. Config row

d3's defaults: strength -30, theta 0.9, distances from 1 to infinity.

#ManyBody Source

newtype ManyBody :: Row Type -> Typenewtype ManyBody row

An initialized many-body force.

#initialize Source

initialize :: forall row. Config row -> Source -> Array (Node row) -> ManyBody row

force.initialize(nodes, random, 3). A node's index is its place in the array, which is what the simulation sets node.index to.

#apply Source

apply :: forall row. ManyBody row -> Number -> Effect Unit

force(alpha): add the many-body acceleration to every node's velocity.