When finding the $y$-coordinate of a centroid, for $f$ as a function of $x$, I understand the formula:
$\bar y = \frac12 \int f(x)^2 dx$ when the lower function is $y=0$
What I don't understand is why, for upper function $f= f(x)$ and lower function $g = g(x)$
$\bar y = \frac12 \int (f(x)^2 - g(x)^2) dx$
I would have expected $y-bar = \frac12 \int (f(x)-g(x))^2 dx$
In other words, I would have expected $f-g$ to be subtracted first, then squaring, rather than squaring first, then subtracting.
I tend to think of these thing in terms of multivariate calculus and double integration.
$\bar y = \displaystyle\frac {\iint y\ dy\ dx}{\iint \ dy\ dx} = \frac {\int \frac 12 y^2 dx}{\int y\ dx}\\ \bar x = \displaystyle\frac {\iint x\ dy\ dx}{\iint \ dy\ dx} = \frac {\int xy\ dx}{\int y\ dx}$
Looking more closely at $\bar y$ bounded above and below by $f(x)$ and $g(x)$ respectively.
$\displaystyle\iint_{g(x)}^{f(x)} y \ dy \ dx = \int \frac 12 y^2|_{g(x)}^{f(x)}\ dx = \frac 12 \int (f(x))^2 - (g(x))^2\ dx$
But you probably haven't learned double integration yet....
The next thing I can say is that there is a certain parallel between these formula and the formula for volume of integration.
Revolution around the x axis (via washers)
$\displaystyle\pi \int f(x)^2 - g(x)^2\ dx $
Revolution around the y axis (via shells)
$\displaystyle2\pi \int x(f(x) - g(x))\ dx $
They are similar integrals to what you use for the centroid. The difference is a factor of $2\pi$ and a factor of the area of the region.
Pappus' theorem ties these two concepts together. The volume of a solid is of revolution is the area of the cross section times the distance that the centroid travels.