---
title: Cylindrical and spherical coordinates
heading: Coordinates that fit wires and charges
eyebrow: A9 · Lesson 18 · Cylindrical and spherical coordinates
xp: 40
---

::: hook
The magnetic field of a wire circles it, getting weaker with distance. In $x$ and $y$ it's the messy-looking $\frac{\mu_0 I}{2\pi}\frac{(-y, x)}{x^2 + y^2}$. Described by distance from the wire and direction around it, it's just "strength $\mu_0I/2\pi r$, pointing around." Choosing coordinates that match the shape of a problem turns hard integrals into easy ones, and every textbook formula for wires, cables and charges is written this way.

::: play
- The arrows show the magnetic field around a wire carrying current $I$ out of the page at the origin. The point is placed by its distance $r$ and angle $\varphi$ instead of $x$ and $y$.
- The two short arrows at the point are the unit vectors $\hat r$ (straight out) and $\hat\varphi$ (around). Move the point. Which one does the field follow?
- Change $r$ and watch the field strength. Change φ: does the strength change?
:::
:::

```sim plot
view: flow
x: x = -3..3 cm
y: y = -3..3 cm
slider: I = 1..20 step 1 = 10 A
slider: r = 0.3..2.8 step 0.1 = 1.5 cm
slider: phi = 0..360 step 5 = 40 °
dx: -y/(x^2 + y^2)
dy: x/(x^2 + y^2)
arrows: scaled
grid: 14
dot: 0, 0 | label: wire
path: r*cos(u), r*sin(u) | over: u = 0..2*pi | color: ch2
vec: r*cos(phi*pi/180), r*sin(phi*pi/180), 0.6*cos(phi*pi/180), 0.6*sin(phi*pi/180) | label: r̂ | color: ch3
vec: r*cos(phi*pi/180), r*sin(phi*pi/180), -0.6*sin(phi*pi/180), 0.6*cos(phi*pi/180) | label: φ̂ | color: ch4
readout: x = r*cos(phi*pi/180) cm
readout: y = r*sin(phi*pi/180) cm
readout: B in µT = 4*pi*1e-7*I/(2*pi*r/100)*1e6
```

::: predict
## In the $x, y$ grid, a small patch has area $dx\,dy$. In polar coordinates, a patch spans $dr$ outward and $d\varphi$ around. What is its area?

- [ ] $dr\,d\varphi$
- [x] $r\,dr\,d\varphi$
- [ ] $r^2\,dr\,d\varphi$
- [ ] $dr\,d\varphi/r$

::: reveal
$r\,dr\,d\varphi$. Turning through an angle $d\varphi$ moves you a distance $r\,d\varphi$ around a circle of radius $r$, so the patch is $dr$ by $r\,d\varphi$. Patches far from the center are bigger than ones near it for the same $dr$ and $d\varphi$. Forgetting that factor of $r$ is the most common mistake with polar integrals.
:::
:::

::: nameit
## Cylindrical and spherical coordinates

**Cylindrical** $(r, \varphi, z)$: distance from an axis, angle around it, and height along it.

$$x = r\cos\varphi \qquad y = r\sin\varphi \qquad z = z \qquad r = \sqrt{x^2 + y^2}$$

**Spherical** $(r, \theta, \varphi)$: distance from a center, angle down from the $z$ axis, and angle around it.

$$x = r\sin\theta\cos\varphi \qquad y = r\sin\theta\sin\varphi \qquad z = r\cos\theta$$

(Math books sometimes swap the names θ and φ; physics and engineering books use these.)

**Unit vectors that move.** $\hat r$, $\hat\varphi$ and $\hat\theta$ point differently at different places: in the plane, $\hat r = (\cos\varphi, \sin\varphi)$ and $\hat\varphi = (-\sin\varphi, \cos\varphi)$. That's why fields look simple in these coordinates:

| Source | Field |
|---|---|
| point charge $Q$ | $\mathbf{E} = \dfrac{Q}{4\pi\varepsilon_0r^2}\hat r$ (spherical) |
| line charge λ | $\mathbf{E} = \dfrac{\lambda}{2\pi\varepsilon_0r}\hat r$ (cylindrical) |
| wire carrying $I$ | $\mathbf{B} = \dfrac{\mu_0I}{2\pi r}\hat\varphi$ (cylindrical) |

**Area and volume elements.** A small patch or box isn't $dr\,d\varphi$:

$$dA = r\,dr\,d\varphi \qquad dV_\text{cyl} = r\,dr\,d\varphi\,dz \qquad dV_\text{sph} = r^2\sin\theta\,dr\,d\theta\,d\varphi$$

**Integrals become easy** when the region matches. The charge on a disk of radius $R$ with density $\sigma = \sigma_0 r/R$:

