Chapter 15
20 min read
Section 140 of 353

Cylindrical and Spherical Coordinates

Vectors and the Geometry of Space

Learning Objectives

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

  1. Understand the geometric meaning of cylindrical coordinates (r,θ,z)(r, \theta, z) and when they simplify problems
  2. Understand the geometric meaning of spherical coordinates (ρ,θ,ϕ)(\rho, \theta, \phi) and their relationship to latitude/longitude
  3. Convert between Cartesian, cylindrical, and spherical coordinate systems
  4. Derive the volume elements (Jacobians) for cylindrical and spherical coordinates
  5. Apply these coordinate systems to simplify integration problems
  6. Recognize applications in physics, engineering, and machine learning

The Big Picture: Beyond Cartesian Coordinates

"The art of choosing the right coordinate system is the art of making the impossible tractable." — Mathematical Wisdom

Cartesian coordinates (x,y,z)(x, y, z) are powerful and intuitive, but they are not always the best choice. Many natural objects and physical phenomena exhibit symmetry that Cartesian coordinates cannot easily capture:

  • Cylinders, pipes, and towers have circular cross-sections and vertical axes
  • Spheres, planets, and atoms are naturally described by distance from a center
  • Rotation problems involve angles rather than linear displacements
  • Wave propagation often spreads radially from a source

The Key Insight

The right coordinate system matches the symmetry of your problem. A sphere described in Cartesian coordinates requires the equation x2+y2+z2=R2x^2 + y^2 + z^2 = R^2. In spherical coordinates, the same sphere is simply ρ=R\rho = R — a single constant! This simplification makes integration, differentiation, and visualization dramatically easier.

This section introduces two essential coordinate systems that complement Cartesian coordinates:

Coordinate SystemBest ForKey Variables
Cartesian (x, y, z)Rectangular regions, linear problemsx, y, z (distances along axes)
Cylindrical (r, θ, z)Cylinders, pipes, axial symmetryr (radial), θ (angular), z (height)
Spherical (ρ, θ, φ)Spheres, radial symmetry, 3D anglesρ (distance), θ (azimuth), φ (polar)

Historical Origins: The Evolution of Coordinate Systems

The development of non-Cartesian coordinate systems arose from practical needs in astronomy, physics, and engineering.

Ancient Astronomy and Celestial Coordinates

Long before René Descartes formalized Cartesian coordinates in 1637, astronomers used spherical-like systems to map the heavens. The celestial sphere — an imaginary sphere surrounding Earth — was described using:

  • Declination: Angle above or below the celestial equator (like latitude)
  • Right Ascension: Angle along the celestial equator (like longitude)

This is essentially a spherical coordinate system with Earth at the center.

Newton and Gravitational Fields (1687)

Isaac Newton's law of gravitation describes force as inversely proportional to the square of distance: F1/r2F \propto 1/r^2. This radial dependence makes spherical coordinates natural for gravitational problems. Newton himself used geometric arguments that implicitly relied on spherical symmetry.

Euler and the Formalization (1750s)

Leonhard Euler systematically developed the mathematical framework for cylindrical and spherical coordinates, including:

  • Explicit conversion formulas between coordinate systems
  • Expressions for arc length, area, and volume elements
  • Methods for transforming differential equations

Laplace and Potential Theory (1785)

Pierre-Simon Laplace expressed his famous equation 2ϕ=0\nabla^2 \phi = 0 in spherical coordinates, enabling solutions for gravitational and electrostatic potentials around spherical bodies. This became foundational for mathematical physics.


Cylindrical Coordinates

Cylindrical coordinates extend polar coordinates into three dimensions by adding a height coordinate zz. A point is specified by three values:

Cylindrical Coordinates (r,θ,z)(r, \theta, z)

  • rr: The radial distance from the z-axis to the point (in the xy-plane). Range: r0r \geq 0
  • θ\theta: The angle from the positive x-axis, measured counterclockwise in the xy-plane. Range: 0θ<2π0 \leq \theta < 2\pi
  • zz: The height above (or below) the xy-plane. Range: <z<-\infty < z < \infty
