In reply to CES.

Thanks for writing. I apologize for the confusion. In my program, I used two different angles (not sure why), and the notation in the program does not match the figure. Also, as you point out, it is unnecessary to introduce south=3*pi/2. In my original computation,
cos(theta) = cos(3*pi/2 + angle/2) = sin(angle/2)
and
sin(theta) = sin(3*pi/2 + angle/2) = -cos(angle/2)
so the answer was correct, but the method waas unnecessarily complicated.
I will revise the program to get rid of 'south' and only use the angle. I will also make sure that the figure and program use consistent notation. Thanks!