Triangle area from uniformly distributed points in squares

129 Views Asked by At

3 random positions in 3 squares are selected from independent uniform distributions. How to calculate the expected absolute triangle area if the squares are arranged as in the sketch?

The side length of a square $m$ is smaller than the square distance $n$. The squares are parallel and colinear. In each square lies 1 random point.

enter image description here

2

There are 2 best solutions below

2
On BEST ANSWER

This is essentially dan_fulea’s solution, but since I’d almost finished it and I wrote it down somewhat differently, I’m posting it anyway.

I'll use coordinates with the origin at the bottom left and the $x$ and $y$ axes in the usual directions.

The signed area is a quadratic function of the coordinates that can be derived e.g. via the cross product of two sides: $A=\frac12((x_2-x_1)(y_3-y_1)-(x_3-x_1)(y_2-y_1))=\frac12(x_3y_1-x_1y_3+x_1y_2-x_2y_1+x_2y_3-x_3y_2)$. The sign changes exactly once across the range of $y_2$, so it’s convenient to do the $y_2$ integration first. Since the integral over the signed area is zero, we can replace the integral of the unsigned area by twice the integral of the signed area over the domain where it is positive:

\begin{eqnarray} && \int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2\int_0^m\mathrm dy_1\int_0^m\mathrm dy_3\int_0^m\mathrm dy_2\,|A| \\ &=& \int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2\int_0^m\mathrm dy_1\int_0^m\mathrm dy_3\int_0^{\frac{x_3y_1-x_1y_3-x_2y_1+x_2y_3}{x_3-x_1}}\mathrm dy_2 \\ && (x_3y_1-x_1y_3+x_1y_2-x_2y_1+x_2y_3-x_3y_2) \\ &=& \int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2\int_0^m\mathrm dy_1\int_0^m\mathrm dy_3\frac12\frac{(x_3y_1-x_1y_3-x_2y_1+x_2y_3)^2}{x_3-x_1} \\ &=& \frac12\int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2\int_0^m\mathrm dy_1 \\ &&\frac1{x_3-x_1}\left(\frac13(x_2-x_1)^2m^3+(x_2-x_1)(x_3-x_2)y_1m^2+(x_3-x_2)^2y_1^2m\right) \\ &=& \frac12m^4\int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2 \\ && \frac1{x_3-x_1}\left(\frac13(x_2-x_1)^2+\frac12(x_2-x_1)(x_3-x_2)+\frac13(x_3-x_2)^2\right) \\ &=& \frac1{12}m^4\int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2 \frac1{x_3-x_1}\left(x_2^2-(x_1+x_3)x_2+2x_1^2+2x_3^2-3x_1x_3\right) \\ &=& \frac1{12}m^4\int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3 \\ && \frac1{x_3-x_1}\left(\frac13(m^3+3m^2n+3mn^2)-\frac12(m^2+2mn)(x_1+x_3)+m(2x_1^2+2x_3^2-3x_1x_3)\right) \\ &=& \frac1{12}m^4\int_0^m\mathrm dx_1\int_{2n-x_1}^{2n+m-x_1}\mathrm du \\ && \frac1u\left(\frac13(m^3+3m^2n+3mn^2)-\frac12(m^2+2mn)(u+2x_1)+m(2x_1^2+2(u+x_1)^2-3x_1(u+x_1))\right) \\ &=& \frac1{12}m^4\int_0^m\mathrm dx_1\left(\left(\frac13(m^3+3m^2n+3mn^2)-(m^2+2mn)x_1+mx_1^2\right)\right. \\ && \left.(\log(2n+m-x_1)-\log(2n-x_1))-\frac12(m^2+2mn)m+m^2x_1+m^3+2m^2(2n-x_1)\right) \\ &=& \frac1{12}m^4\int_0^m\mathrm dx_1\left(\left(\frac13(m^3+3m^2n+3mn^2)-(m^2+2mn)x_1+mx_1^2\right)\right. \\ && \left.(\log(2n+m-x_1)-\log(2n-x_1))+\frac12m^3+3m^2n-m^2x_1\right) \\ &=& \frac1{72}(m^8 + 4m^7n + 6m^6n^2 + 4m^5n^3)\log(2n+m) \\ && -\frac1{72}(m^8 - 4m^7n + 6m^6n^2 - 4m^5n^3)\log(2n-m) \\ && - \frac19(m^7n + m^5n^3)\log(2n)+\frac29m^7n\;. \end{eqnarray}

