Let's write \(\displaystyle x/z=u\) and \(\displaystyle y/z=w\) for simplicity.

Suppose \(\displaystyle \arccos(u)-\arccos(w)=t\)

then \(\displaystyle \cos(\arccos(u)-\arccos(w))=\cos(t)\)

and thus by sum formula for cosinus we have \(\displaystyle uw+\sin(\arccos(u))\sin(\arccos(w))=\cos(t)\)

and now because \(\displaystyle \sin(\arccos(u))=\sqrt{1-u^2}\)

we have \(\displaystyle uw+\sqrt{1-u^2}\sqrt{1-w^2}=\cos(t)\)

so \(\displaystyle t = \arccos(uw+\sqrt{1-u^2}\sqrt{1-w^2})\)

Now replace u and w by their original values again...