To cut a long story short - I needed some JS code to draw a vertical line on a webpage I'm developing. So I hunted around for some lightweight code (no frameworks or canvas) and found this:
HTML line drawing without canvas (just JS)
I dropped it into my page and it worked. Sort of. Even though I'd given it the co-ordinates to draw a vertical line, it decided that the line must be horizontal. The code in question appears to be this:
var calc=Math.atan((ay-by)/(bx-ax));
calc=calc*180/Math.PI;
If I force the angle to be zero, all is well (see here for a JSFiddle and try toggling the calcAngle flag).
How does this code decide which angle the line should be?
N.B. the JSFiddle is just a demonstration of the problem and not anything to do with the site itself so please don't get hung up on the specifics of this code.