Javascript for ephemeris

Javascript for ephemeris

Post by Eurydic » Thu, 05 Aug 2004 18:53:09


I would like to put a javascript code to obtain on my meteo page
http://www.yqcomputer.com/
sunset of the sun according to the date.

I have found nothing on the net up to now that satisfies me.

Thanks if you can give me a link for this.


--
Faites que le re dore votre vie afin que la vie ne dore pas votre
re.
[Antoine de Saint Exupy]
email : Dalip at ifrance.com
http://www.yqcomputer.com/
 
 
 

Javascript for ephemeris

Post by Richard Co » Fri, 06 Aug 2004 01:09:47


It is an interesting characteristic of orbital mechanics that you cannot
directly evaluate orbital position from time. Instead an angle (from the
planet to the centre of its elliptical orbit) called the 'Mean Anomaly'
is calculated based on constant motion in a circular orbit (time
directly relates to that angle) and the real angle to the planet (from
the centre of its elliptical orbit) progressively approximated using
code such as:-

function meanAnomilyToEccentricAnomaly (meanAnomaly, e){
var eccentricAnomaly = meanAnomaly;
var newValue;
var acceptableDiff = 1e-10; //precision of approximation
do{
newValue = eccentricAnomaly;
eccentricAnomaly = (meanAnomaly - (e*Math.sin(eccentricAnomaly)));
}while(Math.abs(newValue - eccentricAnomaly) > acceptableDiff);
return eccentricAnomaly;
}

Where - e - is the elliptical eccentricity of the planet's orbit.
(Angles in Radians, as is normal in javascript).

The approximation works because planetary orbits are nearly circular.

Working out the approximate position of the earth in relation to the sun
at any given time would require knowing an angle at a moment in time.
The exact moment of perihelion or aphelion (recently so as not to suffer
too much from the approximations).

Unfortunately, working out the approximate location of the sun in
relation to the earth at a particular moment in time is not enough. The
orientation of the earth is also a factor; the orientation of its axis
of rotation and the degree to which it is rotated. And then the exact
times of sunrise and sunset are determined by the longitude and latitude
of the observer on the surface of the earth.

I would be very surprised to find that there was a client-side script
that calculates this in existence (or that it would be accurate enough
to be useful).

Richard.

 
 
 

Javascript for ephemeris

Post by Fox » Fri, 06 Aug 2004 17:29:31


NOAA has pretty good JS calculators:

sunrise/sunset/solor noon:
http://www.yqcomputer.com/

solar position:
http://www.yqcomputer.com/

the Jet Propulsion Laboratory @ NASA claims this calculator is accurate
from 1000BCE to 3000CE