An ambulance travels back and forth, at a constant speed, along a road of length $L$. At a certain moment of time an accident occurs at a point uniformly distributed on the road. [That is, its distance from one of the fixed ends of the road is uniformly distributed over $(0, L)$.] Assuming that the ambulance's location at the moment of the accident is also uniformly distributed, compute, assuming the independence, the distribution of its distance from the accident. I get the following:
$$\int\int_{|Y-X|\le a} \frac{1}{L^2} $$
However, I am stuck on trying to find the bounds for the next step.
$$\int\int_{-a\le Y-X\le a} \frac{1}{L^2}$$
I know I get $X-a\le Y\le X+a$ for the bounds of $Y$. But I am confused of how I should find the bounds for $X$?
The problem is that $X-a$ need not be negative and $X+a$ need not be bigger than $L$. We will need to split the integral to consider those possibilities and write the bounds of $Y$ accordingly. Two cases will appear, $a<\frac L2$ and $a>\frac L2$
Case $a<\frac L2$
Here is a visual representation of the region we need to integrate to.
We will split the integral in three parts
$$\int\int_{|Y-X|\le a} \frac{1}{L^2}dydx = \int_0^a\int_0^{X+a} \frac{1}{L^2} dydx + \int_a^{L-a}\int_{X-a}^{X+a} \frac{1}{L^2} dydx + \int_{L-a}^L\int_{X-a}^{L} \frac{1}{L^2} dydx$$
A bit of algebra give $2aL-a^2$
Case $a>\frac L2$
Here is a visual representation of the region we need to integrate to.
Here, $a$ is bigger than $L-a$. We will still split the integral in three parts, but it will be a bit different.
$$\int\int_{|Y-X|\le a} \frac{1}{L^2}dydx = \int_0^{L-a}\int_0^{X+a} \frac{1}{L^2} dydx + \int_{L-a}^{a}\int_{0}^{L} \frac{1}{L^2} dydx + \int_{a}^L\int_{X-a}^{L} \frac{1}{L^2} dydx$$
Surprisingly, this gives exactly the same answer : $2aL-a^2$.
In conclusion : $$P(\lvert X-Y\rvert \leq a) = 2aL-a^2$$
Since the position is uniformly distributed, it is a lot simplier to evaluate the area of each region. It is a square minus two triangles and both cases are the same. $$L^2 - 2\times \frac{(L-a)^2}{2} = 2aL - a^2$$