Chapter 18
28 min read
Section 161 of 353

Triple Integrals in Spherical Coordinates

Multiple Integrals

Learning Objectives

By the end of this section, you will be able to:

  1. Convert triple integrals from Cartesian to spherical coordinates using x=ρsinϕcosθx = \rho\sin\phi\cos\theta, y=ρsinϕsinθy = \rho\sin\phi\sin\theta, z=ρcosϕz = \rho\cos\phi
  2. Derive and explain why the Jacobian factor ρ2sinϕ\rho^2\sin\phi appears in spherical integrals both geometrically and algebraically
  3. Identify 3D regions naturally described in spherical coordinates: spheres, hemispheres, cones, spherical shells, and spherical wedges
  4. Set up appropriate limits of integration for spherical regions
  5. Evaluate triple integrals over spherical regions using the formula EfdV=Ef(ρ,ϕ,θ)ρ2sinϕdρdϕdθ\iiint_E f\,dV = \iiint_E f(\rho,\phi,\theta)\,\rho^2\sin\phi\,d\rho\,d\phi\,d\theta
  6. Apply spherical integration to compute volumes, masses, moments of inertia, and gravitational potentials

The Big Picture: Why Spherical Coordinates?

"Spherical coordinates are the natural language for anything involving spheres, radial symmetry, or problems with a distinguished center point — from planetary physics to Gaussian distributions in machine learning."

Just as polar coordinates simplify 2D circular regions, spherical coordinates are the key to unlocking 3D problems with spherical symmetry. Consider computing the volume of a ball: in Cartesian coordinates, you face nested square roots like R2x2y2zR2x2y2-\sqrt{R^2-x^2-y^2} \le z \le \sqrt{R^2-x^2-y^2}. In spherical coordinates, the ball is simply 0ρR0 \le \rho \le R.

When to Use Spherical Coordinates

Ideal for Spherical Coordinates

  • Balls and spherical shells
  • Hemispheres and spherical caps
  • Cones (ice cream cone regions)
  • Integrands containing x2+y2+z2x^2+y^2+z^2
  • Gravitational and electric potentials
  • 3D Gaussian functions e(x2+y2+z2)e^{-(x^2+y^2+z^2)}
  • Problems with radial symmetry about a point

Better with Other Systems

  • Rectangular boxes (use Cartesian)
  • Cylinders and prisms (use cylindrical)
  • Regions with planar symmetry
  • Integrands simpler in x, y, z form
  • Regions bounded by planes parallel to axes

The Key Transformation

When converting from Cartesian to spherical coordinates, remember four things:

  1. Replace x=ρsinϕcosθx = \rho\sin\phi\cos\theta, y=ρsinϕsinθy = \rho\sin\phi\sin\theta, z=ρcosϕz = \rho\cos\phi
  2. Replace dV=dxdydzdV = dx\,dy\,dz with dV=ρ2sinϕdρdϕdθdV = \rho^2\sin\phi\,d\rho\,d\phi\,d\theta
  3. Use x2+y2+z2=ρ2x^2+y^2+z^2 = \rho^2 to simplify integrands
  4. Convert the region boundaries to spherical form

Historical Context

Spherical coordinates emerged from humanity's oldest scientific pursuit: understanding the heavens. Ancient astronomers described star positions using declination and right ascension — essentially spherical coordinates centered on Earth.

Leonhard Euler (1707–1783) systematized spherical coordinates and developed much of the theory of integration in curvilinear systems. His work on the gravitational potential of spherical bodies laid the foundation for spherical integration.

Pierre-Simon Laplace (1749–1827) used spherical coordinates extensively in his monumental Mécanique Céleste, developing what we now call Laplace's equation in spherical form. The spherical harmonics Ylm(θ,ϕ)Y_l^m(\theta, \phi), which arise from separating Laplace's equation in spherical coordinates, are fundamental to quantum mechanics, computer graphics, and machine learning.

The Physics Connection

Spherical coordinates are essential in physics because many fundamental forces (gravity, electrostatics) depend only on distance from a source. Newton's shell theorem — that a uniform spherical shell exerts no gravitational force on objects inside it — is elegantly proved using spherical integration.


The Spherical Coordinate System

In spherical coordinates, every point in 3D space is described by three numbers:

  • \u03C1 (rho) — the radial distance from the origin to the point (always ρ0\rho \ge 0)
  • \u03C6 (phi) — the polar angle, measured from the positive z-axis (ranges from 00 to π\pi)
  • \u03B8 (theta) — the azimuthal angle, measured from the positive x-axis in the xy-plane (ranges from 00 to 2π2\pi)

