views:

332

answers:

2

Hello,

I'm trying to write a force-directed or force-atlas code base for a graphing application I'm building for myself. Here is an example of what I'm attempting: http://sawamuland.com/flash/graph.html

I managed to find some pseudo code to accomplish what I'd like on the Wiki Force-atlas article. I've converted this into ActionScript 3.0 code since it's a Flash application. Here is my source:

var timestep:int = 0;
var damping:int  = 0;
var total_kinetic_engery:int = 0;

for (var node in list) {
 var net_force:int = 0;
 for (var other_node in list) {
  net_force += coulombRepulsion(node, other_node, nodeList);
 }
 for (var spring in list[node].relations) {
  net_force += hookeAttraction(node, spring, nodeList);
 }
 list[node].velocity += (timestep * net_force) * damping;
 list[node].position += timestep * list[node].velocity;
 total_kinetic_engery += list[node].mass * (list[node].velocity) ^ 2;
}

The problem now is finding pseudo code or a function to perform the the coulomb repulsion and hooke attraction code. I'm not exactly sure how to accomplish this.

Does anyone know of a good reference I can look at...understand and implement quickly?

Best.

+1  A: 

There are links to these in the same article. Hooke's is the spring force between end-nodes of a link, while Coulomb's force repels nearby nodes away.

The question is not really the expressions, but the constants applied inside them. I would read the original article, google for "Fruchterman, T. M. J., & Reingold, E. M. (1991). Graph Drawing by Force-Directed Placement. Software: Practice and Experience, 21(11)." and read through the pdf to see what the authors suggest.

Btw, your vars may have to be floats, not integers.

ron
A: 

have you looked at flare? there is a demo with a force-directed graph.

Renaud