Thread: Rail deserts
View Single Post
  #27   Report Post  
Old November 3rd 07, 05:44 AM posted to uk.transport.london
Tim Woodall Tim Woodall is offline
external usenet poster
 
First recorded activity at LondonBanter: Aug 2006
Posts: 112
Default Rail deserts

On Sat, 3 Nov 2007 01:24:15 +0100,
Jarle H Knudsen wrote:
On Thu, 1 Nov 2007 17:26:38 +0000, Clive D. W. Feather wrote:

In article , Jarle H Knudsen
writes
1 for each grid cell
2 best := infinity
3 for each station on the list
4 d := (distance from station to cell) squared
5 if d best then best := d
6 cell value := sqrt (best)

Why does the distance need to be squared in line 4?


What is the formula for distance between two points on a Cartesian grid?


d = sqrt((x2 - x1)^2 + (y2 - y1)^2).

But that does not explain (to me) why you do d^2 in line 4.

It's an optimization. You only have to calculate a square root once per
cell.

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/