Cylindrical Coordinates Interactive Explorer3D

Drag to rotate the view

Cylindrical Coordinates (r, \u03B8, z)

Cartesian Equivalent

x = r cos(\u03B8) = 1.414

y = r sin(\u03B8) = 1.414

z = 1.500

Key Insight

Cylindrical coordinates extend polar coordinates into 3D by adding a height z. The point lies on a cylinder of radius r, at angle \u03B8 from the positive x-axis, and height z above the xy-plane.

Conversion Formulas: Cylindrical ↔ Cartesian

Cylindrical → Cartesian

x=rcosθx = r \cos\theta

y=rsinθy = r \sin\theta

z=zz = z

Cartesian → Cylindrical

r=x2+y2r = \sqrt{x^2 + y^2}

θ=arctan(y/x)\theta = \arctan(y/x) (with quadrant correction)

z=zz = z

Using arctan2 for θ

The standard arctan(y/x)\arctan(y/x) only gives angles in (π/2,π/2)(-\pi/2, \pi/2). To get the correct angle in all four quadrants, use the atan2(y, x) function available in most programming languages. This function considers the signs of both x and y to determine the correct quadrant.

Geometric Interpretation

Think of cylindrical coordinates as describing a point by:

  1. How far is it from the central axis (the z-axis)? This is rr.
  2. In what direction around the axis? This is θ\theta.
  3. How high up or down? This is zz.

The name "cylindrical" comes from the fact that surfaces of constant rr are cylinders centered on the z-axis.


Spherical Coordinates

Spherical coordinates describe a point by its distance from the origin and two angles. This system is ideal for problems with radial symmetry.

Spherical Coordinates (ρ,θ,ϕ)(\rho, \theta, \phi)

  • ρ\rho (rho): The radial distance from the origin to the point. Range: ρ0\rho \geq 0
  • θ\theta (theta): The azimuthal angle in the xy-plane from the positive x-axis. Range: 0θ<2π0 \leq \theta < 2\pi
  • ϕ\phi (phi): The polar angle from the positive z-axis. Range: 0ϕπ0 \leq \phi \leq \pi
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).

Convention Alert

Different textbooks and fields use different conventions for spherical coordinates. In physics, ϕ\phi is often the azimuthal angle and θ\theta is the polar angle — the opposite of our convention. Always check which convention is being used!

Conversion Formulas: Spherical ↔ Cartesian

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}

θ=arctan(y/x)\theta = \arctan(y/x)

ϕ=arccos(z/ρ)\phi = \arccos(z/\rho)

Understanding the Angles

The two angles in spherical coordinates have distinct roles:

  • θ\theta (azimuthal angle): Like longitude on Earth, this angle sweeps around the z-axis in the xy-plane. It determines the "compass direction."
  • ϕ\phi (polar angle): Like colatitude (90° - latitude), this angle measures how far "down" from the north pole (positive z-axis) the point is.ϕ=0\phi = 0 is the north pole, ϕ=π/2\phi = \pi/2 is the equator, and ϕ=π\phi = \pi is the south pole.

Earth Coordinates Comparison

Geographic coordinates use latitude (measured from the equator, ±90°) instead of the polar angle φ (measured from the north pole, 0 to 180°). The relationship is: ϕ=90°latitude\phi = 90° - \text{latitude}.


Conversion Formulas

Use this interactive calculator to convert between all three coordinate systems:

Coordinate Conversion Calculator

Cartesian (x, y, z)

Cylindrical (r, \u03B8, z)

r = 1.414

\u03B8 = 45.000\u00B0

z = 1.000

r = \u221A(x\u00B2 + y\u00B2)

\u03B8 = atan2(y, x)

z = z

Spherical (\u03C1, \u03B8, \u03C6)

\u03C1 = 1.732

\u03B8 = 45.000\u00B0

\u03C6 = 54.736\u00B0

\u03C1 = \u221A(x\u00B2 + y\u00B2 + z\u00B2)

\u03B8 = atan2(y, x)

