Is There A Simple Equation For Calculating The Average Distance Between One Point In A Grid And Every Other Point?

181 Views Asked by At

Say I have a rectangle/square grid made out of smaller squares; each square is 1 'unit' by 1 'unit' in size. The grid is "w" squares wide and "h" squares tall.

Now, let's say that I want to write, in every single square, the average of the distances between it's own center, and the center of every other square in the grid.

Say, for any given square, we refer to it's position as being "x" on the horizontal, and "y" on the vertical.

Knowing the values "w", "h", "x" and "y", is there an equation that can allow me to quickly calculate the average distance to all the other squares? Or do I need to manually calculate every distance and then just average out the sum?

Even if someone could offer an equation that wasn't dead accurate, but good for rough estimates, I'd appreciate it.

Edit: At the moment, my best running theory is to average out the distances on each axis between the point and the edges of the grid. i.e.

$a = \frac{(\frac{x^2}{2} + \frac{(w-x)^2}{2})}{w}$

$b = \frac{(\frac{y^2}{2} + \frac{(h-y)^2}{2})}{h}$

...and then calculate the hypotenuse for those averages, to get the overall grid average I'm looking for. Not sure if it holds up in practice, though.