Ok this is a really silly question and I should know this, but I can't seem to figure something out:
for the last step, how do they know that $0 \leq x \leq 4$? If we use the minimum value of theta, which is $-\pi/2$, and plug that into $x=\cos(\theta)$, then we get $0$, and same for $\pi/2$.