The error was indeed the plotting offset: the drawing is done on an Inform PictureBox, which is placed at (10,10) in the window. How did I manage not to spot this offset?? Anyway, program corrected and replaced at the beginning of this post. My apologies. Let me know if you find any remaining errors.
In this program, the Y- dimension is increasing as vertical position goes downwards (standard screen convention). Originally I had intended to correct all the trig calculations as if Y- increases in the upward direction. But as the geometry is mirror symmetric in Y-, this has not seemed necessary (but highlights the lack of rigorousness in the coder).