$\cos(\arcsin(x)) = \sqrt{1 - x^2}$. How? How does that bit work?
How is
$$\cos(\arcsin(x)) = \sin(\arccos(x)) = \sqrt{1 - x^2}$$

If $\arcsin(x) = a \in [-\pi/2,\pi/2]$, we then have $\sin(a) = x \in [-1,1]$. Since $\cos^2(a) + \sin^2(a) = 1$, we have $$\cos(a) = \pm \sqrt{1-\sin^2(a)} = \pm \sqrt{1-x^2}$$
But since $a \in [-\pi/2,\pi/2]$, we have $\cos(a) \geq 0$. Hence, we get that
$$\cos(a) = \sqrt{1-x^2}$$
