# Expectation of the number of points inside a foursquare of a rectangle

Consider a rectangle (black one) in the following image. Lets take four random points uniformly on each border then connecting the points one after another (red lines) to get a foursquare inside the rectangle.

If we put a set of random points ($n$ points) uniformly inside the rectangle , I would like to know what is the mathematical expectation of the number of points that are inside the red area?

Since the position of red points are random, I really can't solve this problem.

The probability that each point falls in the red area, is the area of red_line divided by area of rectangle. Since the area it self is a random process, so we need to calculate the expectation of the area of the red line.

• The expected number should be $n\times\frac{Q}{R}$ where $Q$ is the area of the "foursquare" and $R$ is the area if the rectangle – Jonathan Davidson Jul 6 '17 at 21:48
• The expected number is proportional to the expected area of the foursquare which in terms equals to the difference of the area of rectangle and the sum of expected areas of 4 triangles. For each triangle, the two sides (around the right angle) are independent, so its area is $\frac12 \times\left( \frac12 \right)^2 = \frac18$ of that of the rectangle. This means the expected number is simply $n (1 - 4\times \frac18) = \frac12 n$. – achille hui Jul 6 '17 at 21:55
• @quasi The vertices of the foursquare are "four random points uniformly on each other". Even though the sides of triangles at different corners are not independent, the two sides of any triangle are independent. – achille hui Jul 6 '17 at 21:58
• @quasi expectation of sum of something = sum of expectation of something even when the items involved are not independent. – achille hui Jul 6 '17 at 22:01
• @quasi: the probability of falling inside the quadrilateral is its relative area. – Yves Daoust Jul 6 '17 at 22:50

WLOG, I am solving for a unit square.

Let the four vertices be at coordinates $x,x',y,y'$ on the respective sides. The area of the quadrilateral is $1$ minus the areas of the four corners,

$$A=1-\frac{xy+(1-x)y'+x'(1-y)+(1-x')(1-y')}2=\frac{1-(x-x')(y-y')}2.$$

As $x,x',y,y'$ are uniform independent random variables, their pairwise differences follow independent triangular distributions centered on $0$, and the expectation of the product is the product of the expectations.

Hence, $$E(A)=\frac12.$$

One way of doing it:

Let the vertices of the rectangle be $(0,0),(w, 0),(0, h),(w, h)$.

Then the $4$ red points are $(0, r_1h),(w, r_2h), (r_3w,0), (r_4w,h)$ where $r_n$ are uniformly distributed random numbers between $0$ and $1$.

The area of a particular quadrilateral is

$$\textrm{Area of rectangle} - \textrm{Area of 4 triangles}=hw\left(1-\frac{1}{2}(r_1r_3+r_2(1-r_3)+(1-r_1)r_4+(1-r_4)(1-r_2))\right)$$

$$=hw\left(1-\frac{1}{2}(r_1r_3+r_2-r_2r_3+r_4-r_1r_4+1-r_2-r_4+r_2r_4)\right)$$

$$=hw\left(\frac{1}{2}-\frac{1}{2}(r_1r_3-r_2r_3-r_1r_4+r_2r_4)\right)$$

$$=hw\left(\frac{1}{2}(1-(r_1-r_2)(r_3-r_4))\right)$$

The expected number of points inside a particular quadrilateral is $n\left(\frac{\textrm{Area of quadrilateral}}{\textrm{Area of rectangle}}\right)$

We then want to integrate between $0$ and $1$ for each $r_n$ to find the final expectation which gives us:

$$E(\textrm{Number of Points})=\int^1_0\int^1_0\int^1_0\int^1_0{n\left(\frac{\textrm{Area of quadrilateral}}{\textrm{Area of rectangle}}\right)\,\,\,dr_1dr_2dr_3dr_4}$$

$$=\frac{n}{2}-\frac{n}{2}\int^1_0\int^1_0\int^1_0\int^1_0{(r_1-r_2)(r_3-r_4)\,\,\,dr_1dr_2dr_3dr_4}$$

$$=\frac{n}{2}-\frac{n}{2}\int^1_0\int^1_0\left(\int^1_0r_1\,\,\,dr_1-\int^1_0r_2\,\,\,dr_2\right)(r_3-r_4)\,\,\,dr_3dr_4$$

$$=\frac{n}{2}$$

• So what is the answer in the end?! what fraction of $n$ are inside? – M a m a D Jul 6 '17 at 22:06
• Could someone verify my answer? Intuitively, I find $\frac{n}{2}$ confusing. – Shuri2060 Jul 6 '17 at 22:19
• @Shuri2060 what's so confusing, it is the correct answer. – achille hui Jul 6 '17 at 22:22
• @achillehui Might be me, but I can think of quadrilaterals which take up more than half the area of the rectangle, but not less than. – Shuri2060 Jul 6 '17 at 22:26
• +1 I'm glad you figure it out yourself. Following is something that should make the answer more intuitive. First fix 3 vertices and vary one of the vertices, say $r_1$. The area of the the foursquare has the form const $r_1$ + const. When one take expectation over $r_1$, the expected area is the same as if you set $r_1$ directly at the midpoint. Do the same thing to other 3 vertices. one find the expected area of foursquare is the same as the rhombus having the midpoints of the edges of rectangle as vertices. i.e. one half of that of the rectangle. – achille hui Jul 6 '17 at 22:49