Specific force layout code question

22 views
Skip to first unread message

Johnathan Mercer

unread,
May 24, 2013, 11:10:18 PM5/24/13
to d3...@googlegroups.com

I tried to post this on stackoverflow but someone suggested it is too specific? 

Does anyone know the reason for this random perturbation on line 5529 of the d3 source code?

  if (!quad.leaf) {
    quad.point.x += Math.random() - .5;
    quad.point.y += Math.random() - .5;
  }

Thanks!

Ger Hobbelt

unread,
May 26, 2013, 5:21:02 AM5/26/13
to D3 mailing list
comment says:
// jitter internal nodes that are coincident

Short:
 it's a bit of jitter to make sure forces are not zeroed by distances being nil.

Long:
IIRC from my days messing with force layout internals, the +/ 0.5 px jitter is an attempt to help prevent glitches in the force estimate calculation due to nodes otherwise possibly getting sticky when they are sitting right on top of each other: the jitter causes some human-invisible movement (as it's less than a pixel), which you may think of a kind of basic Brownian motion, so that point.x/.y distances have little chance to be exactly zero: /that/ zero would cancel the repulsion force between two nodes which are /very/ close (= sit on top of each other) and we don't want that, so the random is used to move them apart a wee bit with very high probability.

This is off the top of my skull, so you better verify what I'm saying ;-) 
Cop out: I haven't looked at Mike's code / mine is slightly different so what goes for him doesn't always go for me and vice-versa (I use an adapted Barnes-Hut, for one).



Met vriendelijke groeten / Best regards,

Ger Hobbelt

--------------------------------------------------
web:    http://www.hobbelt.com/
        http://www.hebbut.net/
mail:   g...@hobbelt.com
mobile: +31-6-11 120 978
--------------------------------------------------


--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages