Moment of Inertia for Arbitrary Shape
Solution 1
Integral Method
Given a volume of material with constant or varying density, the mass is defined by the volume integral
$$ m = \int \rho \,{\rm d}V \tag{1}$$
The center of mass is given by the integral
$$ \vec{c} = \frac{1}{m} \int \,\vec{r}\, \rho\, {\rm d} V \tag{2}$$
where $\vec{r} = \pmatrix{x \\ y \\ z}$ is the position of each particle in the object, and center of mass $\vec{c} = \pmatrix{c_x \\ c_y \\ c_z}$
Finally, the mass moment of inertia tensor about the origin is found by the integral
$$ \mathbf{I}_0 = \int \begin{bmatrix} y^2+z^2 & x y & x z \\ x y & x^2+z^2 & y z\\ x z & y z & x^2+y^2 \end{bmatrix} \rho \, {\rm d} V \tag{3} $$
If the MMOI about the center of mass is required, then use the parallel axis theorem in vector form"
$$ \mathbf{I}_C = \mathbf{I}_0  m \begin{bmatrix} c_y^2+c_z^2 & c_x c_y & c_x c_z \\ c_x c_y & c_x^2+c_z^2 & c_y c_z\\ c_x c_z & c_y c_z & c_x^2+c_y^2 \end{bmatrix} \tag{4} $$
Example
Consider an upsidedown cone with the coordinate system centered on the tip and uniform density $\rho$
Each particle location in the object is defined by cylindrical coordinates
$$ \vec{r} = \pmatrix{r \cos \theta \\ r \sin \theta \\ z} $$ with $z = 0 \ldots h$, $\theta = 0 \ldots 2\pi$, and $r = 0 \ldots \tfrac{z}{h} R$
The differential volume in cylindrical coordinates is
$$ {\rm d}V = r\, {\rm d} r\, {\rm d}\theta\, {\rm d} z $$
So according to the procedure above we have
$$ m = \int_0^h \int_0^{2\pi} \int_0^{\tfrac{z R}{h}} \rho\, r\, {\rm d} r\, {\rm d}\theta\, {\rm d} z = \rho \frac{\pi h R^2}{3}$$
$$ \vec{c} = \frac{1}{ \rho \tfrac{\pi h R^2}{3} } \int_0^h \int_0^{2\pi} \int_0^{\tfrac{z R}{h}} \rho\, \pmatrix{r \cos \theta \\ r \sin \theta \\ z}\, r\, {\rm d} r\, {\rm d}\theta\, {\rm d} z = \pmatrix{0 \\ 0 \\ \tfrac{3}{4} h } $$
$$ \mathbf{I}_0 = \int_0^h \int_0^{2\pi} \int_0^{\tfrac{z R}{h}} \rho\, \begin{bmatrix} z^2+r^2 \sin^2 \theta & r^2 \sin\theta\cos\theta & r z \cos\theta \\ r^2 \sin\theta \cos\theta & z^2 + r^2 \cos^2 \theta & r z \sin\theta \\ r z \cos\theta &  r z \sin \theta & r^2 \end{bmatrix} r\, {\rm d} r\, {\rm d}\theta\, {\rm d} z $$
$$ \mathbf{I}_0 = \begin{bmatrix} \rho \tfrac{\pi R^2 h (R^2+4h^2)}{20} & & \\ & \rho \tfrac{\pi R^2 h (R^2 +4 h^2)}{20} & \\ & & \rho \tfrac{\pi R^4 h}{10} \end{bmatrix} = \begin{bmatrix} m \tfrac{3 (R^2+4 h^2)}{20} & & \\ & m \tfrac{3 (R^2+4 h^2)}{20} & \\ & & m \tfrac{3 R^2}{10} \end{bmatrix} $$
$$ \mathbf{I}_C = \mathbf{I}_0  m \begin{bmatrix} \tfrac{9 h^2}{16} & & \\ & \tfrac{9 h^2}{16} & \\ & & 0 \end{bmatrix} = \begin{bmatrix} m \left( \tfrac{3 R^2}{20} + \frac{3 h^2}{80} \right) & & \\ & m \left( \tfrac{3 R^2}{20} + \frac{3 h^2}{80} \right) & \\ & & m \tfrac{3 R^2}{10} \end{bmatrix} $$
which matches the published values in
https://en.wikipedia.org/wiki/List_of_moments_of_inertia
Solution 2
Well, the idea that you have is intuitive and is also correct in a certain sense, but it has to be more precise.
This topic is discussed in undergraduate mechanics textbooks(e.g Classical Mechanics by John R. Taylor). My reasoning follows the book I mentioned above(chapter 10, pg 372). I will first mention a summary of the moment of inertia tensor and then address your idea about Kinetic energy. Since you mentioned you are a high school student, I'll try to be as complete in my explanations as possible. Since this topic really involves a lot of calculations, I would really encourage you to do it as an exercise.
The idea of the moment of inertia is as follows. We want to find a relation between the angular momentum of a rotating body(can be composed of many particles) and its angular velocity. Essentially, we want to find something like this: $$ \vec{L} = (something) * \vec{\omega} $$
The question is what is this (something). In the case where the object is rotating about a fixed axis and there is rotational symmetry about it, this object that I call (something) is merely the moment of inertia you are familiar with and is just a number. But what if the object does not possess the rotational symmetry? is this (something) still a number? Well, the answer to that question is what Triatticus described. It is a $3 \times 3$ matrix called the Inertia tensor. Don't get frightened by the word tensor, just think of it as a matrix.
Given many small pieces of masses $m_\alpha$, the net angular momentum is given by the sum of the individual angular momenta: $$ \vec{L} = \sum l_\alpha = \sum \vec{r}_\alpha \times m_\alpha \; \vec{v}_\alpha $$
If you assume the angular velocity to be in one given direction and assume that all position vectors are perpendicular to it i.e all masses are constrained to move in the plane perpendicular to it, then we have the simple idea of the moment of inertia described as a scalar $I$.
$$ \vec{L} = \sum m_\alpha \vec{r}_\alpha \times \vec{\omega} \times \vec{r}_\alpha = \sum m_\alpha (\vec{r}_\alpha)^2 \vec{\omega}  (\vec{r}_\alpha \cdot\vec{\omega} ) \vec{r}_\alpha $$ $$ \vec{L} = \sum m_\alpha (\vec{r}_\alpha)^2 \vec{\omega} = I \vec{\omega} $$ Here I have used a vector identity for $\vec{A}\times\vec{B}\times\vec{C} = (\vec{A}\cdot\vec{C})\vec{B}(\vec{A}\cdot\vec{B})\vec{C}$.
However, this is not very general. The following is just a sketch of what you can do to describe a body of arbitrary shape and I would encourage you to check out the reference and do it by yourself since it is a good exercise. It is not too difficult and is accessible to an extent to high school students in my opinion.
Assume $\vec{\omega} = (\omega_x,\omega_y,\omega_z) $ i.e arbitrary. Then, $$ \vec{L} = \sum \vec{r}_\alpha \times m_\alpha \; \vec{v}_\alpha = m_\alpha \; \vec{r}_\alpha \times (\vec{\omega} \times \vec{r}_\alpha) $$ Note:($\vec{v} = \vec{\omega} \times \vec{r}$)
Substitute the values of $\vec{\omega}$ and $\vec{r}_\alpha = (r_{\alpha,x},r_{\alpha,y},r_{\alpha,z})$
Using the properties of vectors. Then group the terms with the indices $\alpha$. You shall obtain something of the form mentioned by Triatticus. $$ \vec{L} = I \vec{\omega} $$ Where $I$ here is a $3 \times 3$ symmetric matrix called the inertia tensor.
Now, we used the x,y,z directions to describe the vectors and matrix in our problem, but we are not obliged to use it and we can actually use another set of perpendicular axes. It turns out, that if you have a symmetric matrix, you can find 3 directions such that this moment of inertia tensor is a diagonal matrix i.e there are only nonzero terms on the 11, 22, 33 positions.
This is where your intuition was right. If you chose this particular set of directions(and write $\omega$ using with these new unit vectors), you can use the formula you wrote!
I'm sure that I have not written enough, but if you require any clarification, please let me know.
Related videos on Youtube
fullnitrous
Updated on December 16, 2020Comments

