Skip to content
Vamshi Jandhyala

Mathematics

Sheep That See Each Other

A Fiddler puzzle on mutual visibility: sheep at random points in a square, facing random directions, each with a 180-degree field of view. Two sheep see each other with probability 1/4 whatever the pen; for three, the probability reduces to an average of (pi - alpha)(pi - beta)(pi - gamma) over the triangle's angles and comes to about 0.0272, with a Monte Carlo check.

Download PDF →


Problem

Two sheep are at two random points inside a square pen. They are munching grass and staring in two random directions. Each sheep has a field of view that’s 180 degrees. What is the probability that they both see each other?

Extra credit. Now, three sheep are at three random points inside a square pen. They are munching grass and staring in three random directions. As before, each sheep has a field of view that’s 180 degrees. What is the probability that all three sheep see each other?

Credit: The Fiddler on the Proof.

What it means to see

Each sheep stands at a point chosen uniformly in the unit square and faces a direction chosen uniformly on the circle, independently of everything else. A field of view of 180180^\circ means the sheep sees the entire half-plane in front of it: the half whose boundary runs through the sheep at right angles to its facing direction. In vectors, a sheep at PP facing the unit vector u\mathbf{u} sees a point QQ exactly when QQ lies forward of that boundary, (QP)u  0.(Q - P)\cdot \mathbf{u} \ \ge\ 0.

A sheep at a point with a copper arrow showing its facing direction. A dashed line through the sheep, at right angles to the facing direction, divides the plane. The half-plane in front is shaded green and labelled 180-degree field of view, with a green semicircle arc; a point in front is labelled 'in view' and a point behind is labelled 'out of view'.
A sheep with a $180^\circ$ field of view sees everything in the half-plane it faces. The dividing line runs through the sheep at right angles to its facing direction.

Two sheep

Fix the two positions AA and BB for a moment and look only at the directions. Sheep AA sees sheep BB when its facing vector points into the half-plane containing BB, that is, when the facing direction lies within 9090^\circ of the direction from AA to BB. Those facing directions fill exactly half of the circle, and the facing direction is uniform, so P(A sees B)=180360=12.\mathbb{P}(A \text{ sees } B) = \frac{180^\circ}{360^\circ} = \frac12. Crucially this does not depend on where AA and BB are: wherever BB sits, half of AA‘s possible facings point towards it. By the same argument P(B sees A)=12\mathbb{P}(B \text{ sees } A) = \tfrac12. The two facings are independent, so P(both see each other)=1212=14.\mathbb{P}(\text{both see each other}) = \frac12 \cdot \frac12 = \frac14. The positions never entered the calculation, so the square is a red herring: the answer is 14\tfrac14 for a pen of any shape.

Two sheep A and B joined by a dashed line of sight. Around each is a circle of possible facing directions; the half of each circle that looks across towards the other sheep is drawn as a thick green arc, and a copper facing arrow points into it. Each is labelled 'facings that see the other: half the circle, probability one half'.
For each sheep, the facings that look across to the other fill half of the direction circle. The two choices are independent, so both see each other with probability $\tfrac14$, whatever the positions.

Three sheep: each must see two

With three sheep the directions still do all the work, but now each sheep has to see two others at once. Consider sheep AA, and let α\alpha be the interior angle at AA in the triangle ABCABC, the angle between the direction to BB and the direction to CC. Sheep AA sees BB when its facing lies in the half-circle of directions centred on ABA \to B, and sees CC when its facing lies in the half-circle centred on ACA \to C. To see both, the facing must lie in the overlap of these two half-circles.

Two half-circles whose centres are α\alpha apart overlap in an arc of 180α180^\circ - \alpha. (Slide one half-circle round by α\alpha and it loses exactly α\alpha of its overlap with the other.) Since the facing is uniform, P(A sees both B and C)=180α360=πα2π,\mathbb{P}(A \text{ sees both } B \text{ and } C) = \frac{180^\circ - \alpha}{360^\circ} = \frac{\pi - \alpha}{2\pi}, writing α\alpha in radians. The same holds at BB and CC with their interior angles β\beta and γ\gamma.

Left: triangle ABC with interior angles alpha at A, beta at B, gamma at C marked. Right: a wheel of facing directions centred at A. A blue arrow points to B and a red arrow points to C, separated by angle alpha. A blue semicircle arc marks the facings that see B and a red semicircle arc marks the facings that see C; their overlapping sector is shaded copper and labelled 'overlap = pi minus alpha', with P(A sees both) = (pi minus alpha) over 2 pi.
Left: the three positions form a triangle with interior angles $\alpha, \beta, \gamma$. Right: at $A$, the facings that see $B$ and the facings that see $C$ are two half-circles whose centres differ by $\alpha$; their overlap spans $\pi - \alpha$, so $A$ sees both with probability $(\pi-\alpha)/2\pi$.

Averaging over the triangle

