A square appears randomly within a square of ten time its area. probability that the smaller square contains the larger square’s center

analytic geometrygeometryprobabilityproblem solvingtrigonometry

The alignment relative to the larger square can be anywhere between 0° to 90° (0° or 90° being identical orientation to the larger square, 45° being all the way skewed), and the probability distribution of the alignment is based on percentage of total possibility given the constraint guaranteeing that it will fit within the larger square.

The largest discrete probability, for an alignment of 0°=90°, should be simple enough to figure-out‡. The smallest discrete probability, for alignment of 45°, is a bit trickier but straightforward enough.Edit:The off-kilter version would be more likely to contain the center, since it has less possible places to exist and a larger proportion of them are the center. Intuitively this should correspond directly (though not necessarily uniformly) to what I am totally clueless about, which is:

  1. how to determine the probability distribution for between 0° to 45°,

‡ 2. how this continuum corresponds to the probability of the original problem (e.g. {1/17?} for 0° up to {2/9?} for 45° back down to {1/17?} for 90°, along finite part of some sort of curve function presumably),

and 3. how then to apply these equations formulated into the original problem to find the final probability that a square true-randomly generated wholly within a larger square with sides √(10)-times longer would surround (or contain exactly on an edge or corner) the center of the larger square.

‡ I haven't calculated the maximum or minimum ‘discrete’ probabilities (let alone any inbetween) yet. Those guesstimate values are placeholders. I am especially interested in the processes required to solve this, and appreciate any insight or clues.

Best Answer

Without Rotation

