Note that the cylinder equation can be transformed as follows
$$
\begin{gathered}
x^{\,2} + y^{\,2} = a\,x\quad \Rightarrow \quad x^{\,2} - 2\frac{a}
{2}x + \left( {\frac{a}
{2}} \right)^{\,2} + y^{\,2} = \left( {\frac{a}
{2}} \right)^{\,2} \quad \Rightarrow \hfill \\
\left( {x - \frac{a}
{2}} \right)^{\,2} + y^{\,2} = \left( {\frac{a}
{2}} \right)^{\,2} \hfill \\
\end{gathered}
$$
So the base circle of the cylinder is centered at $C=(a/2,0)$ and has radius $a/2$,
which is half of that of the sphere.
Then the ray from the origin to a point $P$ on the cylinder base circle, making an angle $\theta$ with the $x$ axis
will correspond to a ray from $C$ to $P$ making an angle $2 \theta$ with the $x$ axis.
So $\theta$ will range from $-\pi /2$ to $\pi/2$, where it is tangent to the base circle, and
$$
\begin{gathered}
\left| {OP} \right| = \frac{a}
{2}\sqrt {\left( {1 + \cos \left( {2\theta } \right)} \right)^{\,2} + \sin ^{\,2} \left( {2\theta } \right)} = \frac{a}
{2}\sqrt {1 + \cos ^{\,2} \left( {2\theta } \right) + 2\cos \left( {2\theta } \right) + \sin ^{\,2} \left( {2\theta } \right)} = \hfill \\
= \frac{a}
{2}\sqrt {2 + 2\cos \left( {2\theta } \right)} = \frac{a}
{2}\sqrt {2 + 2\cos ^{\,2} \theta - 2\sin ^{\,2} \theta } = a\cos \theta \hfill \\
\end{gathered}
$$