On Mon, 29 Oct 2007 11:04:56 +0000,
Clive D. W. Feather wrote:
In article , Tom
Anderson writes
I'm trying to figure out how to program a computer to find these
automatically.
The approach I've taken in the past is very simple. Start with a grid
representing the entire area (to make it easy, say 1000 x 1000 with one
unit on the grid being 100 metres). Set up a list of locations of all
the stations. Then:
for each grid cell
best := infinity
for each station on the list
d := (distance from station to cell) squared
if d best then best := d
cell value := sqrt (best)
You can optimize things slightly by using a lookup table for the square
roots rather than calculating them each time.
I'd have thought a more useful optimization would be:
If D(x,y) = x^2 + y^2
then D(x+1, y) = D(x, y) + 2x + 1
D(x, y+1) = D(x, y) + 2y + 1
D(x-1, y) = D(x, y) - 2x + 1
D(x, y-1) = D(x, y) - 2y + 1
But optimizing without profiling is generally a complete disaster and
you've done this before but I haven't. ;-)
Tim.
--
God said, "div D = rho, div B = 0, curl E = - @B/@t, curl H = J + @D/@t,"
and there was light.
http://tjw.hn.org/ http://www.locofungus.btinternet.co.uk/