Centroid of wedge I am going crazy trying to figure out what I am doing wrong on this basic problem. I need to find the $y$ coordinate of the center of mass of a pan of water that is sloshing back and forth. Let the equilibrium height be $h$, the length of the pan be $L$, and the height at $x=L$ be $y=h+b$. The coordinate of the center of mass should be
$$
y_{CM}= \frac{1}{M} \iint y \rho dA
$$
Here, we have $y = (h-b) + \frac{2b}{L} x$. We also have $dA = y dx$. Thus, the coordinate is 
$$
y_{CM}= \frac{\rho}{M} \int_0^L \left( (h-b) + \frac{2b}{L} x  \right)^2 dx = \frac{b^2}{3h} + h
$$
where we have used the fact that $M = \rho h L$. But this result is incorrect because when $b = 0$ we should have $y_{CM} = \frac{h}{2}$ not $h$. The result should be (I think) $y_{CM} = \frac{h-b}{2} + \frac{2b}{3}$ obtained by simply adding the positions of the center of masses of the two regions. However, I am more interested in what about this method is incorrect.
Here is a diagram to make the shape more explicit. 

 A: Looks like you might’ve been a bit hasty in converting the double integral into iterated definite integrals. Factoring out the constant density $\rho$, you’ve got $$y_{CM}=\frac1{Lh}\iint y\,dA = \frac1{Lh}\int_0^L\int_0^{y(x)}y\,dy\,dx=\frac1{Lh}\int_0^L\frac12y^2\,dx.$$ Comparing this to your integral, there’s a factor of $\frac12$ that you missed by not also integrating in the $y$-direction.
A: There is the factor $\frac{1}{2}$ missing due to not doing the integration over $y$. Due to insight in physics you already noticed that there was a mistake, which is always good. (Correct result should be $y_c=\frac{b}{6 h} + \frac{h^2}{2}$.)
You also came up with a second option to get the result, via the addition of centres of mass of the rectangular and triangular areas. This is a nice alternative approach, but you can not simply add the positions of the centres of mass go both of them. You need to take an average of them. Moreover, you need to weight them because a large mass is far more important for the combined centre of mass than a much lighter one. You would need to use:
$$
y_{tot} = \frac{m_1 y_1 + m_2 y_2}{m_1+m_2}
$$
where $m_i$ are the masses and $y_i$ the locations of them to get the combined centre of mass.
The centre of mass of the rectangular mass is indeed $y_1 = \frac{h-b}{2}$, but the one for the triangle $y_2 = \frac{2 b}{3}$ is wrong. Should that depend on $h$ or not?
As another remark on physics, you could use either method also to locate the $x$-position of the centre of mass. Unless $b=0$, it will not be at $x=\frac{L}{2}$ but will swing about that. This explains why a pan with a sufficient amount of sloshing water will tend to move. 
