Examples - geometric figures

Cuboid (Box, Rectangular Prism)

L=5; W=6; H=4;
print "Cuboid
 volume=", L*W*H, "
 surface area=", 2*(L*W+W*H+L*H), "
 diagonal=", abs(L,W,H)
Cuboid

Triangular Prism

b=5; /* triangle base length */
h=4; /* triangle height */
l=5; /* prism height */
print "Triangular prism
 volume=", b*h*l/2, "
 side=", s=hypot(b/2,h), "
 surface area=", b*(h+l)+2*l*s
Triangular Prism

Cylinder

R=6; /* radius */
H=4; /* height */
print "Cylinder
 volume=", pi*R^2*H, "
 surface area=", 2*pi*R*(R+H)
Cylinder

Cone

R=6; /* radius */
H=4; /* height */
print "Cone
 volume=", pi*R^2*H/3, "
 surface area=", pi*R*(R+hypot(R,H))
Cone

Truncated Cone (Topless Cone)

R1=6; /* the first base radius */
R2=3; /* the second base radius */
H=4;  /* height */
print "Truncated cone
 volume=", pi*(R1^2+R1*R2+R2^2)*H/3, "
 surface area=", pi*(R1^2+R2^2+(R1+R2)*hypot(R1-R2,H))
Truncated Cone

Sphere

r=5; /* radius */
print "Sphere
 volume=", 4/3*pi*r^3, "
 surface area=", 4*pi*r^2
Sphere

Spherical Cap

h=3; /* height of cap */
r=6; /* radius of sphere */
print "Spherical cap
 volume=", pi*h^2*(r-h/3), "
 area of the zone=", 2*pi*r*h, "
 total surface area with base=", pi*h*(4*r-h)
Spherical Cap

Spherical Cone (Closed Spherical Sector)

h=3; /* height of cap */
R=6; /* radius of sphere */
print "Spherical cone
 volume=", 2/3*pi*R^2*h, "
 surface area=", pi*R*(2*h+sqrt(h*(2*R-h)))
Spherical Cone

Spherical Segment (Sphere 2 Base Segment)

a=6; /* the first base radius */
b=4; /* the second base radius */
h=3; /* height */
print "Spherical segment
 volume=", pi/2*h*(a^2+b^2+h^2/3), "
 radius of sphere=", r=hypot(a,(a^2-b^2-h^2)/2/h), "
 area of the zone=", 2*pi*r*h, "
 total surface area with bases=", pi*(2*r*h+a^2+b^2)
Spherical Segment

Spherical Wedge

r=6;  /* radius of sphere */
a=30; /* angle in degrees */
print "Spherical wedge
 volume=", pi/270*r^3*a, "
 area of the lune=", pi/90*r^2*a, "
 total surface area=", pi*r^2*(a/90+1)
Spherical Wedge

Torus

R=6; /* radius of the torus */
s=3; /* radius of the tube */
print "Torus
 volume=", 2*pi^2*R*s^2, "
 surface area=", 4*pi^2*R*s
Torus

Pyramid - square base

A=5; /* length of pyramid base */
H=4; /* height of pyramid */
print "Pyramid
 volume=", A^2*H/3, "
 surface area=", A*(2*hypot(A/2,H)+A)
Pyramid

Pyramid - rectangular base

L=5; /* length of pyramid base */
W=6; /* width of pyramid base */
H=4; /* height of pyramid */
print "Pyramid
 volume=", L*W*H/3, "
 surface area=", L*hypot(W/2,H)+W*hypot(L/2,H)+L*W
Pyramid

Pyramidal Frustum (Truncated Pyramid) - square bases

a1=2; /* length of the first base  */
a2=1; /* length of the second base */
h=3;  /* height */
print "Pyramidal frustum
 volume=", h/3*(a1^2+a1*a2+a2^2), "
 surface area=",(a1^2+a2^2+2*(a1+a2)*hypot(h,(a1-a2)/2))
Frustum of a Pyramid

Pyramidal Frustum (Truncated Pyramid) - rectangular bases

a=4; b=6; /* the first base */
c=2; d=3; /* the second base */
h=3;      /* height */
print "Pyramidal frustum
 volume=", h/3*(a*b+c*d+(a*d+b*c)/2), "
 surface area=", a*b+c*d+(a+c)*hypot(h,(b-d)/2)+
  (b+d)*hypot(h,(a-c)/2)
Frustum of a Pyramid

Regular Tetrahedron (Triangular Pyramid)

S=6; /* edge length */
print "Regular tetrahedron
 volume=", sqrt(2)/12*S^3, "
 surface area=", S^2*sqrt(3)
Tetrahedron