Geometric probability: line segment intersecting a circle? I'm interested in formulating a $2\text{D}$ geometric probability.
Given:

$(1)$ a circle of radius $r < \frac{1}{2}$ with origin $O$ at the center of a unit square 
$(2)$ two points $\{A,B\}$ chosen at random on the perimeter of the square*

(*To avoid falling prey to the Bertrand paradox, here's the exact way the points are picked. Importantly, this process does not avoid segments on the perimeter, itself.)
What is the probability that the line segment connecting the points also intersects the circle?

From what I've considered so far the perpendicular bisector of $\angle AOB$ provides a good test of intersection... but the task of integrating binarized results is daunting. I've also considered trying to solve this problem by some kind of polar projection, after which the circle would form a bounding line.
 A: Note that if $A$ and $B$ are points on the perimeter of the unit square, then the line segment $AB$ intersects the circle if and only if the midpoint of $AB$ is on the closed disc.
By symmetry, we may assume without loss of generality that $A$ is on the top edge, so  $A=(a,\tfrac12)$ for some $a\in[-\tfrac12,\tfrac12]$. We distinguish four cases:

*

*If $B$ is also on the top edge, then $AB$ does not intersect the circle.


*If $B$ is on the right edge, then $B=(\tfrac12,b)$ for some $b\in[-\tfrac12,\tfrac12]$, and the midpoint of $AB$ is
$$\left(\frac{2a+1}{4},\frac{2b+1}{4}\right).$$
Then the segment $AB$ intersects the circle if and only if
$$\left(\frac{2a+1}{4}\right)^2+\left(\frac{2b-1}{4}\right)^2\leq r^2.$$
Note that $A:=\tfrac{2a+1}{2}$ and $B:=\tfrac{2b+1}{2}$ are uniform random variables on $[0,1]$, and that the above is equivalent to
$$A^2+B^2\leq(2r)^2\tag{1}.$$
The probability that this inequality holds is precisely the proportion of the unit square $[0,1]^2$ that is inside the circle of radius $2r$ centered at the origin, which is of course $\pi r^2$.


*If $B$ is on the left edge, then by symmetry $AB$ intersect the circle with probability $\pi r^2$.


*If $B$ is on the bottom edge, then $B=(b,-\tfrac12)$ for some $b\in[-\tfrac12,\tfrac12]$ and the midpoint of $AB$ is
$$M=(\tfrac{a+b}{2},0).$$
Then the segment $AB$ intersects the circle if and only if
$$\left(\frac{a+b}{2}\right)^2+0^2\leq r^2,$$
or equivalently $|a+b|\leq2r$. Some elementary calculus then shows that the probability that this inequality holds equals $4r-4r^2$.
As each of the cases above is equally likely, we conclude that the probability that the line segment $AB$ intersects the circle equals
$$\frac14\cdot0+\frac24\cdot\pi r^2+\frac14\cdot(4r-4r^2)=\left(\frac{\pi}{2}-1\right)r^2+r.$$
A: Here's an attempt at a brute force approach. It isn't complete because I got tired of it. I might come back to this later, at least to fix errors (which seem likely), and perhaps to complete it. Either way, the idea should be clear, but I'm not convinced it leads to any nice closed form.
By symmetry, without loss of generality you may assume that the first point $A$ is on the left half of the bottom edge, so that $A=(a,-\tfrac12)$ with $a\in[-\tfrac12,0]$. Then the line segment $AB$ intersects the circle if and only if $B$ is between the two tangent lines to the circle that pass through $A$. We distinguish three cases:

*

*One tangent meets the top edge, the other meets the right edge.

*One tangent meets the left edge, the other meets the right edge.

*Both tangents meet the top edge.

The following pictures show circles with $r>\tfrac{1}{2\sqrt{5}}$, $r=\tfrac{1}{2\sqrt{5}}$ and $r<\tfrac{1}{2\sqrt{5}}$, respectively, as well as the tangent lines to the circle passing through the top two corners and  meeting the bottom edge:

Denote the $x$-coordinate of the intersection of the bottom edge and the tangent passing through the top-left corner by $f(r)$. This point is marked by the grey dot in the pictures above. Then considering the three cases listed above, we see that for a point $A=(a,-\tfrac12)$ with $a\in[-\tfrac12,0]$ we have

*

*The first case occurs if and only if $a\leq f(r)$ and $a\leq-f(r)$, i.e. $a\leq-|f(r)|$.

*The second case occurs if and only if $a\geq f(r)$.

*The third case occurs if and only if $a\geq-f(r)$.

Determining $f$ explicitly in terms of $r$ is an exercise in elementary analytic geometry, yielding
$$f(r)=\frac{1-2r^2+r\sqrt{2-4r^2}}{1-4r^2}.$$
Now for each $a\in[-\tfrac12,0]$ with $a\neq r$ the tangents to the circle that pass through $A=(a,-\tfrac12)$ are given by
\begin{eqnarray*}
T_+(x)&=&\lambda_+(x-a)-\tfrac12,\\
T_-(x)&=&\lambda_-(x-a)-\tfrac12.
\end{eqnarray*}
where
$$\lambda_{\pm}=\frac{-a\pm r\sqrt{4(a^2-r^2)+1}}{2(a^2-r^2)}.$$
Next determine their intersections with the appropriate edges, and then the proportion $p$ of the perimeter that is between them:

*

*[Perhaps later]

*[Perhaps later]

*If $a\geq-f(r)$ then in particular $r\leq\tfrac{1}{2\sqrt{5}}$, and solving
$$T_+(x_+)=\tfrac12\qquad\text{ and }\qquad T_-(x_-)=\tfrac12,$$
yields the solutions
$$x_+=a+\lambda_+^{-1}=a+\frac{\lambda_-}{1-4r^2}=a-\frac{a+4r\sqrt{4(a^2-r^2)+1}}{2(1-4r^2)(a^2-r^2)},$$
$$x_-=a+\lambda_-^{-1}=a+\frac{\lambda_+}{1-4r^2}=a-\frac{a-4r\sqrt{4(a^2-r^2)+1}}{2(1-4r^2)(a^2-r^2)},$$
and hence the proportion of the perimeter that is between the tangent lines equals
$$p(a,r)=\frac{|x_+-x_-|}{4}=\frac{r\sqrt{4(a^2-r^2)+1}}{(1-4r^2)|a^2-r^2|}.$$
This shows that for $r\leq\tfrac{1}{2\sqrt{5}}$ we get
\begin{eqnarray*}
P(r)&=&\int_{-\tfrac12}^0p(a,r)\,\mathrm{d}a
=\int_{-\tfrac12}^{-f(r)}??\,\mathrm{d}a
+\int_{-f(r)}^0\frac{r\sqrt{4(a^2-r^2)+1}}{(1-4r^2)|a^2-r^2|}\,\mathrm{d}a\\
&=&[???]
+\frac{1}{2-8r^2}\left[\ln\left(1-\frac{a}{r\sqrt{4(a^2-r^2)+1}}\right)
-\ln\left(1+\frac{a}{r\sqrt{4(a^2-r^2)+1}}\right)
+4r\ln\left(2a+\sqrt{4(a^2-r^2)+1}\right)\right]_{-f(r)}^0\\
&=&\ldots
\end{eqnarray*}