Spherical ↔ Cartesian Conversion

Spherical → Cartesian
x=ρsinϕcosθx = \rho \sin\phi \cos\theta
y=ρsinϕsinθy = \rho \sin\phi \sin\theta
z=ρcosϕz = \rho \cos\phi
Cartesian → Spherical
ρ=x2+y2+z2\rho = \sqrt{x^2 + y^2 + z^2}
ϕ=arccos(zρ)\phi = \arccos\left(\frac{z}{\rho}\right)
θ=arctan(yx)\theta = \arctan\left(\frac{y}{x}\right)

Key identity: x2+y2+z2=ρ2x^2 + y^2 + z^2 = \rho^2

Convention Alert

Some textbooks (especially in physics) swap the meanings of \u03C6 and \u03B8. In this text, \u03C6 is measured from the z-axis (polar angle) and \u03B8 is in the xy-plane (azimuthal angle). Always check conventions when consulting other sources.


Interactive Spherical Coordinate Explorer

Use this interactive tool to explore how spherical coordinates (ρ,θ,ϕ)(\rho, \theta, \phi) map to Cartesian coordinates (x,y,z)(x, y, z). Drag the sliders to see how the point moves in 3D space. Drag on the visualization to rotate the view.

Spherical Coordinates Interactive Explorer3D

Drag to rotate the view

Spherical Coordinates (\u03C1, \u03B8, \u03C6)

Cartesian Equivalent

x = \u03C1 sin(\u03C6) cos(\u03B8) = 1.531

y = \u03C1 sin(\u03C6) sin(\u03B8) = 1.531

z = \u03C1 cos(\u03C6) = 1.250

Key Insight

The point lies on a sphere of radius \u03C1 centered at the origin. \u03B8 determines the "longitude" (angle in xy-plane from x-axis), while \u03C6 determines the "latitude" (angle down from the north pole/z-axis).

What to Explore

  • Set ϕ=0\phi = 0 — the point lies on the positive z-axis (north pole)
  • Set ϕ=π/2\phi = \pi/2 — the point lies in the xy-plane (equator)
  • Set ϕ=π\phi = \pi — the point lies on the negative z-axis (south pole)
  • Keep \u03C1 and \u03C6 fixed, vary \u03B8 — the point traces a horizontal circle
  • Keep \u03C1 and \u03B8 fixed, vary \u03C6 — the point traces a meridian (longitude line)

The Spherical Volume Element: Why dV = \u03C1\u00B2 sin\u03C6 d\u03C1 d\u03C6 d\u03B8

The most important conceptual step in spherical integration is understanding why the volume element changes from dV=dxdydzdV = dx\,dy\,dz to dV=ρ2sinϕdρdϕdθdV = \rho^2\sin\phi\,d\rho\,d\phi\,d\theta. The factor ρ2sinϕ\rho^2\sin\phi is the Jacobian.

Geometric Intuition

Consider a small spherical "box" bounded by:

  • Two spheres of radii ρ\rho and ρ+dρ\rho + d\rho
  • Two cones at angles ϕ\phi and ϕ+dϕ\phi + d\phi from the z-axis
  • Two half-planes at azimuthal angles θ\theta and θ+dθ\theta + d\theta

This curvilinear box has three edge lengths:

DirectionEdge LengthExplanation
RadialSimply the change in radius
Polar (φ)ρ dφArc length on a great circle of radius ρ
Azimuthal (θ)ρ sinφ dθArc length on a circle of radius ρ sinφ

The volume is approximately the product of these three lengths:

dV(dρ)(ρdϕ)(ρsinϕdθ)=ρ2sinϕdρdϕdθdV \approx (d\rho) \cdot (\rho\,d\phi) \cdot (\rho\sin\phi\,d\theta) = \rho^2 \sin\phi\,d\rho\,d\phi\,d\theta

The factor ρ2\rho^2 comes from the two arc lengths (both proportional to \u03C1), while sinϕ\sin\phi accounts for the shrinking of horizontal circles as we approach the poles.


The Jacobian: Algebraic Derivation

The factor ρ2sinϕ\rho^2\sin\phi can also be derived rigorously using the Jacobian determinant of the coordinate transformation.

For the transformation x=ρsinϕcosθ,y=ρsinϕsinθ,z=ρcosϕx = \rho\sin\phi\cos\theta, \, y = \rho\sin\phi\sin\theta, \, z = \rho\cos\phi, the Jacobian matrix is:

