I'm interested in the mean distance between an arbitrary 2D point, $(p, q)$, and a uniformly distributed point inside a rectangle defined by the lower left and upper right vertices $(x_0, y_0)$ and $(x_1, y_1)$, respectively. There is no constraint that $(p,q)$ need lie within the rectangle.
I figure the solution is given by
$$ \int\limits_{y_0}^{y_1}\int\limits_{x_0}^{x_1} \left[(x-p)^2 + (y-q)^2 \right]^{1/2} \text{d}x\text{d}y, $$
which my basic knowledge of calculus prevents from tackling in any way other than numerically. I'm not expecting a closed analytic solution (though it would be great!), but are there any tricks that might help approximate it? And more generally, does this type of integral have a name that would help me look up methods associated with its solution?
Also happy to settle for the assumption that $(p,q)$ lies outside the rectangle.
Thanks all.
In principle the integral is not too difficult using polar coordinates. I will do everything for $x_0=-x_1 ,y_0 =- y_1$ and $p=q=0$ to simplify notation a little bit. Then we don't have to shift and the whole area is given by $4$ times the integral over the first quadrant. We split the remaining integral in two regions.
1.) The triangle with vertices $\{0,0\} ,\{x_1,0\},\{x_1,y_1\}$. Here the upper bound of $r$ goes from $x_1$ to $r_1=\sqrt{x_1^2+y_1^2}$ which means that $r\in [0,\frac{x_1}{\cos(\phi)}]$. The value of $\phi$ is between $0$ and $\phi_1=\arctan(y_1/x_1)$
2.) The triangle with vertices $\{0,0\} ,\{0,y_1\},\{x_1,y_1\}$. Here the upper bound of $r$ goes from $y_1$ to $r_1=\sqrt{x_1^2+y_1^2}$ which means that $r\in [0,\frac{y_1}{\sin(\phi)}]$. The value of $\phi$ is between $\phi_1=\arctan(y_1/x_1)$ and $\pi/2$
We get: $$ \int_{-y_1}^{y_1}\int_{-x_1}^{x_1} dx dy\sqrt{x^2+y^2}=4\int_{0}^{y_1}\int_{0}^{x_1} dx dy\sqrt{x^2+y^2}=\\ 4\int_{0}^{\phi_1}d\phi\int_{0}^{x_1/\cos(\phi_1)}dr r^2+4\int_{\phi_1}^{\pi/2}d\phi\int_{0}^{y_1/\sin(\phi_1)}dr r^2=\\ \frac{4}{3}x_1^3\int_{0}^{\phi_1}d\phi \left(\frac{1}{\cos(\phi)}\right)^3+\frac{4}{3}y_1^3\int_{\phi_1}^{\pi/2}d\phi\left(\frac{1}{\sin(\phi)}\right)^3 $$
The remaining integrals can be done by IBP and the substitutions $y=\arccos{\phi}$ , $y=\arcsin{\phi}$ respectivly.
The result in the end can be simplified a bit but looks still very messy, so i spare it here. But eventually you get a closed form :)
Can you take it from here?