Module

Hylograph.Forces.ThreeD.Tick

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

The parts of a tick that are not forces, in three dimensions: moving the nodes, and d3-force-3d's initializeNodes. Cooling has no dimension and is Hylograph.Forces.Tick.cool.

Ported from d3-force-3d 3.0.6, simulation.js (MIT, Copyright 2017 Vasco Asturiano; itself from d3-force, ISC, Mike Bostock); see LICENSE.

#integrate Source

integrate :: forall row. Number -> Array (Node (Pinnable row)) -> Effect Unit

d3-force-3d's position update, after the forces of a tick, each axis on its own:

if (node.fx == null) node.x += node.vx *= velocityDecay;
else node.x = node.fx, node.vx = 0;

and the same for y and z.

#initializeNodes Source

initializeNodes :: forall row. Array (Node (Pinnable row)) -> Effect Unit

d3-force-3d's initializeNodes at three dimensions: give every node its index; put a pinned coordinate on its pin; give a node with no position a place on d3-force-3d's spherical spiral; and stop a node with no velocity.

node.index = i;
if (node.fx != null) node.x = node.fx;
if (node.fy != null) node.y = node.fy;
if (node.fz != null) node.z = node.fz;
if (isNaN(node.x) || isNaN(node.y) || isNaN(node.z)) {
  var radius = initialRadius * Math.cbrt(0.5 + i),
      rollAngle = i * initialAngleRoll,
      yawAngle = i * initialAngleYaw;
  node.x = radius * Math.sin(rollAngle) * Math.cos(yawAngle);
  node.y = radius * Math.cos(rollAngle);
  node.z = radius * Math.sin(rollAngle) * Math.sin(yawAngle);
}
if (isNaN(node.vx) || isNaN(node.vy) || isNaN(node.vz)) node.vx = node.vy = node.vz = 0;

A node with no position is placed whole: a node pinned in x alone, and nowhere yet, loses its pin's x to the spiral (and gets it back at the first tick), as in d3-force-3d. A field that is missing reads as NaN.

#initialAngleRoll Source

initialAngleRoll :: Number

d3-force-3d's initialAngleRoll, the golden angle: a value of its own, for the reason given at Hylograph.Forces.Tick.initializeNodes (the optimising backend would regroup i * (pi * k)).

#initialAngleYaw Source

initialAngleYaw :: Number

d3-force-3d's initialAngleYaw, Math.PI * 20 / (9 + Math.sqrt(221)).