J=(xρxϕxθyρyϕyθzρzϕzθ)J = \begin{pmatrix} \frac{\partial x}{\partial \rho} & \frac{\partial x}{\partial \phi} & \frac{\partial x}{\partial \theta} \\ \frac{\partial y}{\partial \rho} & \frac{\partial y}{\partial \phi} & \frac{\partial y}{\partial \theta} \\ \frac{\partial z}{\partial \rho} & \frac{\partial z}{\partial \phi} & \frac{\partial z}{\partial \theta} \end{pmatrix}

Computing the partial derivatives:

J=(sinϕcosθρcosϕcosθρsinϕsinθsinϕsinθρcosϕsinθρsinϕcosθcosϕρsinϕ0)J = \begin{pmatrix} \sin\phi\cos\theta & \rho\cos\phi\cos\theta & -\rho\sin\phi\sin\theta \\ \sin\phi\sin\theta & \rho\cos\phi\sin\theta & \rho\sin\phi\cos\theta \\ \cos\phi & -\rho\sin\phi & 0 \end{pmatrix}

The Jacobian determinant (after some calculation) is:

The Jacobian Result

J=ρ2sinϕ|J| = \rho^2 \sin\phi

Therefore: dV=dxdydz=Jdρdϕdθ=ρ2sinϕdρdϕdθdV = dx\,dy\,dz = |J|\,d\rho\,d\phi\,d\theta = \rho^2\sin\phi\,d\rho\,d\phi\,d\theta


Interactive Volume Element Demonstration

This visualization shows a spherical volume element and how its size depends on position. Adjust the radial distance \u03C1 and polar angle \u03C6 to see how the Jacobian ρ2sinϕ\rho^2\sin\phi affects the volume.

Understanding the Spherical Volume ElementInteractive

Drag to rotate. Observe how the volume element dimensions depend on position.

Volume Element Dimensions

Radial: d\u03C1 = 0.40
Arc (\u03C6): \u03C1 d\u03C6 = 0.79
Arc (\u03B8): \u03C1 sin\u03C6 d\u03B8 = 0.91

Volume Formula

dV = (d\u03C1) \u00D7 (\u03C1 d\u03C6) \u00D7 (\u03C1 sin\u03C6 d\u03B8)

dV = \u03C1\u00B2 sin\u03C6 d\u03C1 d\u03C6 d\u03B8


Current volume: 0.2849 cubic units

Key Insight

Notice how the volume element depends on both \u03C1 and \u03C6:

  • Larger \u03C1 \u2192 larger volume (proportional to \u03C1\u00B2)
  • At poles (\u03C6 = 0 or \u03C0) \u2192 volume shrinks (sin\u03C6 \u2192 0)
  • At equator (\u03C6 = \u03C0/2) \u2192 maximum arc length in \u03B8

The Complete Triple Integral Formula

Triple Integral in Spherical Coordinates

If EE is a spherical region described by αθβ\alpha \le \theta \le \beta, cϕdc \le \phi \le d, and g1(θ,ϕ)ρg2(θ,ϕ)g_1(\theta,\phi) \le \rho \le g_2(\theta,\phi), then:

Ef(x,y,z)dV=αβcdg1g2f(ρsinϕcosθ,ρsinϕsinθ,ρcosϕ)ρ2sinϕdρdϕdθ\iiint_E f(x,y,z)\,dV = \int_{\alpha}^{\beta} \int_{c}^{d} \int_{g_1}^{g_2} f(\rho\sin\phi\cos\theta, \rho\sin\phi\sin\theta, \rho\cos\phi) \cdot \rho^2\sin\phi\,d\rho\,d\phi\,d\theta

Step-by-Step Conversion Process

  1. Identify the region and determine if it has spherical symmetry
  2. Convert boundaries to spherical form:
    • x2+y2+z2=R2x^2 + y^2 + z^2 = R^2 becomes ρ=R\rho = R
    • z=0z = 0 (xy-plane) corresponds to ϕ=π/2\phi = \pi/2
    • z=x2+y2z = \sqrt{x^2+y^2} (cone) becomes ϕ=π/4\phi = \pi/4
  3. Replace the integrand: f(x,y,z)f(ρsinϕcosθ,ρsinϕsinθ,ρcosϕ)f(x,y,z) \to f(\rho\sin\phi\cos\theta, \rho\sin\phi\sin\theta, \rho\cos\phi)
  4. Add the Jacobian: Multiply by ρ2sinϕ\rho^2\sin\phi
  5. Set up limits: Usually integrate in order dρdϕdθd\rho\,d\phi\,d\theta
  6. Evaluate the iterated integral