$$Q = \int_0^{2\pi}\!\!\int_0^R \sigma_0\frac{r}{R}\,r\,dr\,d\varphi = 2\pi\sigma_0\frac{R^2}{3}$$

and the volume of a sphere: $\int_0^{2\pi}\!\int_0^\pi\!\int_0^R r^2\sin\theta\,dr\,d\theta\,d\varphi = \tfrac{R^3}{3} \cdot 2 \cdot 2\pi = \tfrac43\pi R^3$.

**Divergence of a spreading field.** For a field pointing straight out from a center, $F_r(r)\hat r$, the divergence is $\frac{1}{r^2}\frac{d}{dr}(r^2F_r)$ in spherical coordinates. For $F_r = 1/r^2$ that's zero: a point charge's field has no divergence anywhere except at the charge itself, just as Gauss's law requires.
:::

::: example
## Find the volume of a cylinder of radius $R$ and height $h$ in cylindrical coordinates.

::: solution
1. **Set up the integral.** The factor $r$ in $dV = r\,dr\,d\theta\,dz$ is essential:
   $$V = \int_0^h\int_0^{2\pi}\int_0^R r\,dr\,d\theta\,dz$$
2. **Integrate each factor.**
   $$\begin{aligned} V &= \frac{R^2}{2} \times 2\pi \times h \\ &= \pi R^2h \end{aligned}$$

**Answer:** the volume is $\pi R^2h$.
:::
:::

::: example
## A ball of radius $R$ has density $\rho = \rho_0(1 - r/R)$. What is its mass?

::: solution
1. **Add up spherical shells.**
   $$M = \int_0^R\rho_0\left(1 - \frac{r}{R}\right)4\pi r^2\,dr$$
2. **Integrate.**
   $$\begin{aligned} M &= 4\pi\rho_0\left(\frac{R^3}{3} - \frac{R^3}{4}\right) \\ &= \frac{\pi\rho_0R^3}{3} \end{aligned}$$
3. **Compare with a uniform ball.** That's a quarter of what a uniform ball at $\rho_0$ would have.

**Answer:** the mass is $\frac{\pi\rho_0R^3}{3}$.
:::
:::

::: example
## Find the volume inside the unit sphere and within 45° of the $z$ axis.

::: solution
1. **Describe the region.** In spherical coordinates it's $0 \le r \le 1$, $0 \le \varphi \le \frac\pi4$, $0 \le \theta \le 2\pi$, with
   $$dV = r^2\sin\varphi\,dr\,d\varphi\,d\theta$$
2. **Integrate each factor.**
   $$\begin{aligned} V &= 2\pi \cdot \tfrac13 \cdot \left(1 - \cos\tfrac\pi4\right) \\ &= 0.613 \end{aligned}$$
3. **Compare with the whole sphere.** That's 14.6% of the whole sphere's $\frac43\pi = 4.19$. The same integral with $\varphi$ up to $\pi$ gives the full volume.

**Answer:** the volume is 0.613.
:::
:::

::: check
given: r = 2..9 int; ph = 20 | 50 | 110 | 140 | 200
answer: r*cos(ph*pi/180)
unit: cm
tolerance: 0.5%

## A point is at $r$ = {r} cm, $\varphi$ = {ph}°. What is its $x$ coordinate, in cm?

::: right
Right. $x = r\cos\varphi$ = {answer}.
:::

::: misses
- [r*sin(ph*pi/180)] That's y. x goes with the cosine.
- [r*cos(ph)] Work in degrees, or convert {ph}° to radians first.
- [any] Not yet. $x = r\cos\varphi$.
:::
:::

::: check
given: s0 = 1..9 int; R = 1 | 2 | 4
answer: 2*pi*s0*R^2/3
unit: nC
tolerance: 0.5%

## A disk of radius {R} m has charge density $\sigma = \given{s0}\,r/R$ nC/m², zero at the center and largest at the rim. What is its total charge?

::: right
Right. $\int_0^{2\pi}\int_0^R \given{s0}(r/R)\,r\,dr\,d\varphi = 2\pi\cdot\given{s0}R^2/3$ = {answer}.
:::

::: misses
- [pi*s0*R^2] That would be the charge if the density were {s0} everywhere. It's less, since it starts at zero.
- [pi*s0*R] Include the $r$ in $dA = r\,dr\,d\varphi$.
- [2*pi*s0*R^2/2] Integrate $r^2/R$ from 0 to R: that's $R^2/3$.
- [any] Not yet. Use $dA = r\,dr\,d\varphi$ and integrate.
:::
:::

::: check
given: rho = 1..9 int; R = 1 | 2 | 5
answer: rho*4/3*pi*(R/100)^3*1e9
unit: nC
tolerance: 0.5%

## A ball of radius {R} cm holds a uniform charge density of {rho} µC/m³. What is its total charge?

