Average Shadows

by Greg Egan


Shadow of a cube


Cubes

What is the average area of the shadow cast by a cube, if we take the average over all possible orientations of the cube, while keeping its centre fixed?

This question was posed in a delightful video by Grant Sanderson, and answered for the case where the light source is infinitely far above the ground, so the shadow is cast by parallel rays. I won’t state the formula right now, so as not to spoil the fun if you decide to watch the video, or work out the answer for yourself. The derivation is a lot of fun, and you might find the result surprisingly simple.

On this page, we will find the average area of the shadow for the case where the light source is at a finite distance, but with the simplifying feature that it will be located directly above the centre of the cube.

We will assume that:

The quantity ½√3 here is the distance from the centre of the cube to one of its vertices, so the condition on δ will ensure that, however the cube is oriented, the light source is always outside the cube. We could impose a similar condition on h, so that no portion of the cube is ever below the ground, but although that would be necessary for the problem to make sense physically, all the geometry of rays from the light source intersecting the ground continues to work for any value of h.

What does it mean to take an average over all possible orientations of the cube? One way to formalise this is to suppose that we start with the cube in a certain orientation, then average over the result of applying all possible rotations. The group of all rotations in three dimensions, known as SO(3), can be given a coordinate system and a measure, which is essentially a probability distribution, assigning to each subset of the space a number such that the whole space has a measure of 1. What’s more, there is a unique way of doing this, such that the measure of a set of rotations is unchanged if we multiply them all by any other fixed rotation. In general, this is known as the Haar measure of the group. If, instead of the rotations themselves, we work with unit quaternions, the space we are considering will be the 3-dimensional surface of a hypersphere in four dimensions, and the Haar measure is the usual geometric measure of volume that the surface inherits from 4-dimensional Euclidean space.

If all of that sounds a bit abstract, don’t worry, because the consequences of formalising things this way are precisely what you would expect, intuitively. Any vector in our initial orientation of the cube (say, a vector n normal to one of the faces) ends up with equal probability of pointing in any direction, so we can average it over the 2-dimensional surface of an ordinary sphere in three dimensions. And any vector e that is orthogonal to n (say, the direction of an edge on the corresponding face of the cube) ends up having equal probability of pointing in any of the circle of directions orthogonal to n in its rotated position. So, if we sweep n over a sphere of directions, and e over a circle of directions orthogonal to n, we will have all orientations covered, with the correct probabilities.

We will proceed by computing the average area of the quadrilateral shadow cast on the ground by a single face of the cube, as the cube itself is swept through all possible orientations while its centre is kept fixed. The shadow of the whole cube is a more complicated polygon, but its area at any instant will be equal to half the sum of the areas of the shadows of all six faces, because each geometric ray casting the shadow will enter the cube on one face and leave it on another. Since all six faces must, by symmetry, have the same average area, the average area of the cube’s shadow will be exactly three times the average area of a single face’s shadow.

Suppose the outward-pointing normal vector to the face is:

n = (sin θ cos φ, sin θ sin φ, cos θ)

where θ measures the angle from the vertical, and ranges from 0 to π, while φ is a longitudinal angle ranging from 0 to 2π. If we integrate over these variables, we need to weight the quantity we are averaging by sin θ, the radius of a circle on the unit sphere at an angle of θ from the north pole, and then divide the integral by 4π, the total area of the unit sphere.

Given that direction for the face normal n, we will suppose that the two directions of the face edges are:

e1 = (–sin α cos θ cos φ – cos α sin φ, cos α cos φ – sin α cos θ sin φ, sin α sin θ)
e2 = (–cos α cos θ cos φ + sin α sin φ, –sin α cos φ – cos α cos θ sin φ, cos α sin θ)

These are unit vectors that are orthogonal to each other, and both are orthogonal to n, with α specifying the amount of rotation in the plane orthogonal to n. If we integrate the quantity we are averaging over α from 0 to 2π, we then need to divide by 2π.

The four vertices of the face are then given by:

v = (0,0,h) + ½n ± ½e1 ± ½e2

We project these vertices with rays from the light source, at s = (0,0,h+δ), to the ground:

P(x, y, z) = [(h+δ) / (h+δ–z)] (x, y)

The area of any triangle in two dimensions can be found as half the determinant of the 2×2 matrix whose columns are two edge vectors of the triangle (the angle moving counterclockwise from the first edge to the second must pass through the interior of the triangle to yield the correct sign). The area of any triangle in three dimensions can be found as half the magnitude of the cross product of any two edges. Combining these with our projection formula, with a bit of algebra it is not too hard to show that the factor by which the area of a triangle is multiplied to give the area of its shadow is:

Triangle shadow area factor = ½(h+δ)2 (n · (ts)) / [(z1h – δ) (z2h – δ) (z3h – δ)]

Here zi are the z coordinates of the triangle’s vertices, n is a unit vector normal to the plane of the triangle, t can be any point at all in the plane of the triangle (we could pick one of the vertices to be concrete), and s = (0,0,h+δ) is the light source. This gives a positive factor overall if the vector n points from the triangle towards the light source; the three terms in the denominator are all negative, because the triangle must lie below the light source.