Suppose a square of side $s\le\frac12$ is placed randomly inside a unit square, without rotation. The probability that the $x$-coordinate of the center of the unit square is within the $x$-span of the smaller square is $\frac{s}{1-s}$. That is, when covering the center of the unit square, the left side of the smaller square can be $s$ to $0$ units to the left of the center of the unit square, while, without restriction, the left side of the smaller square can go from $1$ to $s$ units to the left of the right side of the unit square. The same is true for the $y$-coordinate. So the probability that the center of the larger square is within the smaller square is $$ \left(\frac{s}{1-s}\right)^2\tag1 $$ In your question, $s=\frac1{\sqrt{10}}$, which gives a probability of $$ \bbox[5px,border:2px solid #C0A000]{\frac1{11-2\sqrt{10}}\approx0.213883399}\tag2 $$


With Rotation

Geometry and Probability

The smaller square rotated by $0\le\theta\le\frac\pi4$ will span a width and height of $$ d=s(\cos(\theta)+\sin(\theta))\tag3 $$ Note that $(3)$ says that $d:\left[0,\frac\pi4\right]\mapsto\left[s,s\sqrt2\right]$ monotonically.

If the smaller square is to stay inside the unit square, its center is constrained to a non-rotated square of side $1-d$ concentric with the unit square (shown below as a red square). If the center of the unit square is to be inside the smaller square, the center of the smaller square needs to be inside a square with the same size and rotation, but concentric with the unit square (shown below as a green square).

Thus, the locus of the center of the smaller square so that the smaller square is contained in the unit square, and so that the smaller square contains the center of the unit square is the intersection of the red and green squares (shown below in purple).

enter image description here

For a given size and rotation of the smaller square, given that the smaller square is contained in the unit square, the probability that the center of the unit square is inside the smaller square is the ratio of the area of the purple region divided by the area of the red square.

However, to get the proper weighting of the probabilities for the different angles, we need to weight the probabilities by the area of the red square since that is the probability that the rotated square is contained in the unit square. This means we compute the integral of the area of the purple region and divide that by the integral of the area of the red region.

Computation of the Areas

The area of the red square is $$ \begin{align} \text{area}_\text{red} &=(1-d)^2\tag{4a}\\[6pt] &=(1-s(\sin(\theta)+\cos(\theta)))^2\tag{4b}\\[6pt] &=1-2s(\sin(\theta)+\cos(\theta))+s^2(1+2\sin(\theta)\cos(\theta))\tag{4c}\\ \int_0^{\pi/4}\text{area}_\text{red}\,\mathrm{d}\theta &=\frac\pi4-2s+\left(\frac\pi4+\frac12\right)s^2\tag{4d} \end{align} $$ If $d\le\frac12$, then, because $d\lt1-d$, the green square is completely contained within the red square and so the area of the purple region is $$ \begin{align} \text{area}_\text{purple} &=s^2\tag{5a}\\ \int\text{area}_\text{purple}\,\mathrm{d}\theta &=\theta s^2\tag{5b}\\ &=a_1(s,\theta)\tag{5c} \end{align} $$ We leave $\text{(5b)}$ indefinite since we may need to restrict $\theta$ due to the condition $d\le\frac12$.

For $d\gt\frac12$, we will refer to the following diagram:

enter image description here

Since the side length of the red square $1-d$ and the height of the rotated green square is $d$, the four corners of the green square that extend beyond the red square have altitude $\frac{d-(1-d)}2=d-\frac12$ and base $\frac{d-1/2}{\sin(\theta)\cos(\theta)}$. If the bases of these triangles are smaller than the sides of the red square, then $\frac{d-1/2}{\sin(\theta)\cos(\theta)}\lt1-d$, which is equivalent to $d\lt\frac{1+\sin(2\theta)}{2+\sin(2\theta)}$.

Thus, if $\frac12\lt d\lt\frac{1+\sin(2\theta)}{2+\sin(2\theta)}$, the area of the purple region is $$ \begin{align} \text{area}_\text{purple} &=s^2-\frac{2(d-1/2)^2}{\sin(\theta)\cos(\theta)}\tag{6a}\\ &=s^2-\frac{2\left(s(\sin(\theta)+\cos(\theta))-\frac12\right)^2}{\sin(\theta)\cos(\theta)}\tag{6b}\\[3pt] &=\scriptsize-\frac12\csc(\theta)\sec(\theta)+2(\csc(\theta)+\sec(\theta))s-(3+2\csc(\theta)\sec(\theta))s^2\tag{6c}\\[6pt] \int\text{area}_\text{purple}\,\mathrm{d}\theta &=\scriptsize-\frac12\log(\tan(\theta))+2\log\left(\tan\left(\tfrac\theta2\right)\tan\left(\tfrac\pi4{+}\tfrac\theta2\right)\right)s-\left(3\theta+2\log(\tan(\theta))\right)s^2\tag{6d}\\[9pt] &=a_2(s,\theta)\tag{6e} \end{align} $$ If $d\ge\frac{1+\sin(2\theta)}{2+\sin(2\theta)}$, the red square is completely contained within the green square and so the area of the purple region is the same as the area of the red square: $$ \begin{align} \text{area}_\text{purple} &=(1-d)^2\tag{7a}\\[3pt] &=(1-s(\sin(\theta)+\cos(\theta)))^2\tag{7b}\\[3pt] &=1-2(\sin(\theta)+\cos(\theta))s+(1+2\sin(\theta)\cos(\theta))s^2\tag{7c}\\ \int\text{area}_\text{purple}\,\mathrm{d}\theta &=\theta-2(\sin(\theta)-\cos(\theta))s+\left(\theta+\sin^2(\theta)\right)s^2\tag{7d}\\ &=a_3(s,\theta)\tag{7e} \end{align} $$ Conditional Ranges

We need to apply each of $a_1$, $a_2$, or $a_3$ over particular parts of $\left[0,\frac\pi4\right]$. That is, we use $a_1$ over the green region of the chart below, $a_2$ over the yellow region, and $a_3$ over the red region.

enter image description here

To simplify the usage of the information in the chart above, define $$ \theta_1(s)=\frac12\sin^{-1}\left(\frac{1-4s^2}{4s^2}\right)\tag8 $$ and $$ \theta_2(s)=\frac12\sin^{-1}\left(\frac{1-4s^2+\sqrt{1-4s^2}}{2s^2}\right)\tag9 $$

If $s\le\frac1{2\sqrt2}$, we use $a_1$ for all $\theta\in\left[0,\frac\pi4\right]$. That is, the probability of the randomly rotated and positioned smaller square containing the center of the unit square is $$ \frac{a_1\!\left(s,\frac\pi4\right)-a_1\!\left(s,0\right)}{a_3\!\left(s,\frac\pi4\right)-a_3\!\left(s,0\right)}=\frac{\frac\pi4s^2}{\frac\pi4-2s+\left(\frac\pi4+\frac12\right)s^2}\tag{10} $$ If $\frac1{2\sqrt2}\lt s\le\frac{\sqrt2}3$, we use $a_1$ over $\theta\in[0,\theta_1(s)]$ and $a_2$ over $\theta\in\left[\theta_1(s),\frac\pi4\right]$. That is, the probability of the randomly rotated and positioned smaller square containing the center of the unit square is $$ \frac{a_2\!\left(s,\frac\pi4\right)-a_2(s,\theta_1(s))+a_1(s,\theta_1(s))-a_1(s,0)} {a_3\!\left(s,\frac\pi4\right)-a_3\!\left(s,0\right)}\tag{11} $$ If $\frac{\sqrt2}3\lt s\le\frac12$, we use $a_1$ over $\theta\in[0,\theta_1(s)]$, $a_2$ over $\theta\in[\theta_1(s),\theta_2(s)]$, and $a_3$ over $\theta\in\left[\theta_2(s),\frac\pi4\right]$. That is, the probability of the randomly rotated and positioned smaller square containing the center of the unit square is $$ \frac{a_3\!\left(s,\frac\pi4\right)-a_3(s,\theta_2(s))+a_2(s,\theta_2(s))-a_2(s,\theta_1(s))+a_1(s,\theta_1(s))-a_1(s,0)} {a_3\!\left(s,\frac\pi4\right)-a_3\!\left(s,0\right)}\tag{12} $$ In the question, $s=\frac1{\sqrt{10}}$, so we apply $(10)$ and get a probability of $$ \bbox[5px,border:2px solid #C0A000]{\frac\pi{11\pi+2-8\sqrt{10}}\approx0.279022074}\tag{13} $$ Here is a plot of the probability that a randomly rotated and positioned square of side $s$ inside the unit square contains the origin of the unit square:

enter image description here


Simulation

I ran a simulation placing the center of the smaller square, with side $s$, uniformly in a square, concentric with the unit square, and with side $1-s$, and rotating uniformly with $\theta\in\left[0,\frac\pi4\right]$.

All trials where the translated and rotated square did not fit completely in the unit square were rejected. The remaining trials were tallied counting those where the center of the unit square fell within the smaller square.

The results of $10,\!000,\!000$ trials with $s=\frac1{\sqrt{10}}$ were

non-rejected trials: $7,\!664,\!102$
successful trials: $2,\!136,\!729$
ratio: $0.278797046$

This is close to $0.279022074$.

Here is the Mathematica code for the simulation:

test[s_, x_, y_, \[Theta]_] := 
 Module[{c = {x - 1/2, y - 1/2} (1 - s), 
   m = s {{Cos[\[Theta]], Sin[\[Theta]]}, {-Sin[\[Theta]], Cos[\[Theta]]}},
   u = 1/2 {{-1, 1}, {1, 1}, {1, -1}, {-1, -1}}, 
   cross = (#1.{{0, 1}, {-1, 0}}.#2) &, ul, ur, lr, ll},
   {ul, ur, lr, ll} = u.m + {c, c, c, c}; 
  If[Max[Abs[ul], Abs[ur], Abs[lr], Abs[ll]] > 1/2, {0, 0}, 
   If[Min[cross[ur, ul], cross[ul, ll], cross[ll, lr], cross[lr, ur]] < 0,
    {0, 1}, {1, 1}]]]
Module[{s = 1/Sqrt[10], n = 10000000, data = {0, 0}}, 
 Do[data += test[s, RandomReal[1], RandomReal[1], RandomReal[Pi/4]], n];
 data]