Common Spherical Regions

Spherical coordinates make certain 3D regions particularly simple to describe:

RegionDescriptionLimitsVolume
BallSolid sphere of radius Rρ: 0 to R, φ: 0 to π, θ: 0 to 2π(4/3)πR³
HemisphereUpper half of ball (z ≥ 0)ρ: 0 to R, φ: 0 to π/2, θ: 0 to 2π(2/3)πR³
Spherical shellBetween radii a and bρ: a to b, φ: 0 to π, θ: 0 to 2π(4/3)π(b³-a³)
Spherical capSphere above z = hρ: h/cosφ to R, φ: 0 to arccos(h/R), θ: 0 to 2ππh²(3R-h)/3
Ice cream coneCone φ < α inside sphereρ: 0 to R, φ: 0 to α, θ: 0 to 2π(2/3)πR³(1-cosα)
WedgeSector in θρ: 0 to R, φ: 0 to π, θ: 0 to α(2/3)αR³

Interactive Spherical Integral Visualizer

Explore different spherical regions and see how they are partitioned for integration. The animation shows the integration process sweeping through the region. Observe how the volume element dV=ρ2sinϕdρdϕdθdV = \rho^2\sin\phi\,d\rho\,d\phi\,d\theta varies throughout the domain.

Triple Integrals in Spherical Coordinates3D Interactive

Drag to rotate the view

Volume Element

dV = \u03C1\u00B2 sin\u03C6 d\u03C1 d\u03C6 d\u03B8

The factor \u03C1\u00B2 sin\u03C6 is the Jacobian determinant for the spherical coordinate transformation.

Integration Order

For most spherical regions, we integrate in the order d\u03C1 d\u03C6 d\u03B8. The innermost integral (over \u03C1) creates thin shells, the middle integral (over \u03C6) sweeps from pole to pole, and the outermost (over \u03B8) sweeps around the full circle.


Worked Examples

Example 1: Volume of a Sphere

Find the volume of a ball of radius RR centered at the origin.

Solution: We integrate f=1f = 1 over the ball with the Jacobian.

V=B1dV=02π0π0Rρ2sinϕdρdϕdθV = \iiint_B 1\,dV = \int_0^{2\pi} \int_0^{\pi} \int_0^R \rho^2\sin\phi\,d\rho\,d\phi\,d\theta
=02πdθ0πsinϕdϕ0Rρ2dρ= \int_0^{2\pi} d\theta \cdot \int_0^{\pi} \sin\phi\,d\phi \cdot \int_0^R \rho^2\,d\rho
=2π[cosϕ]0π[ρ33]0R= 2\pi \cdot [-\cos\phi]_0^{\pi} \cdot \left[\frac{\rho^3}{3}\right]_0^R
=2π2R33=4πR33= 2\pi \cdot 2 \cdot \frac{R^3}{3} = \frac{4\pi R^3}{3}

This is the famous formula for the volume of a sphere!

Example 2: Mass with Variable Density

Find the mass of a ball of radius 2 with density δ(ρ)=ρ\delta(\rho) = \rho (density proportional to distance from center).

Solution: Mass is the integral of density over the region.

M=Bρρ2sinϕdρdϕdθ=02π0π02ρ3sinϕdρdϕdθM = \iiint_B \rho \cdot \rho^2\sin\phi\,d\rho\,d\phi\,d\theta = \int_0^{2\pi} \int_0^{\pi} \int_0^2 \rho^3\sin\phi\,d\rho\,d\phi\,d\theta
=2π2[ρ44]02=4π164=16π= 2\pi \cdot 2 \cdot \left[\frac{\rho^4}{4}\right]_0^2 = 4\pi \cdot \frac{16}{4} = 16\pi

Example 3: The 3D Gaussian Integral

Evaluate I=R3e(x2+y2+z2)dVI = \iiint_{\mathbb{R}^3} e^{-(x^2+y^2+z^2)}\,dV.

Solution: Since x2+y2+z2=ρ2x^2+y^2+z^2 = \rho^2, this becomes elegant in spherical coordinates.

I=02π0π0eρ2ρ2sinϕdρdϕdθI = \int_0^{2\pi} \int_0^{\pi} \int_0^{\infty} e^{-\rho^2} \cdot \rho^2\sin\phi\,d\rho\,d\phi\,d\theta

