Integration approach for calculating the moment of inertia of a square "loop" I must confess, most of the time when I was calculating moments of inertia I was using tables and the parallel axis theorem. Now I'm trying to compute the moment of inertia by integration.
The problem I am dealing with is a square "loop" which hangs by one of its corners. The rotation takes place so that the "opening" in the loop "moves" into or out of the screen. For better understanding see the picture. 
Furthermore the loop has a side length of l (this is a lower case "L") and a total mass of 4M.
Now my questions are:

*

*Is the suggested decomposition of the square loop viable and correct?

*What is the best method to calculate the moment of inertia of thin beam which rotates under an angle $\theta$ to the axis of rotation.

For calculating the moment of inertia of a thin beam which rotates under an angle $\theta$ to the axis of rotation I used two approaches, but I failed with both of them in calculating the final result. Which should be $\frac{2}{3} M_{total}l^2$. These approaches were:
First approach: Using the equation
$$I = \int r^2dm$$
With $r = \sqrt{x^2+y^2}$ expressing $dm$ as $dm = M \frac{dr}{l} = M \frac{\sqrt{dx^2+dy^2}}{l}$. This yields in:
$$I = M \int (x^2+y^2) \frac{\sqrt{dx^2+dy^2}}{l}$$
This equation can be simplified if we square both sides in ordered to integrate. But still, after this we have a squared differential... Is this correct at all, if yes how do i solve this integral?
Second approach: Using the tensor of inertia, we take the equation for the rotation around the canonical y-axis
$$
I = \varrho \int\int\int (x^2 + z^2) dz dy dx
$$
But here I don't really know what should I use as the limits of integration in order to calculate the correct moment of inertia.
 A: I am going to show a more general approach. This is a 3D problem since the plane of the shape and the rotation axis are co-planar.
Say you have a line segment spanning two 3D points $\vec{A}$ and $\vec{B}$, with parametric position
$$ \vec{r} = \left(1-t\right)\vec{A}+t\,\vec{B} \tag{1}$$
where $t = 0 \ldots 1$ is a parameter designating where along the line the position is.
Suppose the length of the segment is $\ell = \| \vec{B}-\vec{A} \|$ and the mass of the segment is $m$. The differential mass element is ${\rm d}m = m\, {\rm d}t$
The mass moment of inertia tensor about the origin is defined by the following integral
$$ \mathbf{I} = \int_{0}^{1}m\left(\vec{r}\cdot\vec{r}-\vec{r}\odot\vec{r}\right){\rm d}t \tag{2} $$
where $\cdot$ is the inner product and $\odot$ the outer product, defined as follows
$$ \vec{r} \cdot \vec{r} = \begin{bmatrix} x^2+y^2 & & \\ & x^2+y^2 & \\ & & x^2+y^2 \end{bmatrix} $$
and
$$ \vec{r} \odot \vec{r} = \begin{bmatrix} x^2 & x y &  \\ x y & y^2 &  \\  &  & 0 \end{bmatrix} $$
if $\vec{r} = \pmatrix{x\\y\\ 0 }$
Now carry out the integral in (2) using the parametrization in (1) to get
$${\bf I}=m\left(\frac{\vec{A}\cdot\vec{A}+\vec{A}\cdot\vec{B}+\vec{B}\cdot\vec{B}}{3}-\frac{\vec{A}\odot\vec{A}+\vec{B}\odot\vec{B}}{3}-\frac{\vec{A}\odot\vec{B}+\vec{B}\odot\vec{A}}{6}\right) \tag{3}$$
Now consider $\vec{A} = \pmatrix{a_x\\a_y\\0}$ and $\vec{B} = \pmatrix{b_x\\b_y\\0}$, the above is
$$ \small {\bf I}(\vec{A},\vec{B}) = \begin{bmatrix}\frac{m(a_{y}^{2}+a_{y}b_{y} + b_{y}^{2})}{3} & -\frac{m(2a_{x}a_{y}+a_{x}b_{y}+a_{y}b_{x}+2b_{x}b_{y})}{6}\\
-\frac{m(2a_{x}a_{y}+a_{x}b_{y}+a_{y}b_{x}+2b_{x}b_{y})}{6} & \frac{m(a_{x}^{2}+a_{x}b_{x}+b_{x}^{2})}{3}\\
 &  & \frac{m(a_{x}^{2}+a_{y}^{2}+b_{x}^{2}+b_{y}^{2}+a_{x}b_{x}+a_{y}b_{y})}{3}
\end{bmatrix} \tag{4}$$
What is of interest to you is the top left element, which relates rotation about the x-axis to angular momentum about the x-axis
$$ I_{xx}(\vec{A},\vec{B}) = \frac{m(a_{y}^{2}+a_{y}b_{y}+ b_{y}^{2})}{3} $$

All this is just to prove that $I_{xx} = \int y^2 {\rm d}m$

