Your formula is correct for all angles. But the names that you’ve given the angles are probably not quite right. What you’ve called “horizontal angle” is the inclination angle – the angle between the vector and the z-axis. So if “horizontal angle” is 0, then the point lies on the z-axis, which means that it is correct for x and y to both be 0. What you’ve called “vertical angle” is actually the angle in the x-y plane. If it is 0, then the point lies in the x-z plane, so y is correctly set to 0.