The conversion from degrees to a radian is:
var rad = angle * Math.PI / 180
A 90 degree angle equals 1.57079633 radian
var cos = Math.cos(angle * Math.PI / 180);
I am obviously missing something obvious here, but boy is it screwing up the code.