Converting an equation into a way java script can interpret it

Posted by GeorgeTaylor on Stack Overflow See other posts from Stack Overflow or by GeorgeTaylor
Published on 2013-10-22T21:35:08Z Indexed on 2013/10/22 21:54 UTC
Read the original article Hit count: 262

Filed under:
|
|
|
|

So I have this code that is meant to do this equation:

(1 / 15) * arccos(-tan(L) * tan(23.44 * sin(360 * (D + 284) / 365))) 

and for testing purposes alert it! But for some reason it returns "NaN". I've probably done something really stupid :P

var now = new Date();
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var oneDay = 1000 * 60 * 60 * 24;
var d = Math.floor(diff / oneDay);


var lat = position.coords.latitude;
var long = position.coords.longitude;
var tanlat = Math.atan(lat); 
var tantwentythree = Math.tan(23.44);
var dayplus = d + 284;
var sinday = Math.sin(360 * dayplus);
var arccos = Math.acos(tanlat);
var start = 1 / 15;
var equation = start * arccos * tantwentythree * sinday / 365;
alert(equation);

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about math