\u03C6 = arccos(z/\u03C1)

Cylindrical ↔ Spherical Conversions

Sometimes you need to convert directly between cylindrical and spherical coordinates:

Cylindrical → Spherical

ρ=r2+z2\rho = \sqrt{r^2 + z^2}

θ=θ\theta = \theta (unchanged)

ϕ=arctan(r/z)\phi = \arctan(r/z)

Spherical → Cylindrical

r=ρsinϕr = \rho \sin\phi

θ=θ\theta = \theta (unchanged)

z=ρcosϕz = \rho \cos\phi

Notice that θ\theta is the same in both systems — both measure the angle in the xy-plane from the positive x-axis.


Volume Elements and Jacobians

When changing coordinates in an integral, we must account for how the coordinate transformation stretches or compresses space. This is captured by the Jacobian.

Cylindrical Coordinates: dV = r dr dθ dz

In cylindrical coordinates, the volume element is:

dV=rdrdθdzdV = r \, dr \, d\theta \, dz

The factor of rr appears because:

  • A small change dθd\theta sweeps out an arc of length rdθr \cdot d\theta
  • Near the z-axis (r0r \approx 0), this arc is tiny
  • Far from the z-axis, the same dθd\theta covers more space

Spherical Coordinates: dV = ρ² sin(φ) dρ dθ dφ

In spherical coordinates, the volume element is:

dV=ρ2sinϕdρdθdϕdV = \rho^2 \sin\phi \, d\rho \, d\theta \, d\phi

This Jacobian has two factors:

  • ρ2\rho^2: Spherical shells have area proportional to ρ2\rho^2 (surface area of sphere = 4πρ24\pi\rho^2)
  • sinϕ\sin\phi: Circles of latitude shrink near the poles. At ϕ=0\phi = 0 (north pole), the circumference is zero; at ϕ=π/2\phi = \pi/2 (equator), it's maximum.

Why the Jacobian Matters

Forgetting the Jacobian is one of the most common errors in multivariable calculus. When you change variables in an integral, you must multiply by the absolute value of the Jacobian determinant. For our standard coordinate systems:

  • Cartesian: J=1|J| = 1
  • Cylindrical: J=r|J| = r
  • Spherical: J=ρ2sinϕ|J| = \rho^2 \sin\phi

Real-World Applications

Real-World ApplicationsInteractive

V = \u222B\u222B\u222B r dr d\u03B8 dz = \u03C0r\u00B2h = 14.137

Volume Integration in Cylindrical Coordinates

Cylindrical coordinates are ideal for integrating over cylindrical regions. The volume element is:

dV = r dr d\u03B8 dz

The factor of r appears because as r increases, the arc length for a given d\u03B8 also increases. This is the Jacobian of the transformation.

Applications: Pipes, tanks, magnetic fields around wires, heat distribution in rods, fluid flow in tubes.

When to Use Each Coordinate System

Problem TypeBest CoordinatesWhy
Cylinder, pipe, wireCylindricalr = constant defines cylinders
Sphere, planet, atomSphericalρ = constant defines spheres
Rotation around z-axisCylindricalθ captures rotational symmetry
Radial force (gravity)SphericalForce depends only on ρ
Helical motionCylindricalCombines rotation (θ) with height (z)
Rectangular boxCartesianBoundaries align with axes

Physics Applications

Many fundamental equations of physics simplify dramatically in the right coordinates:

  • Electric field of a charged wire: Cylindrical coordinates, field depends only on rr
  • Gravitational field of a planet: Spherical coordinates, field depends only on ρ\rho
  • Schrödinger equation for hydrogen: Spherical coordinates allow separation of variables, yielding the famous atomic orbitals
  • Fluid flow in a pipe: Cylindrical coordinates capture the parabolic velocity profile

Machine Learning Applications

Coordinate systems and their transformations appear throughout modern machine learning:

1. Hyperspherical Coordinates in High Dimensions

