Sunday, October 29, 2023

Probability of line segments intersecting - A surprisingly simple result

I was drawing random stuff on a piece of paper, suddenly this problem came into my mind:
If I draw a length 1 line segment randomly, then draw another one, what's the probability that they'll intersect?
Of course this description is ambiguous. To give a better description, we need to define things more accurately. First, we should limit the area that we can draw the line segments in. Second, we should define what it means by "drawing a line segment randomly". To avoid annoying boundary situations, let's use periodic boundary conditions. But then, the size can't be too small, otherwise we may encounter complicated situations like crossing multiple times. Apparently, if the second line segment intersects the first, both of the end points of the second line segment must lie within the envelope curve that has distance 1 to the first line segment. This shape is called a "stadium", where a=r=1 in this case. If we choose a rectangular area w×l where w>=2 and l>=2, multiple intersections won't happen. The formal definition of the problem is as the following:
Consider a rectangular area of size w×l with periodic boundary conditions, where w>=2,l>=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?
Let's solve this problem! Because of the periodic boundary conditions, linear translations don't matter. We can move the first line segment to the center of the rectangle area. Then, the probability is only none zero if the second line segment lies within the stadium shape centered at the first line segment. It doesn't matter how the stadium shape is oriented, so we can assume that the first line segment lies horizontally. To find the probability, we can just integrate the probability that the second line segment intersects with the first one for all possible first end points of the second line segment. The area outside the stadium has zero probability density. Due to the symmetry of the shape, we only need to consider a quarter of the stadium, and multiply the answer by 4. The situations are different depending on which part of the stadium shape the first end point is in. We can put them in 4 parts:
(Actually, P1 and P3 can be combined in the calculations in polar coordinates. I started with Cartesian, so I didn't notice until later.) The probability is p=1A×4×12π(p1+p2+p3+p4), where p1=01rdr0π2θsin1(rsinθ)dθ p2=121dx01x2tan1xy+tan11xydy =1201rdrsin1r2π2θ+tan11rsinθrcosθdθ p3=01rdr0sin1r2θ+cos1(rcosθ)dθ p4=012dx1x212cos1y dy (We may combine p1 and p3 and just calculate 01rdrπ2sin1r2θ+cos1(rcosθ)dθ instead.) I'm not sure if Cartesian or polar coordinate system is easier to manually integrate them... I put them on wolfram alpha, and here's the result: p1=14 p2=0.583664 p3=0.155138 p4=0.011197=172(2733ππ2) Then I added them together, the summation is... 0.999999. Well, this can't be a coincidence, can it? I'll get the exact result when I have more time... So, the probability is 2πA, where A is the area that the line segment "occupies". I quickly wrote a program to simulate the problem in a 3×3 square. Averaging 100000000 results, the probability is 0.0707416, where the theoretical value is 29π=0.07073553. This reminds me of the result of Buffon's needle problem, which has probability 2lπt, where l is the length of the needles and t is the spacing between the lines, lt. This result can be taken as a generalization of Buffon's needle problem. It can be described as
Assuming there is a random uniform distribution with density 1A of line segments with length 1 on the 2D plane. More precisely, the distribution is, the middle points of the line segments is uniformly distributied on the plane with density 1A and the angle is also uniformly distributed from 0 to 2π. 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 2πA.
I wonder if this can be further generalized. An obvious first step is, changing the size of the line segments, which probably will give something similar to the result of Buffon's needle problem. How else can we generalize this? 2023.10.30 Update: 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 2πA=2πt. Due to the additivity of expectation, a length l needle will have expectation 2lπt. When lt, there can be at most one intersection, thus this is the probability of them intersecting. Regarding the integrations, Claude Leibovici gives the exact expressions to them, except for p3 which is still based on numerical evidence (albeit a very strong one). It seems very complicated, so I thought maybe it would be easier to do it in the other direction. If we integrate r first instead,the interval of θ is [0,π6] and the interval of r is [2sinθ,1]. The integration is p3=0π6dθ2sinθ1(θ+cos1(rcosθ))rdr =0π6θ2(14sin2θ)+[r2cos2θ2cos1(rcosθ)+14sin1(rcosθ)rcosθ41r2cos2θ]2sinθ11cos2θdθ =0π6θ2(14sin2θ)+(θcos2θ2+14(π2θ)sinθcosθ4sin22θ2(π22θ)14(2θ)+sin2θcos2θ4)1cos2θdθ I got lazy again and just lumped it into wolfram alpha. This time it gives the exact result, 136(9+33π2π2). Combined with the result p2=172(933π+5π2) and the other two known results, I think the proof that the probability equals 2πA is complete.

1 comment:

  1. posted on stackexchange, link: https://math.stackexchange.com/questions/4796686/probability-of-line-segments-intersecting-on-a-plane-an-generalization-to-buff , for reference and update.

    ReplyDelete

A Recursive Geometric Proof for 1962 IMO Problem 6

Youtube recommended a video to me, where the following problem is solved: Consider an isosceles triangle. Let R be the radius of its circ...