All math functions in JavaScript use radians in place of degrees. Yet they are either unequal, or I am way off base.
The conversion from degrees to a radian is:
var rad = angle * Math.PI / 180
A 90 degree angle equals 1.57079633 radian
The cosine of a 90 degree angle equals 0.
The cosine of a 1.57079633 radian equals -3.20510345 × 10-9.
Note that in the Javascript, everything is done in one step to avoid rounding errors:
var cos = Math.cos(angle * Math.PI / 180);
I am obviously missing something obvious here, but boy is it screwing up the code.