Spherical coordinates generalize to n dimensions as hyperspherical coordinates. These are crucial for:

  • Uniform sampling on hyperspheres: Many ML algorithms need to sample uniformly from the surface of a hypersphere (e.g., for weight initialization)
  • Directional statistics: When data lies on a sphere (text embeddings, normalized features), spherical coordinates provide natural distributions
  • von Mises-Fisher distribution: The spherical analog of the Gaussian, used in clustering on spheres

2. Normalizing Flows and Coordinate Transforms

Normalizing flows transform simple distributions into complex ones using invertible mappings. The key insight is tracking the Jacobian:

pX(x)=pZ(f1(x))detf1xp_X(x) = p_Z(f^{-1}(x)) \left| \det \frac{\partial f^{-1}}{\partial x} \right|

This is exactly the change-of-variables formula from multivariable calculus! Polar/spherical transforms inspired many flow architectures.

3. 3D Computer Vision and Graphics

Modern 3D deep learning heavily uses coordinate systems:

  • Point cloud processing: Converting between Cartesian and spherical representations for different tasks
  • NeRF (Neural Radiance Fields): Ray marching uses parametric coordinates
  • Spherical CNNs: Convolutions on spherical data (climate, planetary) require understanding spherical geometry

4. Positional Encodings

The sinusoidal positional encodings in Transformers:

PE(pos, 2i) = sin(pos / 10000^(2i/d))

PE(pos, 2i+1) = cos(pos / 10000^(2i/d))

These are essentially polar coordinates! The position is encoded as angles at different frequencies, allowing the model to learn relative positions through rotation-like operations.


Python Implementation

Coordinate Conversion Functions

Coordinate System Conversions in Python
🐍coordinate_systems.py
4Cartesian to Cylindrical

We compute r as the distance from the z-axis (not the origin), theta using arctan2 for proper quadrant handling, and z remains unchanged.

11Radial Distance r

r = sqrt(x^2 + y^2) is the perpendicular distance from the z-axis, equivalent to the polar radius in the xy-plane.

12Angle theta

arctan2(y, x) correctly handles all four quadrants, returning angles in [-π, π]. This is crucial for proper coordinate conversion.

24Cartesian to Spherical

The spherical conversion requires computing rho (distance from origin), theta (azimuthal angle), and phi (polar angle from z-axis).

31Polar Angle phi

phi = arccos(z/rho) gives the angle from the positive z-axis. We check rho > 0 to avoid division by zero at the origin.

42Spherical to Cartesian

The conversion uses: x = rho*sin(phi)*cos(theta), y = rho*sin(phi)*sin(theta), z = rho*cos(phi). Note sin(phi) appears in x and y.

52Creating a Sphere

In spherical coordinates, a sphere of radius R is simply rho = R. We vary theta and phi over their full ranges to cover the entire surface.

58 lines without explanation
1import numpy as np
2import matplotlib.pyplot as plt
3from mpl_toolkits.mplot3d import Axes3D
4
5def cartesian_to_cylindrical(x, y, z):
6    """
7    Convert Cartesian (x, y, z) to Cylindrical (r, theta, z).
8
9    r: radial distance from z-axis
10    theta: angle from positive x-axis in xy-plane
11    z: height (unchanged)
12    """
13    r = np.sqrt(x**2 + y**2)
14    theta = np.arctan2(y, x)  # Returns angle in [-pi, pi]
15    return r, theta, z
16
17def cylindrical_to_cartesian(r, theta, z):
18    """
19    Convert Cylindrical (r, theta, z) to Cartesian (x, y, z).
20    """
21    x = r * np.cos(theta)
22    y = r * np.sin(theta)
23    return x, y, z
24
25def cartesian_to_spherical(x, y, z):
26    """
27    Convert Cartesian (x, y, z) to Spherical (rho, theta, phi).
28
29    rho: distance from origin
30    theta: azimuthal angle (in xy-plane from x-axis)
31    phi: polar angle (from positive z-axis)
32    """
33    rho = np.sqrt(x**2 + y**2 + z**2)
34    theta = np.arctan2(y, x)
35    phi = np.arccos(z / rho) if rho > 0 else 0
36    return rho, theta, phi
37
38def spherical_to_cartesian(rho, theta, phi):
39    """
40    Convert Spherical (rho, theta, phi) to Cartesian (x, y, z).
41    """
42    x = rho * np.sin(phi) * np.cos(theta)
43    y = rho * np.sin(phi) * np.sin(theta)
44    z = rho * np.cos(phi)
45    return x, y, z
46
47# Example: Create a sphere using spherical coordinates
48rho = 2  # Radius
49theta = np.linspace(0, 2*np.pi, 50)
50phi = np.linspace(0, np.pi, 25)
51THETA, PHI = np.meshgrid(theta, phi)
52
53# Convert to Cartesian for plotting
54X = rho * np.sin(PHI) * np.cos(THETA)
55Y = rho * np.sin(PHI) * np.sin(THETA)
56Z = rho * np.cos(PHI)
57
58fig = plt.figure(figsize=(10, 8))
59ax = fig.add_subplot(111, projection='3d')
60ax.plot_surface(X, Y, Z, alpha=0.6, cmap='viridis')
61ax.set_xlabel('X')
62ax.set_ylabel('Y')
63ax.set_zlabel('Z')
64ax.set_title('Sphere in Spherical Coordinates: rho = 2')
65plt.show()