Now if the four corners of the loop are A, B, C, and D  then
$$ I_{xx} = I_{xx}(\vec{A},\vec{B}) + I_{xx}(\vec{B},\vec{C}) + I_{xx}(\vec{C},\vec{D}) + I_{xx}(\vec{D},\vec{A}) \tag{5}$$
which is expanded into
$$ \boxed{ I_{xx} = \frac{m}{3} \left(2 a_y^2 + 2 b_y^2 + 2 c_y^2 + 2 d_y^2 + a_y b_y + b_y c_y + c_y d_y + d_y a_y  \right) } \tag{6}$$
Now plug in the dimensions
$$ \begin{aligned} a_y &= 0 &
b_y &= -\frac{\ell}{\sqrt{2}} \\ c_y & = -\frac{2 \ell}{\sqrt{2}} & d_y & = -\frac{\ell}{\sqrt{2}} \end{aligned} $$
to get
$$ I_{xx} = \frac{8}{3} m \ell^2 $$
A: I'll only comment on the first approach.
When calculating the moment of inertia, $r$ is not the distance from the origin. It's the distance from the axis of rotation: $r = y.$
As for simplifying the integral, you can factor out $dy^2$ from under the square root (the same as when calculating arc lengths).
\begin{align}
I &= \int r^2dm \\
  &= \int y^2 M\frac{dl}{l} \\
  &= \frac{M}{l}\int y^2 \sqrt{dx^2 + dy^2} \\
  &= \frac{M}{l}\int y^2 dy\sqrt{\left(\frac{dx}{dy}\right)^2 + 1} \\
\end{align}
Since the sides of the square are straight and at 45$^\circ$ to the coordinate axes, their slope is $\pm 1.$ So the integral simplifies to
$$I = \frac{M\sqrt{2}}{l}\int y^2 dy.$$
The top sides that connect to the origin range from $y=0$ to $y = l/\sqrt{2}$ while the bottom sides range from $y = l/\sqrt{2}$ to $y = l\sqrt{2}.$ The final expression for $I$ becomes
\begin{align}
I &= \frac{M\sqrt{2}}{l}\left(2\int_0^{l/\sqrt{2}} y^2 dy + 2\int_{l/\sqrt{2}}^{l\sqrt{2}} y^2 dy\right) \\
  &= \frac{M2\sqrt{2}}{3l}\left((l/\sqrt{2})^3 + (l\sqrt{2})^3 - (l/\sqrt{2})^3\right) \\
  &= \frac{2}{3}Ml^2(\sqrt{2})^{4} \\
  &= \frac{8}{3}Ml^2
\end{align}
Since the total mass of the square is $M_{tot} = 4M,$ we have $I = \frac{2}{3}M_{tot}l^2.$

For future reference, the way to simplify integrals of multiple variables is to use relations between $x$ and $y$ to reduce the number of variables. For example, for the top two sides of the square, your first integral is simplified by using $y = \pm x:$
\begin{align}
I &= \frac{M}{l}\int (x^2 + y^2)\sqrt{dx^2 + dy^2} \\
  &= \frac{M}{l}\int (x^2 + (\pm x)^2)dx\sqrt{1 + \left(\frac{dy}{dx}\right)^2} \\
  &= \frac{M2\sqrt{2}}{l}\int x^2 dx \\
\end{align}
A: 
This is not answer of your question but,
I think it is easier to obtain the results with these  steps
I)
put at each beam local coordinate system at the center of mass
the inertia tensor in your case is:
$$\mathbf I_i= \left[ \begin {array}{ccc} 0&0&0\\ 0&1/12\,m{L}^{2}
&0\\ 0&0&1/12\,m{L}^{2}\end {array} \right] 
\quad i=1..4$$
II)
transformed  each inertia tensor parallel  to the global coordinate system
$$\mathbf I_{0i}=[\mathbf S(\theta_i)]\,\mathbf I_i\,[\mathbf S^T(\theta_i)]
$$
where
$$\mathbf S_i=\left[ \begin {array}{ccc} \cos \left( \theta_{{i}} \right) &-\sin
 \left( \theta_{{i}} \right) &0\\  \sin \left( \theta
_{{i}} \right) &\cos \left( \theta_{{i}} \right) &0
\\  0&0&1\end {array} \right] 
$$
III)
parallel axes transformation
$$ \mathbf I_{xyz}=\sum_{i=1}^4\left(\mathbf I_{0i}-m_i\,
\left[ \begin {array}{ccc} 0&0&y_{{i}}\\  0&0&0
\\  -y_{{i}}&0&0\end {array} \right]\,
\left[ \begin {array}{ccc} 0&0&y_{{i}}\\  0&0&0
\\  -y_{{i}}&0&0\end {array} \right]\right)$$
with
$$\theta=\frac{\pi}{4}\\
\theta_1=-\theta\\\theta_2=\pi+\theta\\
\theta_3=\pi-\theta\\\theta_4=\theta$$
and
$$y_1=y_2=-\frac L2\,\sin(\theta)\\
y_3=y_4=-\frac {3L}{2}\,\sin(\theta)$$
$\Rightarrow$
$$\mathbf I_{xyz}=
 \left[ \begin {array}{ccc} 8/3\,m{L}^{2}&-1/6\,m{L}^{2}&0
\\  -1/6\,m{L}^{2}&1/6\,m{L}^{2}&0
\\  0&0&{\frac {17}{6}}\,m{L}^{2}\end {array}
 \right]
$$
