Document that for spherical coordinates theta is going from x to y and phi is going from xy-plane to z. This definition of phi differs from the mathematically defined phi: https://en.wikipedia.org/wiki/Spherical_coordinate_system