The integrals separate:

=(02πdθ)(0πsinϕdϕ)(0ρ2eρ2dρ)= \left(\int_0^{2\pi} d\theta\right) \left(\int_0^{\pi} \sin\phi\,d\phi\right) \left(\int_0^{\infty} \rho^2 e^{-\rho^2}\,d\rho\right)
=2π2π4=π3/2= 2\pi \cdot 2 \cdot \frac{\sqrt{\pi}}{4} = \pi^{3/2}

The 3D Gaussian integral is π3/2\pi^{3/2}!

Normalization Connection

This result implies that the normalized 3D Gaussian density is 1π3/2e(x2+y2+z2)\frac{1}{\pi^{3/2}} e^{-(x^2+y^2+z^2)}. This appears throughout statistical mechanics, quantum mechanics, and machine learning (e.g., in Gaussian mixture models and RBF kernels).

Example 4: Volume of an Ice Cream Cone

Find the volume of the region inside the sphere ρ=2\rho = 2 and above the cone ϕ=π/3\phi = \pi/3.

Solution: The region is bounded by 0ρ20 \le \rho \le 2, 0ϕπ/30 \le \phi \le \pi/3, 0θ2π0 \le \theta \le 2\pi.

V=02π0π/302ρ2sinϕdρdϕdθV = \int_0^{2\pi} \int_0^{\pi/3} \int_0^2 \rho^2\sin\phi\,d\rho\,d\phi\,d\theta
=2π[cosϕ]0π/383= 2\pi \cdot \left[-\cos\phi\right]_0^{\pi/3} \cdot \frac{8}{3}
=2π(12+1)83=2π1283=8π3= 2\pi \cdot \left(-\frac{1}{2} + 1\right) \cdot \frac{8}{3} = 2\pi \cdot \frac{1}{2} \cdot \frac{8}{3} = \frac{8\pi}{3}

Applications in Science and Engineering

Physics: Gravitational Potential

The gravitational potential at distance rr from a uniform spherical shell of radius RR and mass MM is computed using spherical integration. Newton's shell theorem follows: inside the shell, the potential is constant (no net force), and outside, it behaves as if all mass were at the center.

Quantum Mechanics: Atomic Orbitals

The wave functions of the hydrogen atom are separable in spherical coordinates:

ψnlm(r,θ,ϕ)=Rnl(r)Ylm(θ,ϕ)\psi_{nlm}(r, \theta, \phi) = R_{nl}(r) \cdot Y_l^m(\theta, \phi)

Normalization integrals ψ2ρ2sinϕdρdϕdθ=1\int |\psi|^2 \rho^2\sin\phi\,d\rho\,d\phi\,d\theta = 1 are natural in spherical coordinates. The spherical harmonics YlmY_l^m arise from solving Laplace's equation.

Engineering: Antenna Radiation Patterns

The power radiated by an antenna in different directions is described in spherical coordinates. The total radiated power is:

Prad=02π0πU(θ,ϕ)sinϕdϕdθP_{rad} = \int_0^{2\pi} \int_0^{\pi} U(\theta, \phi) \sin\phi\,d\phi\,d\theta

where U(θ,ϕ)U(\theta, \phi) is the radiation intensity.


Applications in Machine Learning

Gaussian Mixture Models

In 3D GMMs, the normalization constant for each Gaussian component involves the integral e12(xμ)TΣ1(xμ)d3x\int e^{-\frac{1}{2}(x-\mu)^T\Sigma^{-1}(x-\mu)} d^3x, which is elegantly computed in spherical coordinates after diagonalizing the covariance matrix.

RBF Neural Networks

Radial Basis Function networks use kernels of the form ϕ(r)=er2/2σ2\phi(r) = e^{-r^2/2\sigma^2}. Understanding their behavior in 3D (and higher) dimensions requires integrating over spherical shells.

Spherical Harmonics in Graphics

In neural rendering and environment mapping, spherical harmonics provide a basis for representing lighting and radiance fields. Computing SH coefficients involves spherical integration of the form f(θ,ϕ)Ylm(θ,ϕ)sinϕdϕdθ\int f(\theta,\phi) Y_l^m(\theta,\phi) \sin\phi\,d\phi\,d\theta.

High-Dimensional Balls

Understanding why high-dimensional data "concentrates near the surface" of a ball comes from the spherical volume element: most of the volume is at largeρ\rho because of the ρd1\rho^{d-1} factor in d dimensions.