fullnitrous over 2 years
Consider any arbitrary shape with arbitrary rotation axes, global and or local to the shape that are able to describe any orientation of the shape. The shape is also defined with an arbitrary density function. Using
$$dI=r^2dm$$
to obtain the moment of inertia in each of those axes, would then
$$\sum \frac{1}{2}I_i\omega_i^2$$
equal the total rotational kinetic energy of the shape?

Triatticus almost 4 yearsNot entirely, the moment of inertia of an arbitrary body can be represented by a $3\times3$ array of numbers (also called the moment of inertia tensor) $I_{ij}$

fullnitrous almost 4 years@Triatticus could you elaborate please I have a hard time understanding inertia tensors?

Triatticus almost 4 yearsWhat level of mechanics are you familiar with? That is are you talking a calculus based mechanics course.

G. Smith almost 4 years$E_K=\frac{1}{2}I_{ij}\omega_i\omega_j$

fullnitrous almost 4 years@Triatticus I don't know, I'm in highschool.


fullnitrous almost 4 yearsYes, sorry for asking further but. How would I apply this to a rod with the roll, pitch and yaw angles. The kinetic rotational energy must be described with these angles so it can be put into a Lagrangian equation so i get the equations of motion for those angles. Simply put  the center of mass and mass of a rod is calculated with a triple integral of the density function of the rod. What is the rotational kinetic energy using only the roll pitch and yaw angles? Also the total rotational kinetic energy plus the total linear kinetic energy must equal the total kinetic energy right?

fullnitrous almost 4 yearsNote  the roll and yaw angles are aligned initially so it is in gimbal lock. The yaw angle is rotation around the global y axis while roll rotation is the axis that is the centre line of the rod.

Sparsh Mishra almost 4 yearsIs the rod 3 dimensional or does it just have a length and no thickness(ideal rod)?

fullnitrous almost 4 yearsIt's a 3 dimensional rod and so is the density function. Technically the density function could form any shape within the limits of the cylinder.

Sparsh Mishra almost 4 yearsSo, you can use the axes you mentioned, but you may then have to use the inertia tensor in a form that is not diagonal and it'll make the computation harder(because you said that the density can have any form and so it's not rotationally symmetric). Finding the inertia tensor, finding 3 directions that make it diagonal and then using those axes will be much better. Then you can use rotations about these axes to give the rotational kinetic energy. The total kinetic energy will be that plus the translational kinetic energy of the CoM.

fullnitrous almost 4 yearsIs this imgur.com/a/XvPCNgR correct in that case? The goal in the calculation was to only express the rotational kinetic energy of the rod by calculating the inertia tensor and the angular velocity.

fullnitrous almost 4 yearsForgot to write it but the origin is the center of mass of the rod.

Sparsh Mishra almost 4 years@fullnitrous It seems okay to me.

fullnitrous almost 4 yearshow okay? I need my calculations to be 100% correct I'm making a simulation.