<s>[INST] Limits of integration for theta in double integrals I have a question that asks me to find the volume lying inside both the sphere $x^2+y^2+z^2=a^2$ and the cylinder $x^2+y^2=ax$. The worked solution in the textbook goes like this
One quarter of the required volume lies in the first octant. In polar coordinates the cylinder $x^2 + y^2 = ax$ becomes $r = a cos θ$. Thus, the required volume is
$$
V=4\iint_D\sqrt{a^2-x^2-y^2}\,dA=4\int_0^{\pi/2}\int_0^{a\cos\theta}\sqrt{a^2-r^2}\,r\,dr\,d\theta=\frac{2\pi a^3}{3}-\frac{8a^3}{9}
$$
My question is why can't I do the integral from $0$ to $2\pi$ and get the same answer.
$$
V=\int_0^{2\pi}\int_0^{a\cos\theta}\sqrt{a^2-r^2}\,r\,dr\,d\theta=\frac{2\pi a^3}{3}
$$
Why do these answers differ? and how can you know when you have to split it up and when you can integrate all the way through?
 [/INST] In polar coordinates, $ \theta \in (0, 2\pi)$ is valid for the circle centered at the origin. But we have a circle that is centered on x-axis away from the origin and in fact the origin is a point on the circle.
The projection of the cylinder in XY-plane is circle $x^2 + y^2 = ax$.
Or, $ \displaystyle \left(x - \frac{a}{2}\right)^2 + y^2 = \frac{a^2}{4}$. This is a circle centered at $(a/2, 0)$ with radius $a/2$.
Now if we use the parametrization $x = r \cos\theta, y = r \sin\theta$ which measures radial distance from the origin, $x^2 + y^2 = ax$ simplifies to $r = a \cos\theta$. Also note that the circle is in the fourth and the first quadrant, and hence $ \theta \in (- \pi/2, \pi/2)$ covers the entire circle. Please see the below diagram for further explanation.

However if we parametrize the circle as $x = \frac{a}{2} + r \cos\theta, y = r \sin \theta$, which translates the origin to $(a/2, 0)$, the limits of $\theta$ will be $(0, 2\pi)$.
</s>