P2.7.4Volume and surface area of a right regular pyramid
A right regular pyramid with height \(h\) and a base consisting of a regular \(n\)-sided polygon of side length \(s\) has a volume, \(V = \frac{1}{3}Ah\) and total surface area, \(S = A + \frac{1}{2}nsl\) where \(A\) is the base area and \(l\) the slant height which may be calculated from the apothem of the base polygon, \(a = \frac{1}{2}s\cot\frac{\pi}{n}\) as \(A = \frac{1}{2}nsa\) and \(l = \sqrt{h^2 + a^2}\).
Use these formulae to define a function, pyramid_AV returning \(V\) and \(S\) when passed values for \(n\), \(s\) and \(h\).
Show solution
The code below is self-explanatory.
import math
def pyramid_AV(n, s, h):
""" Returns V, S for a right regular polygonal pyramid.
Returns the volume and total surface area of the right regular pyramid
of height h with a base of a regular n-gon of side s.
"""
a = s / 2 / math.tan(math.pi / n) # apothem
A = n * s * a / 2 # base area
l = math.hypot(h, a) # slant height
V = A * h / 3
S = A + n * s * l / 2
return V, S
print(pyramid_AV(5, 36.5, 12))
The volume and surface area are reported to be:
(9168.424067738604, 4832.337304213042)