I have a square with side length $ s $.

A (uniformly) random coordinate $ c = (x,y) $ inside this square is the origin of a (uniformly) randomly oriented vector of fixed length $ l $.

enter image description here

Vector endpoints can end up both within the square and outside of it, depending on their orientation and $ c $. The escape probability for a point is not the same everywhere, it depends on their position.

A vector starting closer to the center/halfway along the side of the square has a lower probability than one in the corner to land outside.

Point p here can reach the sides but not the corner, everything closer to the corner can do both and therefore has an even higher probability.

enter image description here

So how does this probability distribution $ P_{escape}(s,l,x,y) $ look like?

Can it be used to express the average expected escape probability for large amounts of randomly chosen vectors analytically?

$ P_{escape}(s,l) = ? $

Some possibly irrelevant notes:

In the special case where $ l<s/2 $, there exists in the center of the square a region (here in green) where vectors, regardless of orientation, cannot reach the edge. In this special case, there is also a segment of the square edges that have probability 1/2

Also, if $ l = 0 $, then $ P(s,l) = 0 $, or if $ l > \sqrt{2*s^2} $, then $ P(s,l) = 1 $

  • $\begingroup$ Hint: Assume the bottom left corner of the square is the origin. Consider any point $(x,y)$ and draw a circle with radius $l$. Then any point on the circle be written as $(x + l \cos \theta, y + l \sin \theta)$ for $\theta \in [0, 2 \pi)$. Can you find the range of $\theta$ for which this point lies outside the square? $\endgroup$
    – sudeep5221
    Jun 30, 2023 at 21:32
  • $\begingroup$ @sudeep5221 if you look at the range of $\theta$, the calculus gets quite messy. I've posted an alternative approach as an answer. $\endgroup$ Jul 2, 2023 at 12:03

2 Answers 2


To simplify things a little, let's make $s=2$ and we'll consider the square $S$ with vertices $(\pm1,\pm1)$.

Say the start point of the vector is $P(u,v)$ and its angle (measured anticlockwise from the positive $x$-axis, as usual) is $\theta$.

Then the endpoint of the vector is $Q(u+l \cos \theta,v+l \sin \theta)$.

It's tempting to pick $P(u,v)$ and work out the range of $\theta$ that makes $Q$ outside $S$, but this makes calculations very messy.

It's better to fix $\theta$, and consider the ranges of $u$ and $v$.

Let's restrict $\theta$ to be in the range $\left(0,\frac{\pi}{2}\right)$ (this will actually cover all cases, by symmetry). This means both $\cos \theta$ and $\sin \theta$ are positive.

We need to consider the cases $l \le 2$ and $l>2$ separately.

Case $l \le 2$

For the point $Q$ to be inside $S$, we need both $$-1<u<1-l \cos \theta$$


$$-1<v<1-l \sin \theta$$

These inequalities define a rectangle, with area $$(2-l \cos \theta)(2-l \sin \theta)$$

So, for a given $\theta$, the probability the point $Q$ is inside $S$ is $$P(\theta) = \frac{(2-l \cos \theta)(2-l \sin \theta)}{4}$$

(the ratio of the areas of the rectangle and the whole square).

Now, to find the overall probability, we need to integrate: $$\begin{align} P(\text{inside})&=\frac{2}{\pi} \int_0^\frac{\pi}{2} \frac{(2-l \cos \theta)(2-l \sin \theta)}{4} d\theta \\ &= 1+\frac{l(l-8)}{4\pi}\end{align}$$

So the probability we want (one minus this) is $$\boxed{P(\text{escape}) = \frac{l(8-l)}{4\pi}}$$

Case $l>2$

This method needs a slight adjustment for $l>2$. Note that now, if $P=(-1,-1)$ and $\cos \theta > \frac{2}{l}$, $Q$ will always be outside $S$.

This observation tells us what to do, though; we just change the limits for $\theta$ in the integral:

$$\begin{align} P(\text{inside})&=\frac{2}{\pi} \int_{\cos^{-1} \frac{2}{l}}^{\frac{\pi}{2} - \cos^{-1} \frac{2}{l}} \frac{(2-l \cos \theta)(2-l \sin \theta)}{4} d\theta \\ &= \frac{1}{4\pi} \left(8\sqrt{l^2-4}-16\cos^{-1} \frac{2}{l} + 4\pi - 8 - l^2 \right) \end{align}$$

So finally, in this case, $$\boxed{P(\text{escape}) = \frac{1}{4\pi} \left(8 + l^2 - 8\sqrt{l^2-4}+16\cos^{-1} \frac{2}{l} \right)}$$