Integration Example: Comparing Coordinate Systems

Volume Integration in Different Coordinates
🐍integration_comparison.py
4Cartesian Integration

In Cartesian coordinates, integrating over a cylinder requires complex bounds: y depends on x due to the circular cross-section.

10Complex y Bounds

For a cylinder, y ranges from -sqrt(R² - x²) to +sqrt(R² - x²) for each x. This makes the integral harder to set up and compute.

22Cylindrical Integration

With cylindrical coordinates, the bounds are simple constants: r from 0 to R, θ from 0 to 2π, z from 0 to H.

28Jacobian Factor r

The integrand includes r (not 1) because dV = r dr dθ dz. The r factor is the Jacobian of the coordinate transformation.

40Spherical Integration

For a sphere, spherical coordinates give constant bounds: ρ from 0 to R, θ from 0 to 2π, φ from 0 to π.

46Jacobian Factor ρ²sin(φ)

The volume element in spherical coordinates is dV = ρ² sin(φ) dρ dθ dφ. This Jacobian accounts for the geometry of spherical shells.

61 lines without explanation
1import numpy as np
2from scipy import integrate
3
4def cylinder_volume_cartesian(R, H):
5    """
6    Compute cylinder volume using Cartesian coordinates.
7    This requires complex bounds for x, y integration.
8    """
9    def integrand(z, y, x):
10        return 1
11
12    def y_lower(x): return -np.sqrt(R**2 - x**2)
13    def y_upper(x): return np.sqrt(R**2 - x**2)
14
15    result, _ = integrate.tplquad(
16        integrand,
17        -R, R,           # x bounds
18        y_lower, y_upper, # y bounds (depend on x)
19        0, H             # z bounds
20    )
21    return result
22
23def cylinder_volume_cylindrical(R, H):
24    """
25    Compute cylinder volume using cylindrical coordinates.
26    Much simpler bounds!
27
28    V = ∫∫∫ r dr dθ dz
29    """
30    def integrand(z, theta, r):
31        return r  # The Jacobian factor!
32
33    result, _ = integrate.tplquad(
34        integrand,
35        0, R,            # r bounds: 0 to R
36        0, 2*np.pi,      # theta bounds: 0 to 2π
37        0, H             # z bounds: 0 to H
38    )
39    return result
40
41def sphere_volume_spherical(R):
42    """
43    Compute sphere volume using spherical coordinates.
44
45    V = ∫∫∫ ρ² sin(φ) dρ dθ dφ
46    """
47    def integrand(phi, theta, rho):
48        return rho**2 * np.sin(phi)  # The Jacobian!
49
50    result, _ = integrate.tplquad(
51        integrand,
52        0, R,            # rho bounds: 0 to R
53        0, 2*np.pi,      # theta bounds: 0 to 2π
54        0, np.pi         # phi bounds: 0 to π
55    )
56    return result
57
58# Test the formulas
59R, H = 2, 3
60print(f"Cylinder (R={R}, H={H}):")
61print(f"  Cartesian:   {cylinder_volume_cartesian(R, H):.4f}")
62print(f"  Cylindrical: {cylinder_volume_cylindrical(R, H):.4f}")
63print(f"  Exact (πR²H): {np.pi * R**2 * H:.4f}")
64
65print(f"\nSphere (R={R}):")
66print(f"  Spherical:   {sphere_volume_spherical(R):.4f}")
67print(f"  Exact (4/3πR³): {4/3 * np.pi * R**3:.4f}")