Each sheep’s success depends only on its own facing, and the three facings are independent. So, with the positions fixed, P(all three see each othertriangle)=πα2ππβ2ππγ2π=(πα)(πβ)(πγ)8π3.\mathbb{P}(\text{all three see each other} \mid \text{triangle}) = \frac{\pi-\alpha}{2\pi}\cdot\frac{\pi-\beta}{2\pi}\cdot\frac{\pi-\gamma}{2\pi} = \frac{(\pi-\alpha)(\pi-\beta)(\pi-\gamma)}{8\pi^3}. Because α+β+γ=π\alpha + \beta + \gamma = \pi, each factor is the sum of the other two angles, πα=β+γ\pi - \alpha = \beta + \gamma, and the same identity expands the product neatly: (πα)(πβ)(πγ)=π(αβ+βγ+γα)αβγ.(\pi-\alpha)(\pi-\beta)(\pi-\gamma) = \pi(\alpha\beta + \beta\gamma + \gamma\alpha) - \alpha\beta\gamma. What remains is to average this over the triangle made by three uniform points in the square, P(all three see each other)=18π3E[(πα)(πβ)(πγ)].\mathbb{P}(\text{all three see each other}) = \frac{1}{8\pi^3}\,\mathbb{E}\bigl[(\pi-\alpha)(\pi-\beta)(\pi-\gamma)\bigr]. The distribution of the angles of a random triangle in a square has no tidy closed form, so this last expectation is evaluated numerically. To high precision, P(all three see each other)0.02721,\mathbb{P}(\text{all three see each other}) \approx 0.02721, that is, about 2.72%2.72\%. The factor (πα)(πβ)(πγ)(\pi-\alpha)(\pi-\beta)(\pi-\gamma) vanishes whenever one angle approaches π\pi, so the long, thin triangles that three random points so often make contribute almost nothing, which is why the answer sits well below the value 1/270.0371/27 \approx 0.037 that a perfectly equilateral pen would give.

QuantityValue
P(two sheep see each other)\mathbb{P}(\text{two sheep see each other})1/4=0.251/4 = 0.25
P(three sheep all see each other)\mathbb{P}(\text{three sheep all see each other})0.02721\approx 0.02721

Computational verification

We confirm both answers by simulation: place the sheep uniformly, draw their facings uniformly, and test the half-plane condition (QP)u0(Q - P)\cdot\mathbf{u} \ge 0 for every ordered pair. This uses nothing but the raw rule of the problem, no angles and no formula, so it checks the whole argument independently. As a faster cross-check, which assumes the (πα)/2π(\pi-\alpha)/2\pi step rather than testing it, we also average the per-triangle formula (πα)(πβ)(πγ)/8π3(\pi-\alpha)(\pi-\beta)(\pi-\gamma)/8\pi^3, with the directions already integrated out.

import numpy as np
rng = np.random.default_rng(20260529)
N = 20_000_000

def dirs(n):                       # uniform facing directions
    t = rng.uniform(0, 2*np.pi, n)
    return np.stack([np.cos(t), np.sin(t)], -1)

def sees(P, u, Q):                 # viewer at P facing u sees Q?
    return ((Q - P) * u).sum(-1) >= 0

# two sheep
A, B = rng.uniform(0,1,(N,2)), rng.uniform(0,1,(N,2))
both = sees(A, dirs(N), B) & sees(B, dirs(N), A)
print(both.mean())                 # -> 0.2500

# three sheep
A, B, C = (rng.uniform(0,1,(N,2)) for _ in range(3))
uA, uB, uC = dirs(N), dirs(N), dirs(N)
allsee = (sees(A,uA,B) & sees(A,uA,C) &
          sees(B,uB,A) & sees(B,uB,C) &
          sees(C,uC,A) & sees(C,uC,B))
print(allsee.mean())               # -> 0.0272
QuantityExact / formulaMonte Carlo
two sheep0.250000.250000.250050.25005
three sheep0.027210.027210.027210.02721
Two panels. Left: a histogram of the probability, for one random triangle, that all three sheep see each other; it rises towards roughly 0.037 and has a copper mean line at about 0.0272. Right: running Monte Carlo estimates against the number of trials on a log scale; a blue 'two sheep' curve settles on a dashed line at 1/4, and a green 'three sheep' curve settles on a dashed line at 0.0272.
Left: across random triangles, the probability that all three sheep see each other ranges from $0$ for thin triangles up towards $1/27$ for near-equilateral ones, with mean $\approx 0.0272$. Right: the running Monte Carlo estimates settle onto $1/4$ and $0.0272$.

A pen where the answer is exact: the circle

The square resists a closed form because the angles of a random triangle inside it have no tractable distribution. One pen escapes this: a circular fence with the sheep on the rail. Three points on a circle make a triangle inscribed in it, and inscribed triangles pin the angles down exactly.

The angles are half the opposite arcs

Fix the circle’s centre OO. The inscribed-angle theorem says the interior angle at a vertex is half the central angle standing on the same chord. At AA this is BAC=12BOC\angle BAC = \tfrac12 \angle BOC, the central angle of the arc BCBC opposite AA.

