4

Suppose you have two straight line of length $L_1$ and $L_2$, and a point is chosen at random along each line.

What is the expected distance between these points?

This question is a complement of Average Distance Between Random Points on a Line Segment.

Best regards!

tortue
  • 2,223
  • 1
    Do we know anything about this two straight lines segment (like if they are subsets of $\mathbb{R}^n$ for some $n$)? Also do you mean Uniformly distributed right? – JayTuma Aug 10 '18 at 09:55
  • 1
    These lines are R^n for n = 2. I have the lines coordinates of start and end. Yes, uniformly distributed. – Wagner Wolff Aug 10 '18 at 10:28
  • This can be set up easily as a double integral, but I doubt there's any simplification in the general case. – Connor Harris Aug 10 '18 at 14:31
  • You don't specify the orientation of the two lines. See this for one particular orientation: https://math.stackexchange.com/questions/2505978/pdf-of-the-distance-between-two-points-on-a-rectangle – Dean Aug 10 '18 at 18:06
  • Is the expected value of the distance squared of any interest? Things simplify quite nicely in that case. For the expected value of distance, the problem becomes an integral of the square root of a quadratic form over a rectangle in $\mathbb R^2$, which could perhaps be evaluated with some effort. – Kajelad Aug 10 '18 at 22:28
  • I would like an expression for all cases, is it possible? Lines intercepted, overlayed (same direction and contrary) and non-overlayed. – Wagner Wolff Aug 12 '18 at 14:56

1 Answers1

1

I'll refer to the endpoints of each line as $\vec a_1, \vec b_1$ and $\vec a_2, \vec b_2$ for lines $1$ and $2$. To parameterize them, I'll use vectors $\vec u$ and $\vec v$. $$ \vec u_1=\frac{\vec a_1+\vec b_1}{2},\ \ \ \vec v_1=\frac{\vec a_1-\vec b_1}{2} \\ \vec u_2=\frac{\vec a_2+\vec b_2}{2},\ \ \ \vec v_2=\frac{\vec a_2-\vec b_2}{2} $$ Then, we can define the lines themselves as: $$ L_1=\{\vec u_1+t_1\vec v_1:\ t_1\in[-1,1]\} \\ L_2=\{\vec u_2+t_2\vec v_2:\ t_2\in[-1,1]\} $$ A uniform probability distribution would have a value of $\frac 12$ for all $t$. We can find the expected distance squared with the following integral: $$ \langle d^2\rangle=\frac 14\int_{-1}^1\int_{-1}^1||(\vec u_1+t_1\vec v_1)-(\vec u_2+t_2\vec v_2)||^2dt_1dt_2 $$ regrouping terms: $$ \langle d^2\rangle=\frac 14\int_{-1}^1\int_{-1}^1||(\vec u_1-\vec u_2)+t_1\vec v_1-t_2\vec v_2||^2 dt_1dt_2 $$ When we distribute the dot products, we obtain a quadratic function of $t_1$ and $t_2$ with the following coefficients: $$ A=||\vec u_1-\vec u_2||^2 \\ B_1=2\vec v_1\cdot(\vec u_1-\vec u_2),\ \ \ B_2=-2\vec v_2\cdot(\vec u_1-\vec u_2) \\ C_1=||\vec v_1||^2,\ \ \ C_2=||\vec v_2||^2,\ \ \ C_3=-2\vec v_1\cdot\vec v_2 \\ $$ Rewriting the integral: $$ \langle d^2\rangle=\frac 14\int_{-1}^1\int_{-1}^1\left(A+B_1t_1+B_2t_2+C_1t_1^2+C_2t_2^2+C_3t_1t_2\right)dt_1dt_2 $$ Here, all the terms containing an odd power of $t_1$ or $t_2$ vanish by symmetry, which leaves us with a compact result. $$ \tag{1} \langle d^2\rangle=A+\frac 13(C_1+C_2)=||\vec u_1-\vec u_2||^2+\frac 13\left(||\vec v_1||^2+||\vec v_2||^2\right) $$ The square root of this quantity, the RMS disntance, is a slightly different measure of the "typical" distance between points. If we want to compute the true expected value of distance, then the resulting integral permits no such simplifications. $$ \tag{2} \langle d\rangle=\frac 14\int_{-1}^1\int_{-1}^1\sqrt{A+B_1t_1+B_2t_2+C_1t_1^2+C_2t_2^2+C_3t_1t_2}\ dt_1dt_2 $$ It's quite possible that this expression can be coerced into some kind of elliptic integral, but I doubt there is a simple way to do so.

