# Probability of line segments intersecting on a plane - A generalization to Buffon's needle problem

I came up with this problem:

If I draw a length 1 line segment randomly, then draw another one, what's the probability that they'll intersect?

More precisely,

Consider a rectangular area of size $$w\times l$$ with periodic boundary conditions, where $$w\ge 2,l\ge 2$$. Draw two length 1 line segments randomly. Here, by randomly it means, first choose a random point with uniform distribution over the rectangular area, then from the circle that is centered at the first point with radius one, randomly choose a point with uniform distribution. These two points are the end points of the line segment.

Question: What's the probability that the two line segments intersect?

The solution can be found by simply integrating the probability densities, which gives $$p=\frac{1}{A}\times 4\times\frac{1}{2\pi}(p_1+p_2+p_3+p_4)$$, where $$A=lw$$ is the area, and

$$p_1=\int_0^1 rdr\int_0^{\frac{\pi}{2}}\theta-\sin^{-1}(r\sin\theta)d\theta$$

$$p_2=\int_{\frac{1}{2}}^1dx\int_0^\sqrt{1-x^2}\tan^{-1}\frac{x}{y}+\tan^{-1}\frac{1-x}{y}dy$$

$$\quad=\frac{1}{2}\int_0^1 rdr\int_{\sin^{-1}\frac{r}{2}}^{\frac{\pi}{2}}\theta+\tan^{-1}\frac{1-r\sin\theta}{r\cos\theta}d\theta$$

$$p_3=\int_0^1 rdr\int_0^{\sin^{-1}\frac{r}{2}}\theta+\cos^{-1}(r\cos\theta)d\theta$$

$$p_4=\int_0^{\frac{1}{2}}dx\int_\sqrt{1-x^2}^1 2\cos^{-1}y\ dy$$

And the results are

$$p_1=\frac{1}{4}$$

$$p_2=0.583664$$

$$p_3=0.155138$$

$$p_4=0.011197 =\frac{1}{72}(27 - 3 \sqrt 3 \pi - \pi^2)$$

Details can be found on my blog post.

The summation of these numbers is 0.999999, which is probably not a coincidence. My questions are,

1. Do they sum up to exactly 1, so that the probability is exactly $$\frac{2}{\pi A}$$? (Probably true, just need to find the exact integration value.) (✓ Proved)
2. Is there an easier and more intuitive way to prove this?
3. How can this be generalized?

I searched similar problems but I didn't find anything quite the same.

Considering that Buffon's needle problem has probability $$\frac{2l}{\pi t}$$, are they somehow related?

A more general description of this problem can be stated as the following:

Assuming there is a random uniform distribution with density $$\frac{1}{A}$$ of line segments with length 1 on the 2D plane. More precisely, the distribution is, the middle points of the line segments are uniformly distributed on the plane with density $$\frac{1}{A}$$ and the angles are also uniformly distributed from 0 to $$2\pi$$.

Then, if we draw another line segment of length one randomly, as described in the beginning, the expected number of intersections between this line segment and the line segments in the "background" is $$\frac{2}{\pi A}$$.

Edit:

I think, indeed, the Buffon's needle problem can be seen as a special case of this problem.

If we see each line as an infinite chain of length 1 line segments, and the distance between the lines is $$t$$, then each line segment occupies an area $$t$$, thus the expectation of the number of intersections between a length 1 needle with the lines is $$\frac{2}{\pi A}=\frac{2}{\pi t}$$. Due to the linearity of expectation, a length $$l$$ needle will have expectation $$\frac{2l}{\pi t}$$. When $$l\leq t$$, there can be at most one intersection, thus this is the probability of them intersecting.

Update 2023.10.30

After seeing @Claude Leibovici's answer, it seems that the integration of $$p_3$$ is particularly complicated, so I thought maybe doing it in the other direction is easier.

If we integrate $$r$$ first instead,the interval of $$\theta$$ is $$[0,\frac{\pi}{6}]$$ and the interval of $$r$$ is $$[2\sin\theta,1]$$. The integration is

$$p_3=\int_0^{\frac{\pi}{6}}d\theta\int_{2\sin\theta}^1 (\theta+\cos^{-1}(r\cos\theta))rdr$$ $$\quad=\int_0^{\frac{\pi}{6}}\frac{\theta}{2}(1-4\sin^2\theta)+\left[\frac{r^2\cos^2\theta}{2}\cos^{-1}(r\cos\theta)+\frac{1}{4}\sin^{-1}(r\cos\theta)-\frac{r\cos\theta}{4}\sqrt{1-r^2\cos^2\theta}\right]_{2\sin\theta}^1\frac{1}{\cos^2\theta}d\theta$$ $$\quad=\int_0^{\frac{\pi}{6}}\frac{\theta}{2}(1-4\sin^2\theta)+\left(\theta\frac{\cos^2\theta}{2}+\frac{1}{4}(\frac{\pi}{2}-\theta)-\frac{\sin\theta\cos\theta}{4}-\frac{\sin^2 2\theta}{2}(\frac{\pi}{2}-2\theta)-\frac{1}{4}(2\theta)+\frac{\sin 2\theta \cos 2\theta}{4}\right)\frac{1}{\cos^2\theta}d\theta$$

which is exactly $$\frac{1}{36}(9+3\sqrt 3\pi-2\pi^2)$$.