If we divide our square face into two triangles with equal area of ½, the area of the shadow of the face will just be the average of these factors for the two triangles. If we grind through all the calculations, we end up with:

A(θ, α) = | 4 (h + δ)2 (2δ – cos θ) (2δ cos θ – 1) / ((2δ – cos θ)4 – 2 (2δ – cos θ)2 sin2 θ + (cos2 α – sin2 α)2 sin4 θ) |

Note that the angle φ does not appear here at all! Because we have chosen to place the light source directly above the centre of the cube, the longitudinal angle makes no difference to the size of the shadow. As a further check that this formula makes sense, we can put θ=0, which gives:

A = 4 (h + δ)2 / (2δ – 1)2

Putting z=h+½ in the projection formula gives a linear scaling factor whose square matches this.

We will perform the integration over α first. Because α measures the rotation of the face in its own plane, the value of α cannot have any effect on the sign of the quantity we are using to compute the area. So we can integrate over the full range of α without worrying about having to take the opposite value of the integrand for part of the range (as we will need to do for θ).

We will make use of the formula:

1/(2π) ∫0 1 / (b + (cos2 α – sin2 α)2) dα = 1 / √[b (b+1)]

This can be proved fairly easily by means of Cauchy’s residue theorem, after converting the denominator of the integrand into:

b + (cos2 α – sin2 α)2 = ½(1 + 2b + cos 4α)

This expression has four distinct zeroes with real parts between 0 and 2π in the upper half-plane of the complex numbers. By deforming the integral from 0 to 2π to loop around these four zeroes, the residues of the original function can be added up to give the result we are claiming.

This lets us average the area over α, obtaining:

A(θ) = | 4 (h + δ)2 (2 δ cos θ – 1) / [(2 cos2 θ – 4 δ cos θ + 4 δ2 – 1) √(3 cos2 θ – 4 δ cos θ + 4 δ2 – 2)] |

The sign of the quantity whose absolute value we are taking depends entirely on the (2δ cos θ – 1) term in the numerator. Neither of the expressions in the denominator have real zeroes for θ, given the restriction we have imposed on δ. So we can integrate the expression and its opposite over the two ranges for θ where the sign is constant, on either side of arccos(1/(2δ)).

When we integrate over θ, we need to multiply the expression above by sin θ to get the correct measure on the sphere of directions, and then divide by 2. Why 2, and not the area of the sphere, 4π? Because there is no dependence on φ, we aren’t going to bother explicitly integrating for φ from 0 to 2π, but if we did, that would introduce a factor of 2π, and then dividing by 4π would simply be the same as dividing by 2.

This integral can be performed after making the substitution u = cos θ. The indefinite integral can then be expressed as:

I(u) = (h + δ)2 arctan( ( (u – 2 δ) √(3 u2 – 4 δ u + 4 δ2 – 2)) / (u2 – 1) )

Or, in a form you can cut and paste into software like Mathematica, if you want to verify the derivative:

(d + h)^2*ArcTan[((-2*d + u)*Sqrt[-2 + 4*d^2 - 4*d*u + 3*u^2])/(-1 + u^2)]

Then the sum of the two definite integrals, with the appropriate signs, multiplied by half the number of faces, yields a final result:

Average unit cube shadow = 3 (h + δ)2 arctan( (√(3 – 16 δ2 + 16 δ4)) / (1 – 8 δ2 + 8 δ4) )

Some care is needed taking the arctan here; when the denominator crosses zero so the argument becomes negative, we need to choose the value of the angle that lies in the second quadrant (i.e. between π/2 and π) rather than using negative values.

These features are illustrated in the plot below. The numerical values here correspond to setting h=1.

Average shadow of a cube, as distance to light source varies

The average shadow area for a cube with any edge length can be found by rescaling the unit cube version:

Average cube shadow, edge length L = 3 (h + δ)2 arctan( L2 (√(3L4 – 16 δ2 L2 + 16 δ4)) / (L4 – 8 δ2 L2 + 8 δ4) )

Other Polyhedra

We could generalise these calculations to any convex polyhedron at all, but to keep the results simple we will impose the restriction that all the faces are regular polygons, with the line from the centre of the face to the centre of the polyhedron perpendicular to the plane of the face. That includes the Platonic solids, whose faces are identical regular polygons, but we won’t need to assume that all the faces are the same, as different sets of faces can always be averaged separately then added together.

Consider a face that is a regular m-gon of radius r (that is, each vertex is a distance r from the centre of the face), and the centre of the face lies at a perpendicular distance p from the centre of the polyhedron. As before, we will assume that the centre of the polyhedron is at (0,0,h), while the light source is at s = (0,0,h+δ). We will impose the restriction δ2 > p2+r2, to ensure that the light source is outside the polyhedron.