This we need to divide by

$$ \int_0^m\mathrm dx_1\int_{2n}^{2n+m}\mathrm dx_3\int_n^{n+m}\mathrm dx_2\int_0^m\mathrm dy_1\int_0^m\mathrm dy_3\int_0^m\mathrm dy_2=m^6 $$

to obtain the expected unsigned area,

$$ \frac1{72}\left(m^2 + 4mn + 6n^2 + 4\frac{n^3}m\right)\log(2n+m) \\ -\frac1{72}\left(m^2 - 4mn + 6n^2 - 4\frac{n^3}m\right)\log(2n-m) \\ - \frac19\left(mn + \frac{n^3}m\right)\log(2n)+\frac29mn\;. $$

2
On

Let us denote by $P_k=(X_k,Y_k):\Omega\to\Bbb R^2$ the three random variables with values in the three squares $S_k$, for $k\in\{1,2,3\}$ respectively. Here $\Omega$ is some probability space. We may take it of the shape $S_1\times S_2\times S_3$, and $P_k$ is the projection on the corresponding component, $P_k:S_1\times S_2\times S_3\to S_k$.

The important information we have is $$ X_1<X_2<X_3\ . $$ We write down an integral for the unsigned area $|A|$ of $\Delta P_1P_2P_3$, where the signed area $A$ is given by $$ A=\frac 12 \begin{vmatrix} 1 & X_1 & Y_1\\ 1 & X_2 & Y_2\\ 1 & X_3 & Y_3 \end{vmatrix}\ , $$ and search for a useful Fubini separation. We may "fix" for this the points $P_1=(X_1,Y_1)$, $P_3=(X_3,Y_3)$, then fix from $P_2$ its part $X_2$ and separate the cases

  • $Y_2$ is bigger than the intersection $Y^*$ of the line $P_1P_2$ with the vertical in $X_2$,
  • $Y_2$ is smaller than the intersection $Y^*$.

And note that the $Y^*$ is again in range between $Y_1,Y_3$, in either order, so in the same interval on the vertical line given by the projection of any of the squares on it.

The two cases above distinguish the orientation of the triangle $P_1P_2P_3$, and thus also the sign of the determinant. In the first case it is negative, in the second case it is positive. The line $P_1P_2$ has the equation $$ \frac{y-Y_1}{Y_3-Y_1} = \frac{x-X_1}{X_3-X_1}\ , $$ i.e. $$ y = Y_1 +(x-X_1)\cdot\frac {Y_3-Y_1}{X_3-X_1} $$ so $$ Y^* = Y_1 +(X_2-X_1)\cdot\frac {Y_3-Y_1}{X_3-X_1}\ . $$ To have an easy situation, i will rescale to have $m=2$, so the final result has to be multiplied by $m^2/2^2$, and let $a$ be the difference between the rescaled $n$ an the rescaled $m=2$. The squares are then

  • $S_1=[-(3+a),-(1+a)]\times [0,2]$
  • $S_2=[-1,1]\times [0,2]$
  • $S_3=[1+a,3+a]\times [0,2]$