Combined with the other exact results, I think it's safe to say that the probability equals $$\frac{2}{\pi A}$$ is proved?

Some variations that I can think of:

1. Change background line segments into disks of radius 1. (Should be $$\frac{1}{A}\left(\pi+\int_1^{\sqrt 2} 2r\sin^{-1}\left(\frac{1}{r}\right)dr+\int_{\sqrt 2}^2 2r\cos^{-1}\left(\frac{r}{2}\right)dr\right)=\frac{\pi+2}{A}$$ if my calculation is correct.)
3. Empty circles of radius R<0.5. (Expected number of intersections, or probability of intersecting.)
4. Empty circles of radius R>0.5. (Expected number of intersections, or probability of intersecting.)

Are the expected numbers for cases 3 and 4 the same as considering the circle as the limit of an $$n$$-gon as $$n\rightarrow\infty$$? From the linearity of expectation, I expect that... If these problems turn out to be interesting, I'll post them in a seperate question.

• Nice work for sure and (+1). Commented Oct 30, 2023 at 9:21
• Perhaps relevant: cs.umb.edu/~eb/piday/whypi.pdf Commented Oct 30, 2023 at 15:13
• @EthanBolker This is called "Buffon's noodle" problem, a variation of the needle problem. I found this entry when I read through the needle problem, and I was thinking that maybe the Barbier's theorem is relevant to this problem. But after reading it more carefully, I realized that it's still the "shapes intersecting infinite lines that are evenly spaced" problem, so it doesn't provide much new info. But thanks anyway! Commented Oct 30, 2023 at 21:05

$$p_2=\frac{1}{72} \left(9-3 \sqrt{3} \pi +5 \pi ^2\right)$$ $$p_3=\frac{1}{36} \left(9+3 \sqrt{3} \pi -2 \pi ^2\right)$$ $$p_4=\frac{1}{72}\left(27 - 3 \sqrt 3 \pi - \pi^2\right)$$

I did not obtain $$p_3$$ directly but computed the integral to high accuracy and searched for $$(a,b,c)$$ such that $$0.15513848544247898382438117552853053666469992828759\cdots$$ $$=\frac{1}{72}\left(a + 3\sqrt 3 \pi b+c \pi^2\right)$$ over integers (three loops).

So $$(p_1+p_2+p_3+p_4)$$ is strictly equal to $$1$$.

Edit

In the middle of my work, I also found that

$$\int_0^1 r\,dr\int_0^{\sin ^{-1}\left(\frac{r}{2}\right)}\theta\,d \theta=\frac{1}{144} \left(-18+6 \sqrt{3} \pi -\pi ^2\right)$$ Too many common features !

Update

The real problem is $$\int_0^{\sin ^{-1}\left(\frac{r}{2}\right)}\cos ^{-1}(r \cos (\theta ))\,d \theta=\frac{1}{2} \pi \sin ^{-1}\left(\frac{r}{2}\right)-$$ $$\int_0^{\sin ^{-1}\left(\frac{r}{2}\right)}\sum_{n=0}^\infty \frac{ (2 n)!\, r^{2 n+1} }{4^n\,(2 n+1)\, (n!)^2}\cos ^{2 n+1}(\theta)$$

The problem is that

$$\int_0^{\sin ^{-1}\left(\frac{r}{2}\right)}\cos ^{2 n+1}(\theta)\,d\theta=\frac{1}{2} \left(\frac{\sqrt{\pi }\, \Gamma (n+1)}{\Gamma \left(n+\frac{3}{2}\right)}-B_{1-\frac{r^2}{4}}\left(n+1,\frac {1}{2}\right)\right)$$

SO, for $$p_3$$ we end with the monster $$p_3=\frac{1}{48} \left(12+24 \left(\sqrt{3}-2\right) \pi +\pi^2\right)+$$ $$\sum_{n=0}^\infty \frac{ (2 n)!}{2^{2 n+1}(2 n+1) (n!)^2}\int_0^1 r^{2 n+2} B_{1-\frac{r^2}{4}}\left(n+1,\frac{1}{2}\right)\,dr$$

Only the first term of the summation has a closed form value $$(\frac 5 {24})$$ but the summation converges quite fast.

Hoping no sign errors !

• If it helps, I get $$\frac{d}{dr} \int_0^{\sin^{-1}(r/2)} \cos^{-1}(r \cos \theta)\, d\theta = \frac{\cos^{-1}\left(r \sqrt{1-\frac{r^2}{4}}\right)}{\sqrt{1-\frac{r^2}{4}}} + \frac{\ln(1-r^2) - \ln 2}{2r}$$ Commented Oct 30, 2023 at 14:14
• @aschepler. Thank you but the problem moves after. This integral is a nightmare. Cheers :-) Commented Oct 30, 2023 at 14:16
• wow this seems really complicated. What are the $B$ functions here? Are they Bernoulli polynomials? I don't know they can take non-integer indices. Also, how did you get the high accuracy integral? Does the GMP library provide such precision? Regarding the integration itself, I found a work around, just integrate $r$ first, it's much easier! I updated it in the description. Commented Oct 30, 2023 at 23:39
• @YiJiang. The incomplete beta functions. Commented Oct 31, 2023 at 4:40
• @ClaudeLeibovici I see, thanks! Commented Oct 31, 2023 at 6:30