Python Implementation

Numerical Spherical Integration

Triple Integrals in Spherical Coordinates
🐍spherical_integration.py
3Spherical Triple Integration

This function numerically computes triple integrals in spherical coordinates. The key is including the Jacobian factor ρ² sinφ in the integrand.

18The Jacobian Factor

When converting to spherical coordinates, we must multiply by ρ² sinφ. This is the Jacobian determinant that accounts for the stretching of volume elements.

42Volume of a Sphere

To find volume, we integrate f = 1 with the Jacobian. The result is (4/3)πR³, the famous sphere volume formula.

52Variable Density

When density varies with position (here ρ²), spherical coordinates make the integration natural. The total mass involves ∫∫∫ ρ² · ρ² sinφ dρ dφ dθ.

63Spherical Cap

A spherical cap (portion of sphere above a plane) has variable ρ bounds that depend on φ. This shows the power of spherical coordinates for such regions.

73 lines without explanation
1import numpy as np
2from scipy import integrate
3import matplotlib.pyplot as plt
4from mpl_toolkits.mplot3d import Axes3D
5
6def spherical_triple_integral(f, rho_bounds, phi_bounds, theta_bounds):
7    """
8    Compute a triple integral in spherical coordinates.
9
10    The integral is: ∫∫∫ f(ρ,φ,θ) ρ² sin(φ) dρ dφ dθ
11
12    Parameters:
13    - f: function of (rho, phi, theta) to integrate
14    - rho_bounds: (rho_min, rho_max) or functions of (phi, theta)
15    - phi_bounds: (phi_min, phi_max) or functions of theta
16    - theta_bounds: (theta_min, theta_max)
17
18    Returns: approximate value of the integral
19    """
20    def integrand(rho, phi, theta):
21        # Include Jacobian: ρ² sin(φ)
22        return f(rho, phi, theta) * rho**2 * np.sin(phi)
23
24    # Unpack bounds
25    theta_min, theta_max = theta_bounds
26
27    def phi_integral(theta):
28        phi_min = phi_bounds[0](theta) if callable(phi_bounds[0]) else phi_bounds[0]
29        phi_max = phi_bounds[1](theta) if callable(phi_bounds[1]) else phi_bounds[1]
30
31        def rho_integral(phi):
32            rho_min = rho_bounds[0](phi, theta) if callable(rho_bounds[0]) else rho_bounds[0]
33            rho_max = rho_bounds[1](phi, theta) if callable(rho_bounds[1]) else rho_bounds[1]
34            result, _ = integrate.quad(lambda r: integrand(r, phi, theta), rho_min, rho_max)
35            return result
36
37        result, _ = integrate.quad(rho_integral, phi_min, phi_max)
38        return result
39
40    result, _ = integrate.quad(phi_integral, theta_min, theta_max)
41    return result
42
43# Example 1: Volume of a sphere of radius R
44R = 2.0
45f_constant = lambda rho, phi, theta: 1
46
47volume_sphere = spherical_triple_integral(
48    f=f_constant,
49    rho_bounds=(0, R),
50    phi_bounds=(0, np.pi),
51    theta_bounds=(0, 2*np.pi)
52)
53print(f"Volume of sphere (radius {R}): {volume_sphere:.6f}")
54print(f"Expected (4πR³/3): {4*np.pi*R**3/3:.6f}")
55
56# Example 2: Mass of a sphere with density ρ(r) = r²
57def density_r_squared(rho, phi, theta):
58    return rho**2
59
60mass = spherical_triple_integral(
61    f=density_r_squared,
62    rho_bounds=(0, R),
63    phi_bounds=(0, np.pi),
64    theta_bounds=(0, 2*np.pi)
65)
66print(f"\nMass with density ρ² over sphere radius {R}: {mass:.6f}")
67print(f"Expected (4πR⁵/5): {4*np.pi*R**5/5:.6f}")
68
69# Example 3: Volume of a spherical cap (z ≥ 1 inside unit sphere)
70# The cap is where ρ cos(φ) ≥ 1 and ρ ≤ 2
71h = 1  # Height of cap from z = 1 to z = 2
72volume_cap = spherical_triple_integral(
73    f=f_constant,
74    rho_bounds=(lambda phi, theta: 1/np.cos(phi) if np.cos(phi) > 0.001 else 1000, 2),
75    phi_bounds=(0, np.arccos(1/2)),  # φ where ρ=2 gives z=1
76    theta_bounds=(0, 2*np.pi)
77)
78print(f"\nVolume of spherical cap (z ≥ 1, ρ ≤ 2): {volume_cap:.4f}")

