Well, the biggest problem I see here is:
alpha = arctan (tan(lambda) x cos(epsilon)) // in same quadrant as lambda ... var alpha = Math.atan(Math.tan(lambda) * Math.sin(epsilon));
You have moved from using cosine to sine in the second expression.
Now, this at first glance does not lead to the same result, so let's dig a little deeper. For clarity, I will use these functions and constants:
var lambda = 326.186; var epsilon = 23.4396; function rad (v) { return v * Math.PI / 180 } function deg (v) { return v * 180 / Math.PI }
Javascript math functions take a radial coordinate, so let's try:
var result = deg(Math.atan(Math.tan(rad(lambda)) * Math.cos(rad(epsilon)))); console.log(result);
Thanks to the magic of how the degrees work, this is the same answer as 360 + -31.5717 = 328.428.
source share