Edit: Reframed the problem to find an actual answer! Though I may well be talking to myself at this point. Answer below the original problem.
The original context of this question is a ridiculous, brainless mobile game. But the geometric question that arises seems quite interesting--I suspect it has already been studied. But I can't quite figure out how to calculate, or even if it can be calculated.
Consider a rectangle $ABCD$ centered on the origin (just for simplicity/symmetry). Now consider two sets of lines: $H$, the set of all lines passing through a point on $\overline{AB}$ and a point on $\overline{CD}$; and $V$, the set of lines passing through a point on $\overline{AD}$ and a point on $\overline{BC}$.
(Or perhaps more simply, all of the lines in $\mathbb{R}^2$ that pass through opposite sides of the rectangle.)
Is there a density function $f(x_0, y_0)$ that computes the proportion of these lines that pass through an infinitesimal area defined as any of the points $(x_0-\delta < x < x_0 + \delta, y_0 - \delta < y < y_0 + \delta)$? If not, can we find such a function that works for a non-infinitesimal area?
Other questions might include:
- Does the density function change based on the length:width ratio, or does the function stretch uniformly as we deform the rectangle?
- Does the shape of the inner square matter, e.g., would the density function change if it were a circle?
It seems to me that (assuming the function isn't just trivially uniform) an integral from $A$ to $B$ of the ratio: (the range of angles that create lines that pass through the inner square from this point)/(the range of valid angles of lines drawn from this point) would be a start. Then add similar integrals from the other three sides. (Or find the mean of the four?) But I'm wholly uncertain how to represent those ratios mathematically.
In addition, a first educated guess suggests the maximum density ought to be at the origin, if there is a maximum, and minima toward the corners.
Any thoughts? Or any references to a solution to this?
Answer
To get to an answer, I've simplified slightly and rearranged the parameters. Instead of trying to converge on an infinitesimal, I thought, maybe we could start with the infinitesimal, i.e., the point we want a probability for. Let's have a new diagram:
The square is centered at the origin, and its corners are at $(\pm 1, \pm 1)$. The point $P$ is at $(p,q)$. (You can mess with this diagram at GeoGebra if desired.)
All of the "admissible" lines will sit between $AV$ and $BU$ (horizontally) and between $CS$ and $DT$ (vertically). Hence the "density"--really, a probability--is the proportion $\frac{1}{\tau} (2 \alpha + 2 \gamma)$. It turns out, though, that determining $\beta$ is a lot easier than determining $\gamma$, so we will instead measure $\frac{1}{\tau} (\tau +2 \alpha - 2 \beta)$.
In fact, we can determine both $\alpha$ and $\beta$ using just the law of cosines. If we take the side length as $s$, we can see that:
$$ \begin{align} 2 ab \cos \alpha &= a^2 + b^2 - s^2 \\ 2 cd \cos \beta &= c^2 + d^2 - s^2 \\ \end{align} $$
The lengths $a, b, c,$ and $d$ are determined easily by the Pythagorean distance formula, which I'll assume is well-known. I could write out a bunch of messy equations here, but I'm pretty sure that's not useful.
However, there is one more thing of note. Just as a square has eightfold symmetry, the probability at various points has the same. That is, one should expect the same probability for points at $(0.6, 0.3), (-0.6, -0.3)$, and $(0.3, -0.6)$. Hence, the following transformations make the math slightly simpler:
$$ x' = \max(|x|, |y|) \ ; \ y' = \min(|x|, |y|) $$
This transform maps every point in the square onto a point with $x \geq 0, y \geq 0, x \geq y$.
Other minor points of interest:
- At the origin, the probability is $1$, as all the angles are right angles. Note that "probability" at this point means "number of points at the edges that can produce an admissible line, divided by all points."
- The probability drops to a minimum of $0.25$ at the corners, and to around $0.30$ at the centers of the edges.


Let $A=(a/2;b/2)$, $B=(-a/2;b/2)$, $C=(-a/2;-b/2)$, $D=(a/2;-b/2$.
Consider rectangle $(x,y;x+dx,y+dy)$, taking for simplicity (because of symmetry) $x>0$, $y>0$.
The minimum slope for this rectangle is $k_{min}=\frac{y}{x+dx}=\frac{y}{x}\frac{1}{1+dx/x}=\frac{y}{x}(1-dx/x)=\frac{y}{x}-\frac{y}{x^2}dx$. The maximum slope is $k_{max}=\frac{y+dy}{x}=\frac{y}{x}+\frac{1}{x}dy$.
The number of lines going through the rectangle is $N=\int_{k_{min}}^{k_{max}} f(k) dk$, where $f(k)$ is distribution function for slopes. $k_{min}-k_{max}=\frac{1}{x}dy+\frac{y}{x^2}dx$, $N=f(y/x) \cdot\left(\frac{1}{x}dy+\frac{y}{x^2}dx\right)$. $N$ is not proportional to $dx dy$, so we cannot use density per area here, but we can introduce line density as ratio of $N$ to infinitesimal square side $dy=dx$. Such density is $f(y/x)\cdot (1/x+y/x^2)$.
The constant slope distribution function $f(k)=A$ makes lines distibution more dense along $y$-axis ($x=0$), because this area corresponds to infinite $k$-range.