Visualization of Volume Elements

Visualizing Spherical Volume Elements
🐍spherical_visualization.py
6Volume Element Visualization

This function creates both a 3D view of the volume element and a contour plot showing how the element size varies with position in the sphere.

23Curved Surfaces

The volume element has curved faces (constant ρ surfaces are spheres). This is fundamentally different from Cartesian boxes or cylindrical wedges.

44Position Dependence

The contour plot shows that volume elements are largest at the equator (sinφ = 1) and at large ρ. Near the poles and origin, elements shrink.

58Physical Dimensions

The three edge lengths of the element are dρ (radial), ρ dφ (polar arc), and ρ sinφ dθ (azimuthal arc). Their product gives dV.

73 lines without explanation
1import numpy as np
2import matplotlib.pyplot as plt
3from mpl_toolkits.mplot3d import Axes3D
4
5def visualize_spherical_volume_element(rho=2, phi=np.pi/3, theta=np.pi/4,
6                                        d_rho=0.3, d_phi=np.pi/8, d_theta=np.pi/6):
7    """
8    Visualize a spherical volume element dV = ρ² sin(φ) dρ dφ dθ.
9    Shows how the element depends on position.
10    """
11    fig = plt.figure(figsize=(14, 6))
12
13    # 3D view of volume element
14    ax1 = fig.add_subplot(121, projection='3d')
15
16    # Create the spherical volume element
17    rho_vals = np.linspace(rho - d_rho/2, rho + d_rho/2, 3)
18    phi_vals = np.linspace(phi - d_phi/2, phi + d_phi/2, 20)
19    theta_vals = np.linspace(theta - d_theta/2, theta + d_theta/2, 20)
20
21    # Draw the curved surfaces
22    for r in [rho_vals[0], rho_vals[-1]]:
23        PHI, THETA = np.meshgrid(phi_vals, theta_vals)
24        X = r * np.sin(PHI) * np.cos(THETA)
25        Y = r * np.sin(PHI) * np.sin(THETA)
26        Z = r * np.cos(PHI)
27        ax1.plot_surface(X, Y, Z, alpha=0.3, color='orange')
28
29    # Draw wireframe of reference sphere
30    phi_sphere = np.linspace(0, np.pi, 30)
31    theta_sphere = np.linspace(0, 2*np.pi, 40)
32    PHI_S, THETA_S = np.meshgrid(phi_sphere, theta_sphere)
33    X_S = rho * np.sin(PHI_S) * np.cos(THETA_S)
34    Y_S = rho * np.sin(PHI_S) * np.sin(THETA_S)
35    Z_S = rho * np.cos(PHI_S)
36    ax1.plot_wireframe(X_S, Y_S, Z_S, alpha=0.1, color='blue')
37
38    ax1.set_xlabel('X')
39    ax1.set_ylabel('Y')
40    ax1.set_zlabel('Z')
41    ax1.set_title(f'Volume Element at (ρ={rho:.1f}, φ={phi*180/np.pi:.0f}°, θ={theta*180/np.pi:.0f}°)')
42
43    # Show how volume varies with position
44    ax2 = fig.add_subplot(122)
45
46    phi_range = np.linspace(0.1, np.pi - 0.1, 50)
47    rho_range = np.linspace(0.5, 3, 50)
48
49    PHI, RHO = np.meshgrid(phi_range, rho_range)
50    # Volume element size proportional to ρ² sin(φ)
51    dV = RHO**2 * np.sin(PHI)
52
53    contour = ax2.contourf(PHI * 180 / np.pi, RHO, dV, levels=20, cmap='viridis')
54    plt.colorbar(contour, ax=ax2, label='Relative volume element size')
55
56    ax2.set_xlabel('φ (degrees from z-axis)')
57    ax2.set_ylabel('ρ (radial distance)')
58    ax2.set_title('Volume Element Size: dV ∝ ρ² sin(φ)')
59
60    # Mark current position
61    ax2.scatter([phi * 180 / np.pi], [rho], color='red', s=100, marker='*',
62                label=f'Current: dV = {rho**2 * np.sin(phi):.2f}')
63    ax2.legend()
64
65    plt.tight_layout()
66    plt.savefig('spherical_volume_element.png', dpi=150)
67    plt.show()
68
69    # Calculate actual volume
70    actual_dV = rho**2 * np.sin(phi) * d_rho * d_phi * d_theta
71    print(f"Volume element dimensions:")
72    print(f"  Radial: dρ = {d_rho:.3f}")
73    print(f"  φ arc length: ρ dφ = {rho * d_phi:.3f}")
74    print(f"  θ arc length: ρ sin(φ) dθ = {rho * np.sin(phi) * d_theta:.3f}")
75    print(f"  dV = ρ² sin(φ) dρ dφ dθ = {actual_dV:.6f}")
76
77visualize_spherical_volume_element()

