# Parametric integral with abs()

I've got the integral $$\int_B|\sin(x)-y|dx dy$$ with $$B=\{0\leq x\leq \pi, 0\leq y\leq 1\}$$ My problem is how handle the abs in the integral. I'd probably go with two integrals (one when the abs is negative, one if it's positive), but I suppose there's a nicer solution. Note: I know how to deal with parametric integrals, the question is how to integrate the absolute value.

-
First compute the integral over $0\le y\le1$ for $x$ fixed. –  Did Jun 23 '11 at 15:45

$$\int_0^\pi \int_0^1 |\sin x-y| dy dx=$$ $$\int_0^\pi\left( \int_0^{\sin x} (\sin x-y)dy +\int_{\sin x}^1 (y-\sin x)dy\right)dx=$$ $$\int_0^\pi \left( \sin^2 x- \frac{\sin^2 x}{2} + \frac{1}{2}-\sin x-\frac{\sin^2 x}{2}+\sin^2 x \right)dx=$$ $$\int_0^\pi \left(\frac{1}{2}+\sin^2 x-\sin x\right)dx$$