The final position $(X,Y)$ is $(C_x + l\cos\Theta,C_y + l\sin\Theta)$ where: $C_x,C_y \sim U(0,s)$, $\Theta \sim U(-\pi,\pi)$, $l\cos(\Theta)\sim\operatorname{Arcsine}(-l,l)$.

Let $L_x=l\cos\Theta$ and $L_y = l\sin\Theta$
$L_x = \lambda \Rightarrow L_y=\lambda\tan\Theta$

$$\begin{align}F_{L_y}(l_y)&=P(L_y\leq l_y)\\&= P(\lambda\tan\Theta\leq l_y)\\&= P\left(\Theta\leq\tan^{-1}\left(\frac{l_y}{\lambda}\right)\right)\\&= F_\Theta\left(\tan^{-1}\left(\frac{l_y}{\lambda}\right)\right)\\&= \frac{1}{2\pi}\left(\tan^{-1}\left(\frac{l_y}{\lambda}\right)+\pi\right) \end{align}$$

$$\therefore P(L_y|L_x=\lambda)= \frac{1}{2\pi}\frac{\lambda}{\lambda^2+l_y^2}\\ $$ $$\begin{align} P(L_x) &= \frac{1 }{\pi\sqrt{(l_x-(-l))(l-l_x)} } \\&= \frac{1 }{\pi\sqrt{l^2-l_x^2} } \end{align} $$ $$\begin{align} P(C_y|L_x) &= P(C_y) \end{align} $$ $$\begin{align} P(C_y+L_y|L_x) &= \int_{-\infty}^\infty{f_{C_y}(y−l_y)f_{L_y}(l_y)dl_y}\\&= \int_{y}^{y-s}{\frac{1}{s}\frac{1}{2\pi}\frac{\lambda}{\lambda^2+l_y^2}dl_y}\\&= \frac{\tan^{-1}\left(\frac{y-s}{\lambda}\right)-\tan^{-1}\left(\frac{y}{\lambda}\right)}{2 \pi s} \end{align} $$ $$\begin{align} P(C_y+L_y) &= \int_{y}^{y-s}{\frac{1}{s} \frac{1 }{\pi\sqrt{l^2-l_y^2} }dl_y}\\&= \frac{\sin^{-1}\left( \frac{y-s}{l }\right)-\sin^{-1}\left( \frac{y}{l}\right) }{\pi s } \end{align} $$ $$\begin{align} P(L_x|Y)&= P(L_x|C_y+L_y)\\&= P(C_y+L_y|L_x) \frac{P(L_x)}{P(C_y+L_y) }\\&= \frac{\tan^{-1}\left( \frac{y-s}{l_x }\right)-\tan^{-1}\left( \frac{y}{l_x }\right)}{2 \pi s } \frac{ \frac{1 }{\pi\sqrt{l^2-l_x^2} } }{\frac{\sin^{-1}\left( \frac{y-s}{l }\right)-\sin^{-1}\left( \frac{y}{l}\right) }{\pi s } }\\&= \frac{\tan^{-1}\left( \frac{y-s}{l_x }\right)-\tan^{-1}\left( \frac{y}{l_x }\right)}{2\pi\left(\sin^{-1}\left( \frac{y-s}{l }\right)-\sin^{-1}\left( \frac{y}{l}\right)\right)\sqrt{l^2-l_x^2} } \end{align} $$ $$ P(C_x|Y)=P(C_x) $$ $$ \begin{align} \therefore P(X|Y)&= P(C_x+L_x|Y)\\&= \int_{-\infty}^\infty{f_{C_x}(x-l_x)f_{L_x}(l_x)dl_x}\\&= \int_{x}^{x-s}{ \frac{1}{s } \frac{\tan^{-1}\left( \frac{y-s}{l_x }\right)-\tan^{-1}\left( \frac{y}{l_x }\right)}{2\pi\left(\sin^{-1}\left( \frac{y-s}{l }\right)-\sin^{-1}\left( \frac{y}{l}\right)\right)\sqrt{l^2-l_x^2} }dl_x} \end{align} $$

This is as far as I got,

$$\begin{align}P(X,Y)&=P(X|Y)P(Y)\\ &=P(C_x+L_x|C_y+L_y)P(C_y+L_y) \end{align} $$

And, $$\begin{align}P(0\leq X\leq s, 0\leq Y\leq s)&=\int_0^s{\int_0^sP(X=x,Y=y){dx}dy} \end{align}$$

This should at least sketch you a solution


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .