# Compute the average distance from the base of a rectangular pyramid to its apex

How can I compute the average distance from the base of a rectangular pyramid to its apex? For example, if the base of the pyramid is 30 feet by 8 feet, and the height of the pyramid is 12 feet, then what is the average distance from the base to the apex, meaning if we measured the distance from every point in the base to the apex, what would be the average distance? Assume that the pyramid is symmetric.

I had originally thought there would be some simple formula for this computation, but mathematicians have informed me it is a complex integral. How can I set that up in Mathematica?

• Is it easier for square pyramids? What does the integral look like in the plane w/ triangles? Oct 29, 2014 at 16:43
• NIntegrate[EuclideanDistance[{x, y, 0}, {0, 0, 12}], {x, -15, 15}, {y, -4, 4}]/(30 8)
– user484
Oct 29, 2014 at 16:44
• @alancalvitti Since a square pyramid is symmetric across the diagonal, the answer will be the same for a half pyramid divided that way. Oct 29, 2014 at 20:29
• @TylerDurden, by the 2nd part of my q, I meant, what does the integral look like of the average distance from the base of a triangle to the apex, in the plane. Oct 29, 2014 at 20:41

dist = UniformDistribution[{{-15, 15}, {-4, 4}}];
avgdist = NExpectation[Norm[{x, y, 12}], {x, y} \[Distributed] dist]


14.8171

You can also use

 NExpectation[EuclideanDistance[{x, y, 0}, {0, 0, 12}], {x, y} \[Distributed] dist]


to get the same result.

Update: You can obtain the average distance symbolically using

Integrate[Sqrt[c^2 + x^2 + y^2] Boole[-a < x < a && -b < y < b],
{x, -Infinity, Infinity}, {y, -Infinity, Infinity},
Assumptions -> {a > 0, b > 0, c > 0}]/(4 a b)


DensityPlot[EuclideanDistance[{x, y, 0}, {0, 0, 12}], {x, -15, 15}, {y, -4, 4},
AspectRatio -> Automatic]


NIntegrate[EuclideanDistance[{x, y, 0}, {0, 0, 12}], {x, -15, 15}, {y, -4, 4}]/(30 8)

(* 14.8171 *)

{a, b, c, d, e} = {{0, 0, 12}, {-15, -4, 0}, {-15, 4, 0}, {15, 4, 0}, {15, -4, 0}};
coords = {{b, c, d, e}, {a, b, c}, {a, c, d}, {a, d, e}, {a, e, b}};
text = DensityPlot[EuclideanDistance[{x, y, 0}, {0, 0, 12}], {x, -15, 15}, {y, -4, 4},
AspectRatio -> Automatic, Frame -> None,  PlotRangePadding -> None];
Graphics3D[{Texture[Rasterize@text],
Polygon[coords[[1]], VertexTextureCoordinates -> {{1, 1}, {1, 0}, {0, 0}, {0, 1}}],
FaceForm[Opacity[.3]], Polygon /@ Rest@coords}, Lighting -> "Neutral"]