and we have to compute the following integrals, $$ \begin{aligned} J &= \int_{(x_1,y_1)\in S_1}dx_1\;dy_1 \int_{(x_3,y_3)\in S_3}dx_3\;dy_3 \int_{-1}^1dx_2 \int_0^{y^*(x_1,y_1;x_3,y_3;x_2)} A\; dy_2\ , \\ &=\frac 89\int_{-(3+a)}^{-(1+a)}dx_1\int_{(1+a)}^{(3+a)}dx_3\cdot\frac{6x_1^2-9x_1x_3+6x_3^2+1}{x_3-x_1}\ , \\ &=\frac 89\int_{-(3+a)}^{-(1+a)}dx_1\int_{(1+a)}^{(3+a)}dx_3\cdot\frac{6(x_3-x_1)^2 +3x_1x_3+1}{x_3-x_1}\ , \\ &=\frac{128}3(a+2) \\ &\qquad\qquad+\frac 89\int_{-(3+a)}^{-(1+a)}dx_1\int_{(1+a)}^{(3+a)}dx_3\cdot\frac{3x_1x_3+1}{x_3-x_1}\ , \\[3mm] J' &= \int_{(x_1,y_1)\in S_1}dx_1\;dy_1 \int_{(x_3,y_3)\in S_3}dx_3\;dy_3 \int_{-1}^1dx_2 \int_{y^*(x_1,y_1;x_3,y_3;x_2)}^2 A\; dy_2 \\ &=-\frac 89\int_{-(3+a)}^{-(1+a)}dx_1\int_{(1+a)}^{(3+a)}dx_3\cdot\frac{6x_1^2-9x_1x_3+6x_3^2+1}{x_3-x_1} \ , \end{aligned} $$ then build the average area as $J-J'=2J$, and have to divide with $2^6$, so that we indeed use a probability measure, which leads to the answer $$\color{blue}{\frac 1{2^6}\cdot 2J}\ .$$

Later EDIT: Above, the factor $1/2^6$ was inserted after joriki's comment.

(We have as expected $J'=-J$ also because of the obvious symmetry w.r.t. horizontal line through the center of the squares $S_1, S_2,S_3$, which brings the domain of integration for $J$ in the one for $J'$ and viceversa.)

Since $A$ is a polynomial with involved monomials of the shape $x_jy_k$, and the only involved denominator in the condition for $y^*$ is $(x_3-x_1)$, we have integrated first against the other variables, and the computation is a routine exercise, left here on the hands of a computer... (Sage code appended.)

It remains to compute (twice) $J$. The part in the last integral with $(3x_1x_3+1)/(x_3-x_1)$ leads to logarithmic terms, it does not have a beautiful expression, so instead of typing it, i will delegate the answer to the CAS below. I consider here the mathematical part finished.

$\square$


Promised sage code:

var('x1,y1,x2,y2,x3,y3,a')
assume(a>0)
J_13 = integral( integral( integral( integral(
    matrix(3, 3, [1, x1, y1, 1, x2, y2, 1, x3, y3]).det(),
    y2, 0, y1 + (x2-x1) * (y3-y1)/(x3-x1) ),
    y1, 0, 2),
    y3, 0, 2),
    x2, -1, 1)

JJ_13 = integral( integral( integral( integral(
    matrix(3, 3, [1, x1, y1, 1, x2, y2, 1, x3, y3]).det(),
    y2, y1 + (x2-x1) * (y3-y1)/(x3-x1), 2 ),
    y1, 0, 2),
    y3, 0, 2),
    x2, -1, 1)

print( J_13.factor() )
print( JJ_13.factor() )

The last two prints deliver

-8/9*(6*x1^2 - 9*x1*x3 + 6*x3^2 + 1)/(x1 - x3)
8/9*(6*x1^2 - 9*x1*x3 + 6*x3^2 + 1)/(x1 - x3)

as mentioned in the computation of $J, J'$. We may require:

sage: assume(x1-a-3>0)                                                                                    
sage: assume(x1-a-1>0)                                                                                    
sage: 8/9 * integral( integral( 6*(x3-x1), 
....:     x3, 1+a, 3+a), 
....:     x1, -(3+a), -(1+a) ).factor()                                                                   
128/3*a + 256/3

which is one explicit piece, but we also have to mention...

sage: 8/9 * integral( integral( (3*x1*x3 + 1) / (x3-x1), 
....:     x3, 1+a, 3+a), 
....:     x1, -(3+a), -(1+a) ).simplify_full()                                                            

16/9*(a^3 + 9*a^2 + 28*a + 30)*log(2*a + 6)
 - 32/9*(a^3 + 6*a^2 + 16*a + 16)*log(2*a + 4)
 + 16/9*(a^3 + 3*a^2 + 4*a + 2)*log(2*a + 2)
 - 128/9*a - 256/9

(Output was manually rearranged.)