::: right
Right. $\rho \cdot \tfrac43\pi R^3$ = {answer}.
:::

::: misses
- [rho*4*pi*(R/100)^2*1e9] That's using the surface area. Use the volume.
- [rho*4/3*pi*R^3*1e9] Convert centimeters to meters.
- [any] Not yet. $Q = \rho \cdot \tfrac43\pi R^3$.
:::
:::

::: check
given: lam = 1..9 int; r = 1 | 2 | 5 | 10
answer: lam*1e-9/(2*pi*8.854e-12*r/100)
unit: V/m
tolerance: 1%

## A long wire carries {lam} nC/m of charge. How strong is the electric field {r} cm from it?

::: right
Right. $E = \lambda/(2\pi\varepsilon_0 r)$ = {answer}.
:::

::: misses
- [lam*1e-9/(4*pi*8.854e-12*(r/100)^2)] That's a point charge's field. A line charge's falls as $1/r$.
- [lam*1e-9/(2*pi*8.854e-12*r)] Convert {r} cm to meters.
- [any] Not yet. Gauss's law on a cylinder gives $E = \lambda/(2\pi\varepsilon_0r)$.
:::
:::

::: check
kind: choice

## You integrate over a sphere using $dV = dr\,d\theta\,d\varphi$, forgetting the $r^2\sin\theta$. What goes wrong?

- [ ] Nothing: it's only a scale factor
- [x] Small regions near the center and near the poles are counted as if they were as big as the ones far out at the equator
- [ ] The answer comes out negative
- [ ] The integral diverges

::: right
Right. The factor $r^2\sin\theta$ is the actual size of a small box at that spot. Without it, every coordinate box counts the same, though near the center or the poles they're tiny.
:::

::: misses
- [1] It's a factor that changes from place to place, so it changes the answer.
- [3] The answer would be wrong, but not negative.
- [4] It would give a finite but wrong answer.
:::
:::

::: check
kind: parts
given: a = 30 | 45 | 60

## The cone within {a}° of the $z$ axis, inside the unit sphere.

::: part
answer: 2*pi/3*(1 - cos(a*pi/180))
tolerance: 0.5%

### What is its volume?

::: misses
- [any] $\int_0^{2\pi}\int_0^{\alpha}\int_0^1r^2\sin\varphi\,dr\,d\varphi\,d\theta$.
:::
:::
:::

::: check
kind: derivation
vars: R = 0.5..3, h = 0.5..3

## Find the volume of a cylinder in cylindrical coordinates.

::: step
answer: R^2/2

### What is $\int_0^Rr\,dr$?
:::

::: step
answer: pi*R^2*h

### What is $\int_0^h\int_0^{2\pi}\int_0^Rr\,dr\,d\theta\,dz$?
:::

::: right
Right. $\pi R^2h$, with the factor $r$ in $dV$ doing the work.
:::
:::

::: explain
## Why does the area element in polar coordinates include a factor of $r$?

::: model
A small step $d\varphi$ in angle moves you a distance that depends on how far out you are: around a circle of radius $r$, an angle $d\varphi$ spans an arc of length $r\,d\varphi$. So a small patch reaching $dr$ outward and $d\varphi$ around is a near-rectangle $dr$ by $r\,d\varphi$, with area $r\,dr\,d\varphi$. Patches far from the center are larger for the same coordinate steps, and the factor of $r$ accounts for that.
:::
:::

::: practice

::: check
given: x0 = 3 | 5 | 6; y0 = 4 | 8 | 12
answer: sqrt(x0^2 + y0^2)
tolerance: 0.5%

## What is $r$ for the point $(\given{x0}, \given{y0})$?

::: misses
- [x0 + y0] Use Pythagoras.
- [any] $r = \sqrt{x^2 + y^2}$.
:::
:::

::: check
given: R = 1 | 2 | 4 | 5 | 6
answer: 4/3*pi*R^3
tolerance: 0.5%

## Integrate $r^2\sin\theta$ over $0 \le r \le \given{R}$, $0 \le \theta \le \pi$, $0 \le \varphi \le 2\pi$.

::: misses
- [4*pi*R^2] That's the sphere's surface area. Integrate over r too.
- [2*pi*R^3/3] $\int_0^\pi\sin\theta\,d\theta = 2$.
- [any] The three integrals separate: $\frac{R^3}{3} \cdot 2 \cdot 2\pi$.
:::
:::

::: check
given: I = 1..20 int; r = 2 | 5 | 10
answer: 4*pi*1e-7*I/(2*pi*r/1000)
unit: T
tolerance: 0.5%

## How strong is the magnetic field {r} mm from a wire carrying {I} A?

::: misses
- [4*pi*1e-7*I/(2*pi*r)] Convert millimeters to meters.
- [any] $B = \mu_0I/(2\pi r)$.
:::
:::
:::
