This looks dangerous for theta == pi/2.