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!

  • 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 at 9: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 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 at 14:31
  • You don't specify the orientation of the two lines. See this for one particular orientation: math.stackexchange.com/questions/2505978/… – Dean Aug 10 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 at 22:28
up vote 1 down vote accepted

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.

  • 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 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 at 21:11
  • 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 at 16:42
  • 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 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 at 19:18

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.