# Finding distribution of $y$ intercept given by line generated by two uniformly chosen points in $[0,1]^2$

The method I'm using seems super inefficient. What I did was define $$4$$ RVs namely $$X_1,X_2,Y_1,Y_2$$ and thus my two uniformly random points are $$(X_1,Y_1),(X_2,Y_2)$$ and hence the $$y$$ intercept is $$-X_1(Y_2-Y_1)/(X_2-X_1)+Y_1$$ but them I'll have to do Jacobian tranform multiple times.

Is there any simpler method I seem to be missing?

• You might find it easier to find the CDF for the intercept. Note that distribution is symmetric about $\frac12$. Empirically, it seems uniform between $0$ and $1$ – Henry Jun 12 at 8:16
• @henry Wait $y$ intercept would have the whole real line as range no? and not just between $0$ and $1$ – Anvit Jun 12 at 8:18
• @Henry: it can't be uniform(0,1) since it is easy to cook up examples of negative $y$-intercepts – user10354138 Jun 12 at 8:18
• @user10354138 The range is the whole axis. What I was saying was that empirically, within this the density seems to be constant between $0$ and $1$ (i.e. uniform in this part). I think the density overall looks like a flat top mountain – Henry Jun 12 at 13:26
• Empirically the density appears to be $1/2$ on $[0, 1]$. – Michael Lugo Jun 12 at 17:05

I'd approach this by first computing the conditional cdf of the slope given one point $$(X_1,Y_1)$$, hence the conditional cdf of the $$y$$-intercept and integrate to get the unconditioned cdf. It still requires some integration and separation into cases but it looks more approachable this way, because the conditional cdf is just really areas of triangles and similar shapes.

Partial answer: Proofs that (A) $$y$$-intercept $$\in [0,1]$$ with probability $$\frac12$$, and (B) it is uniform within $$[0,1]$$.

For shorthand, write $$E=$$ the event that $$y$$-intercept $$\in [0,1]$$.

Easy proof of (A): Given any two points $$P_1, P_2 \in [0,1]^2$$, the line $$L$$ through them hits a corner of the square with probability $$0$$. Therefore, $$L$$ passes through exactly two sides of the square with probability $$1$$. Now rotate the square by $$90^\circ, 180^\circ, 270^\circ$$. The $$4$$ rotations are symmetric, and of the four lines exactly two of them passes through the left side of the square, i.e. has $$y$$-intercept $$\in [0,1]$$. Thus $$P(E) = \frac12$$.

Harder proof of (A) and (B): Let $$W = \max(X_1, X_2) =$$ the $$x$$-coordinate of the point that is further to the right. We call this point $$P$$ and the other point $$Q$$. Conditioned on $$W=w$$, the point $$Q$$ is uniform in the rectangle $$R$$ with corners $$(0,0), (0,1), (w,0), (w,1)$$, i.e. the rectangle to the left of $$x=w$$. Meanwhile, the $$y$$-intercept $$\in [0,1]$$ iff $$Q$$ lies in the triangle $$T$$ formed by $$P, (0,0), (0,1)$$. This triangle $$T$$ is exactly $$\frac12$$ of rectangle $$R$$, so the conditional probability $$P(E \mid W=w) = P(Q\in T \mid Q \in R) = \frac12$$. Since this is true for any $$w$$, the unconditioned probability $$P(E)$$ is also $$\frac12$$, regardless of the distribution of $$W$$.

More generally, the $$y$$-intercept $$\in [0, c]$$ (where $$c\le 1$$) iff $$Q \in$$ the smaller triangle $$Z$$ formed by $$P, (0,0), (0,c)$$. This triangle $$Z$$'s area is exactly $$c$$ of the area of $$T$$, or equivalently, $${c \over 2}$$ of the area of $$R$$. This shows uniform distribution within $$[0,1]$$.

Empirically the density and cumulative distribution functions seem to look something like this, with the probability of the intercept being in $$[0,1]$$ being $$\frac12$$ and the density being constant in that interval

I am not convinced that this distribution has a mean, though it is obviously centred at $$\frac12$$; even if it does, I would be very surprised if it has a finite second moment