Eurydice wrote:
I would like to put a javascript code to obtain on my meteo page
http://perso.wanadoo.fr/jmrw/Meteo/Meteo.shtml the time of the raise
and the 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.
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.