Common Mistakes to Avoid

Mistake 1: Forgetting the Jacobian

The most common error is writing dV=dρdϕdθdV = d\rho\,d\phi\,d\theta instead of dV=ρ2sinϕdρdϕdθdV = \rho^2\sin\phi\,d\rho\,d\phi\,d\theta. Without the Jacobian, you will get the wrong answer. The factor ρ2sinϕ\rho^2\sin\phi is essential!

Mistake 2: Wrong Limits for \u03C6

For a full sphere, ϕ\phi goes from 00 to π\pi, not from 00 to 2π2\pi. The polar angle \u03C6 only needs to go from the "north pole" to the "south pole" — that's already the full sphere when combined with θ\theta going from 0 to 2\u03C0.

Mistake 3: Confusing \u03C6 and \u03B8

Remember: ϕ\phi is the angle from the z-axis (0 to \u03C0), and θ\theta is the angle in the xy-plane (0 to 2\u03C0). This is the mathematics convention. Physics texts often swap these!

Mistake 4: Not Converting the Integrand

If the Cartesian integrand is f(x,y,z)=zf(x,y,z) = z, you must write f=ρcosϕf = \rho\cos\phi in spherical coordinates. Don't leave Cartesian variables in your spherical integral!

Pro Tip: Check with Known Results

After computing a spherical integral, verify with known results:

  • Volume of a ball of radius 2 = (4/3)\u03C0(8) = 32\u03C0/3 \u2248 33.51
  • Volume of a hemisphere of radius 2 = (2/3)\u03C0(8) = 16\u03C0/3 \u2248 16.76
  • Surface area of a sphere of radius R = 4\u03C0R\u00B2

Test Your Understanding

Test Your Understanding1/8
Score: 0
What is the volume element (Jacobian) in spherical coordinates?

Summary

Triple integrals in spherical coordinates are essential tools for evaluating integrals over regions with spherical symmetry. The key insight is understanding why and how the volume element transforms.

Key Formulas

ConceptFormulaNotes
Coordinate transformx = ρ sinφ cosθ, y = ρ sinφ sinθ, z = ρ cosφBasic conversion
Volume elementdV = ρ² sinφ dρ dφ dθThe Jacobian is ρ² sinφ
Key identityx² + y² + z² = ρ²Simplifies many integrands
Full ballρ: 0 to R, φ: 0 to π, θ: 0 to 2πVolume = (4/3)πR³
Hemisphere (z ≥ 0)ρ: 0 to R, φ: 0 to π/2, θ: 0 to 2πHalf the ball
3D Gaussian∫∫∫ e^{-ρ²} ρ² sinφ dρ dφ dθ = π^{3/2}Famous result

Key Takeaways

  1. Spherical coordinates simplify spherical regions — what requires nested square roots in Cartesian becomes simple constant bounds
  2. The Jacobian factor \u03C1\u00B2 sin\u03C6 is essential — it accounts for the stretching of volume elements as we move outward and toward the equator
  3. The \u03C6 limits are 0 to \u03C0, not 0 to 2\u03C0 — the polar angle only needs to sweep from pole to pole
  4. Convert everything: the integrand, the limits, and the volume element
  5. The 3D Gaussian integral eρ2ρ2sinϕdρdϕdθ=π3/2\int e^{-\rho^2} \rho^2\sin\phi\,d\rho\,d\phi\,d\theta = \pi^{3/2} is derived using spherical coordinates — fundamental to statistics and physics
  6. Spherical harmonics and many physical potentials are naturally expressed and integrated in spherical coordinates
The Essence of Spherical Integration:
"Spheres become constants, cones become constant angles, and the Jacobian \u03C1\u00B2 sin\u03C6 reminds us that volume elements grow with distance and shrink near the poles."
Coming Next: In the next section, we'll explore Change of Variables in Multiple Integrals, generalizing the Jacobian technique to arbitrary coordinate transformations.
Loading comments...