The simplest approach will be to decompose the m-gon into m isosceles triangles, each with one vertex at the centre of the face and two that are adjacent vertices of the face itself. We will make use of three mutually orthogonal vectors:

n = (sin θ, 0, cos θ)
e1 = (–sin α cos θ, cos α, sin α sin θ)
e2 = (–cos α cos θ, –sin α, cos α sin θ)

which are essentially the same as those we employed in the previous section, but now with hindsight we have set the angle φ in the original vectors to zero, because we know that the value of φ will make no difference to the area of the shadow.

Our triangle’s vertices will be:

v1 = (0,0,h) + p n
v2,3 = (0,0,h) + p n + r (cos π/m e1 ± sin π/m e2)

The area of the shadow is then:

T(θ, α) = |[r2 (h + δ)2 (p – δ cos(θ)) sin(2π/m)] / [2 (δ – p cos(θ)) (δ – p cos(θ) + r sin(π/m – α) sin(θ)) (δ – p cos(θ) – r sin(π/m + α) sin(θ))] |

This can be averaged over α fairly easily by again using Cauchy’s residue theorem, though the integrand takes a slightly different form. The general result we rely on is:

1/(2π) ∫0 1 / [(a + sin(b – α))(a – sin(b + α))] dα = 2 a / [(2a2 – cos(2b) – 1) √(a2 – 1)]

This gives us:

T(θ) = | [r2 (h + δ)2 (p – δ cos(θ)) sin(2π/m)] / [ ((2 p2 + r2 (1 + cos(2π/m))) cos(θ)2 – 4 p δ cos(θ) + 2 δ2r2 (1 + cos(2π/m))) √((p2 + r2) cos(θ)2 – 2 p δ cos(θ) – r2 + δ2) ] |

As before, the integral that averages over θ can be performed after making the substitution u = cos θ and dividing by 2. The indefinite integral is:

I(u) = ¼ (h + δ)2 arctan([2 sin(2π/m) (p u – δ) √(r2 (u2 – 1) + (p u – δ)2)] / [r2 (u2 – 1) + (r2 (u2 – 1) + 2 (p u – δ)2) cos(2π/m)])

Or in machine-friendly form:

((d + h)^2*ArcTan[(2*(-d + p*u)*Sqrt[(-d + p*u)^2 + r^2*(-1 + u^2)]*Sin[(2*Pi)/m])/ (r^2*(-1 + u^2) + (2*(-d + p*u)^2 + r^2*(-1 + u^2))*Cos[(2*Pi)/m])])/4

Although this expression certainly has the correct derivative, the arctan function is multivalued (because tan is periodic), and we risk having discontinuities in the value between the endpoints of our region of integration, introducing extra multiples of π that don’t matter in an indefinite integral (because the derivative of any added constant is zero), but can reck the result of our definite integrals. So, for the next step we will consider the arctan to have been rewritten as a function of separate x and y arguments, rather than just the ratio y/x. Since there are different conventions as to the order in which the two arguments should be given, we will label them explicitly:

I(u) = ¼ (h + δ)2 arctan(y = 2 sin(2π/m) (p u – δ) √(r2 (u2 – 1) + (p u – δ)2), x = r2 (u2 – 1) + (r2 (u2 – 1) + 2 (p u – δ)2) cos(2π/m))

The integrand changes sign at u = p/δ, and the sum of the two definite integrals, multiplied by m, then gives us:

Average m-gon shadow area = (h + δ)2 ((m/2) arctan(y = 2 sin(2π/m) √((p2 – δ2) (p2 + r2 – δ2)), x = –r2 – (2 p2 + r2 – 2 δ2) cos(2π/m)) – π)

The average shadow area for the entire polyhedron would then be half the sum of this for all faces.

As a cross-check, for the unit cube we have:

m = 4
p = ½
r = 1/√2
Average square face shadow area = (h + δ)2 (2 arctan(y = 2 √((¼ – δ2) (¾ – δ2)), x = –½) – π)

It is not immediately obvious that this answer agrees with our previous calculation, but using the formula for the tan of a double angle, they can be shown to be the same.

To compare the behaviour of the shadow size between polyhedra, we need to make some choices that put the different shapes on an equal footing. If we scale all the Platonic solids to fit into a sphere of radius 1, with its centre at a height of 1, and divide the average shadow areas by the surface areas of the polyhedra, we obtain the following curves:

Average shadow divided by surface area

So the ratio for large values of δ is very similar (and all of these will tend to a limit of ¼), while the shadow size when the light source is close is influenced by the solid angle that the body of the polyhedron subtends at a vertex, which is much more for a dodecahedron that it is for a tetrahedron. The ratio for a sphere is shown for comparison; this tend to infinity as the light source approaches the surface of the sphere.



Valid HTML Valid CSS
Science Notes / Average Shadows / created Wednesday, 29 December 2021
If you link to this page, please use this URL: https://www.gregegan.net/SCIENCE/AverageShadows/AverageShadows.html
Copyright © Greg Egan, 2021. All rights reserved.