Common Pitfalls

Forgetting the Jacobian

When converting an integral to cylindrical or spherical coordinates, you must include the appropriate Jacobian factor:

  • Cylindrical:  ⁣ ⁣ ⁣ ⁣ ⁣ ⁣fdV= ⁣ ⁣ ⁣ ⁣ ⁣ ⁣frdrdθdz\int\!\!\!\int\!\!\!\int f \, dV = \int\!\!\!\int\!\!\!\int f \, r \, dr \, d\theta \, dz
  • Spherical:  ⁣ ⁣ ⁣ ⁣ ⁣ ⁣fdV= ⁣ ⁣ ⁣ ⁣ ⁣ ⁣fρ2sinϕdρdθdϕ\int\!\!\!\int\!\!\!\int f \, dV = \int\!\!\!\int\!\!\!\int f \, \rho^2 \sin\phi \, d\rho \, d\theta \, d\phi

Angle Ranges

Be careful with angle ranges:

  • θ\theta ranges from 00 to 2π2\pi (full circle)
  • ϕ\phi ranges from 00 to π\pi (half circle, pole to pole)

Integrating ϕ\phi from 0 to 2π2\piwould double-count the sphere!

Convention Differences

Physics and mathematics often use opposite conventions for θ\theta and ϕ\phi in spherical coordinates. Some texts use (r,θ,ϕ)(r, \theta, \phi) instead of (ρ,θ,ϕ)(\rho, \theta, \phi). Always check the definitions!

Cylindrical r vs. Spherical ρ

Don't confuse cylindrical rr (distance from z-axis) with spherical ρ\rho (distance from origin). They are related by r=ρsinϕr = \rho \sin\phi.


Test Your Understanding

Test Your UnderstandingQuestion 1 of 8

In cylindrical coordinates (r, θ, z), what does the coordinate r represent?


Summary

Cylindrical and spherical coordinates are powerful tools for problems with rotational or radial symmetry. They transform complex boundaries into simple constants and make otherwise intractable integrals manageable.

Key Formulas

Coordinate SystemPointVolume Element
Cartesian(x, y, z)dx dy dz
Cylindrical(r, θ, z)r dr dθ dz
Spherical(ρ, θ, φ)ρ² sin(φ) dρ dθ dφ

Key Takeaways

  1. Cylindrical coordinates (r,θ,z)(r, \theta, z) extend polar coordinates to 3D and are ideal for cylinders and axial symmetry
  2. Spherical coordinates (ρ,θ,ϕ)(\rho, \theta, \phi) describe points by distance and two angles, perfect for spheres and radial symmetry
  3. The Jacobian accounts for how coordinate transformations stretch or compress space — never forget it in integrals!
  4. Choose coordinates that match your problem's symmetry: a sphere is ρ=R\rho = R in spherical but x2+y2+z2=R2x^2 + y^2 + z^2 = R^2 in Cartesian
  5. These concepts extend to machine learning through hyperspherical geometry, normalizing flows, and 3D computer vision
The Essence of Coordinate Systems:
"The right coordinates turn the impossible into the obvious. What appears as a complex surface in one system becomes a single constant in another."
Coming Next: In the next chapter, we'll explore Vector-Valued Functions, learning how to describe curves and motion in three-dimensional space using vectors that change with a parameter.
Loading comments...