A circle with centre O and three points A, B, C on it forming an inscribed triangle. The interior angle alpha at A is marked, and the central angle 2 alpha at O, both standing on the same arc BC, which is highlighted in green. Dashed radii run from O to B and to C.
The inscribed angle $\alpha$ at $A$ is half the central angle $2\alpha$ subtending the same arc $BC$. So each interior angle is half its opposite arc.

Write a^\hat a for the central angle of the arc opposite AA, and likewise b^,c^\hat b, \hat c. Then α=12a^,β=12b^,γ=12c^.\alpha = \tfrac12\hat a, \qquad \beta = \tfrac12\hat b, \qquad \gamma = \tfrac12\hat c. The three opposite arcs tile the circle, a^+b^+c^=2π\hat a + \hat b + \hat c = 2\pi, which simply re-derives α+β+γ=π\alpha + \beta + \gamma = \pi.

The arcs are uniform on the simplex

The three points are independent and uniform on the circle. By rotational symmetry we may hold one of them fixed; the other two are then uniform on the cut circle, an interval of circumference 2π2\pi. The three arcs are exactly the gaps left by two uniform points on that interval, and the gaps of kk uniform points on an interval are uniformly distributed over the simplex of fractions that sum to one. With k=2k = 2, the three normalised arcs, and hence the normalised angles (a,b,c)=(απ,βπ,γπ),a+b+c=1,(a, b, c) = \Bigl(\tfrac{\alpha}{\pi}, \tfrac{\beta}{\pi}, \tfrac{\gamma}{\pi}\Bigr), \qquad a + b + c = 1, are uniform over the triangle {a,b,c0, a+b+c=1}\{a, b, c \ge 0,\ a + b + c = 1\}.

Two integrals

On that triangle the density is constant. The triangle has area 12\tfrac12, so the density is 22. Writing c=1abc = 1 - a - b and integrating over a0, b0, a+b1a \ge 0,\ b \ge 0,\ a + b \le 1, E[ab]=201 ⁣ ⁣01aabdbda=01a(1a)2da=112,\mathbb{E}[ab] = 2\int_0^1\!\!\int_0^{1-a} ab \, db \, da = \int_0^1 a(1-a)^2 \, da = \frac{1}{12}, E[abc]=201 ⁣ ⁣01aab(1ab)dbda=1301a(1a)3da=13120=160,\mathbb{E}[abc] = 2\int_0^1\!\!\int_0^{1-a} ab(1 - a - b) \, db \, da = \frac13\int_0^1 a(1-a)^3 \, da = \frac13\cdot\frac{1}{20} = \frac{1}{60}, the inner integrals being 01abdb=(1a)2/2\int_0^{1-a} b\,db = (1-a)^2/2 and 01ab(1ab)db=(1a)3/6\int_0^{1-a} b(1-a-b)\,db = (1-a)^3/6. By symmetry E[ab+bc+ca]=3E[ab]=14\mathbb{E}[ab + bc + ca] = 3\,\mathbb{E}[ab] = \tfrac14.

Assembling the answer

For any pen, the per-triangle probability is (πα)(πβ)(πγ)/8π3(\pi-\alpha)(\pi-\beta)(\pi-\gamma)/8\pi^3. In normalised angles πα=π(1a)\pi - \alpha = \pi(1 - a), so this is π3(1a)(1b)(1c)8π3=(1a)(1b)(1c)8=(ab+bc+ca)abc8,\frac{\pi^3 (1-a)(1-b)(1-c)}{8\pi^3} = \frac{(1-a)(1-b)(1-c)}{8} = \frac{(ab + bc + ca) - abc}{8}, using (1a)(1b)(1c)=1(a+b+c)+(ab+bc+ca)abc(1-a)(1-b)(1-c) = 1 - (a+b+c) + (ab+bc+ca) - abc with a+b+c=1a + b + c = 1. Taking the expectation over the uniform-simplex angles, P(all three see each other)=18(E[ab+bc+ca]E[abc])=18(14160)=181460=72400.02917.\mathbb{P}(\text{all three see each other}) = \frac18\Bigl(\mathbb{E}[ab + bc + ca] - \mathbb{E}[abc]\Bigr) = \frac18\Bigl(\frac14 - \frac{1}{60}\Bigr) = \frac18\cdot\frac{14}{60} = \frac{7}{240} \approx 0.02917. The independent direction-level simulation, with the sheep placed on the circle and their facings drawn at random, gives 0.029160.02916, in agreement.

A round pen is therefore a little kinder to mutual sightlines than a square one, 7/2402.92%7/240 \approx 2.92\% against the square’s 2.72%\approx 2.72\%. Points on a rim never fall almost in a line, so the triangles stay fatter, the binding overlaps παi\pi - \alpha_i stay larger, and the product survives more often. Two sheep, as always, see each other with probability exactly 14\tfrac14, on a pen of any shape at all.


More mathematical writing →