in reply to Re^2: Data visualisation.
in thread Data visualisation.
Heh. That's not a technical term. You can do something like this:
for $i (0 .. $npts-1) { for $j ($i+1 .. $npts-1) { $dx = $x[$j] - $x[$i]; $dy = $y[$j] - $y[$i]; $d = sqrt($dx*$dx + $dy*$dy); $f = $d - $distance[$i][$j]; $fx[$i] += $f * $dx / $d; $fy[$i] += $f * $dy / $d; $fx[$j] -= $f * $dx / $d; $fy[$j] -= $f * $dy / $d; } }
That gives you the x and y components of the total "force" on each point. Then you can update the positions.
for $i (0 .. $npts-1) { $x[$i] += $dt * $fx[$i]; $y[$i] += $dt * $fy[$i]; }
The trick is choosing a good time step $dt. Too small and it will converge very slowly. Too high and it will rattle around and never settle down. (You might want to look at the forces before choosing a time step, which is why I've put the update in a separate loop.) This kind of thing is sensitive to initial conditions and doesn't always converge well, so you may need to fiddle around with it to get it to work.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Data visualisation.
by BrowserUk (Patriarch) on Jan 03, 2014 at 00:08 UTC | |
by Anonymous Monk on Jan 03, 2014 at 02:30 UTC | |
by BrowserUk (Patriarch) on Jan 03, 2014 at 11:21 UTC | |
by roboticus (Chancellor) on Jan 03, 2014 at 00:57 UTC |