in reply to Re: Data visualisation.
in thread Data visualisation.

iteratively scoot the points

I searched CPAN & google for a "scoot"ing algorithm without luck.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Data visualisation.
by Anonymous Monk on Jan 02, 2014 at 23:48 UTC

    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.

      Heh. That's not a technical term.

      (I kinda knew that :)

      The trick is choosing a good time step $dt.

      So...you're solving a simultaneous equation for each point? (I'm guessing?)

      Is that necessary? Cannot The law of cosines be combined with Sine function to derive the cartesian coordinates of a 3rd point given its vector lengths from two other points with known coordinates?

      This is what I've been trying, but I think the signed-ness malarkey of trig functions beyond π/2 is screwing me up :(


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        All that trigonometry gets a bit brittle, since the distances don't seem to lie in a plane, exactly. The plan is to consider the system as a network of springs, and try to jiggle them into a position where they aren't under too much stress. So I'm calculating the "force" each "spring" would apply to each point, and scooting each point a little bit in the direction that the springs are pushing it. Do that over and over, and hopefully the positions will gradually get closer to a reasonable solution. (I should have said it that way to start with...)

        BrowserUk:

        Yeah, the signedness is screwing me up, too. I've found a bug in my code, so I'm working up a better test for it. Hopefully I can get it nailed down tonight or tomorrow morning and post a better version.

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.