Definition
Moment of inertia, $I$, for a point particle of mass $m$ and distance $\rho$ away from the axis of rotation:\begin{equation}
I = m \: \rho^2
\end{equation}
Note that $\rho$ is not the radial distance from the origin. It is the shortest distance from the axis of rotation. It is not the distance $r$ as in spherical coordinates, but it is the distance $\rho$ as in cylindrical coordinates. This forces me to write the volumetric mass density as $\varrho(r)$, which is commonly written as $\rho(r)$.
Descrete Collection
For a collection of discrete $N$ particles of masses $m_i$ and axial distances $\rho_i$ from the axis of rotation, the moment of inertial is given by:\begin{equation}
I = \sum_{i=1}^N m_i \rho_i^2
\end{equation}
Continuous Collection
For a continuous collection of particles the moment of inertia is simply given by an integral over all the mass elements, $dm$:\begin{align}
I &= \int_{V'} \rho'^2 \: dm
\end{align}
Note that the primes on $\rho'$ and $V'$ indicates that the integral is over the mass distribution. It is not a crucial thing here, but just a good notation system. Similar notation system is used in electromagnetism, where primes indicate location of charges and non-primes indicate the location of interest. For example $V(r)$ vs. $\varrho(r')$.
For 3D, $dm = \varrho(r') d^3r'$. For 2D, $dm = \sigma(r') d^2r'$. For 2D, $dm = \lambda(r') dr'$. So the moment of inertia changes appropriately. All these integrals could be evaluated in spherical, cylindrical or cartesian coordinates depending on the symmetry of the problem.
\begin{align}
I &= \int_{V'} \rho'^2 \: \varrho(r') \: d^3r' \label{Eq. 3D Cont I} \\
&= \int_{A'} \rho'^2 \: \sigma(r') \: d^2r' \\
&= \int_{L'} \rho'^2 \: \lambda(r') \: dr'
\end{align}
Once again, note that the $r$ is axial distance from axis of rotation and not radial distance from the origin.
Calculations
Solid Sphere
Consider a solid 3D sphere of total mass M and radius R of uniform density. First, we need to define the axis of rotation. Suppose z-axis is the axis of rotation.Density can be found using total Mass divided by total Volume.
\begin{equation}
\varrho = \frac{M}{4/3 \: \pi R^3} = \frac{3M}{4 \pi R^3}
\end{equation}
Let's plug in this $\varrho$ into the moment of inertia equation, Eq. \ref{Eq. 3D Cont I}. We will evaluate this integral in spherical coordinates $(d^3r = r^2)$. The $\rho'$ is the axial distance from the z-axis, which is $r \: sin(\theta)$ in spherical coordinates.
\begin{align}
I &= \int_{r=0}^R \int_{\theta=0}^\pi \int_{\phi=0}^{2\pi} \Big(r sin(\theta)\Big)^2 \bigg(\frac{3M}{4 \pi R^3}\bigg) \Big(r^2 sin(\theta)\Big) dr d\theta d\phi \nonumber \\
& = (2 \pi) \bigg(\frac{3M}{4 \pi R^3}\bigg) \int_{0}^R r^4 dr \int_{0}^\pi sin^3(\theta) d\theta \nonumber \\
& = \bigg(\frac{3M}{2 R^3}\bigg) \bigg( \frac{R^5}{5} \bigg) \bigg( \frac{4}{3} \bigg) \nonumber \\
& = \frac{2}{5} \: M R^2
\end{align}
The common mistake, a mistake that I make almost all the time, is forgetting to remember that the $\rho$ is the axial distance from the axis of rotation and not distance from origin. I have emphasized this point throughout this paper.
Note that it is easier to just remember a few of these equations than derive them. But, it is absolutely necessary to know how to derive them.
If you would like other examples worked out here, leave a comment below.






