Moment of inertia of a square (single integral) My goal is to determine the moment of inertia of a square with the side length $a$. I know I could do this like this: 
$$J = \frac{m}{a^2}\int_{\frac{-a}{2}}^{\frac{a}{2}} \int_{\frac{-a}{2}}^{\frac{a}{2}} x^2 \,dxdy = \frac{ma^2}{12}$$
But I thought that it would also work if I integrated differently over the square area. Let's define $r = \frac{a}{2}$ so $r$ has the same distance to every side. Now I can calculate the area of the square as follows:
$$\int_{0}^{\frac{a}2} 8r\, dr = a^2$$
And with this I tried to calculate the moment of inertia:
$$\int_{0}^{\frac{a}2} r^2\cdot8r\,dr = \frac{ma^2}{8}$$
It is easy to see that the result cannot be correct. But I don't understand why? I thought that area integration works over the perimeter for all polygons, isn't that correct?
 A: Essentially you are using polar coordinates $r,\varphi$ with the origin in the center of the square. In this case $\text d r$ is a line segment along the radial coordinate and $r\text d \varphi$ would be an arclength segment on the perimeter of the circle with radius $r$. 
What you calculate in your integral
$$
\int_0^{\frac a2}8r\text d r
$$
is $\frac{8}{2\pi}$ times the area of a circle with radius $\frac a2$ since
$$
A_\text{circle}=\int_{0}^{2\pi}\int_{0}^{\frac a2}r\text dr\text d\varphi=2\pi\int_0^{\frac a2}r\text d r=\pi\left(\frac a2\right)^2
$$
A: The correct integral for area in polar coordinates is
$$A =4\left( \int_{\phi = 0}^{\frac\pi4}\int_{r=0}^{\frac{a}{2\cos\phi}} r\,drd\phi + \int_{\phi =\frac\pi4}^{\frac\pi4}\int_{r=0}^{\frac{a}{2\sin\phi}} r\,drd\phi\right) = a^2$$
integrating along the two triangles in the first quadrant, and multiplying by $4$ due to symmetry.
Similarly for $I$, the squared distance to the $y$-axis is $x^2 = r^2\cos^2\phi$ so we have
$$I = \frac{m}{a^2}\cdot4\left( \int_{\phi = 0}^{\frac\pi4}\int_{r=0}^{\frac{a}{2\cos\phi}} r^3\cos^2\phi\,drd\phi + \int_{\phi =\frac\pi4}^{\frac\pi2}\int_{r=0}^{\frac{a}{2\sin\phi}} r^3\cos^2\phi\,drd\phi\right) = \frac{ma^2}{12}$$