Kajelad
  • 14,951
  • Hi, Kajelad thanks for your answer! Is this solution can be employed for all situations (different lengths, directions, locations, overlayed, cross-crossed)? – Wagner Wolff Aug 16 '18 at 13:03
  • This way of stating the problem makes no assumptions about length, orientation, crossings, etc. Both the rms and expected difference are well behaved in every case. – Kajelad Aug 16 '18 at 21:11
  • I compared this result with the overlayed situation where the expected mean is equal $\dfrac{L}{3}$ and got different results. Following the exemple in R language: ` – Wagner Wolff Aug 17 '18 at 15:47
  • 1
    There was a typo in the coefficients. After fixing it, the resulting integral for that example is $$\frac L8\int_{-1}^1\int_{-1}^1\sqrt{t_1^2+t_2^2-2t_1t_2}\ dt_1dt_2$$, giving the correct result of $\langle d\rangle = \frac L3$. – Kajelad Aug 17 '18 at 16:42
  • Something is wrong with root square. It is not calculating the integral. The result is only correct when I remove it. $$\dfrac{L}{8}\int_{-1}^1\int_{-1}^1t_1^2+t_2^2-2t_1t_2dt_1dt_2$$ I would like an expression with $L_1+L_2$ instead of $L$. I appreciate your help!! – Wagner Wolff Aug 17 '18 at 20:21
  • That integral has the same value in this special case, but it isn't the proper way to calculate $\langle d\rangle$. The square root integral will give the correct result in every case. – Kajelad Aug 17 '18 at 20:59
  • Yes, now it works for me, but I would like a general solution for all situations. – Wagner Wolff Aug 17 '18 at 23:23
  • By the way, what was the typo? Maybe a correction on it, we could find the solution. – Wagner Wolff Aug 18 '18 at 09:10
  • $B_1$, $B_2$, and $C_3$ were missing factors of $2$. Also, the integral $(2)$ is the general solution, but it is unlikely to have a closed form. If a simple closed form is more important than the particular averaging procedure used, the RMS distance might be worth considering instead. – Kajelad Aug 19 '18 at 16:27
  • Ok very nice! Comparing the results obtained by the integral (2) (solved numerically), with Monte Carlo simulations. I got the following conclusions. When the lines don't overlay the results obtained by integral (2) are similar to the simulation. On the other hand, when there is an overlay situation the integral (2) doesn't converge numerically. However, the solution is known, being $d=\dfrac{L}{3}$ or $d=\dfrac{L}{8}\int^1_{−1}\int^1_{−1}\sqrt{t_1^2+t_2^2−2t_1t_2}dt_1dt_2$. Now, my problem seems to be solved thanks a lot!!! – Wagner Wolff Aug 20 '18 at 12:20
  • Hi Kajelad Could you explain me how do you find $\frac{L}{8}$? It is the situation when the lines are overlayed. Thanks in advance! – Wagner Wolff Aug 23 '18 at 16:22
  • 1
    Using $\vec v_1$, $\vec v_2$ chosen to be parallel, you get $A=B_1=B_2=0$, $C_1=C_2=L^2/4$, and $C_3=-L^2/2$. Plugging these in gives: $$ \langle d\rangle=\frac 14\int_{-1}^1\int_{-1}^1\sqrt{\frac{L^2}{4}t_1^2+\frac{L^2}{4}t_2^2-\frac{L^2}{2}t_1 t_2}\ \ dt_1dt_2 $$ The $L^2/4$ can be factored out of the square root. – Kajelad Aug 23 '18 at 19:13
  • 1
    Also, if you're having issues with numerics, it might be sufficient to take the absolute value of the argument of the square root. Numerical error could cause this to be negative near a crossing, but otherwise the function is well-behaved. – Kajelad Aug 23 '18 at 19:18