Accueil > > > CALCULER LA PHASE DE LA LUNE - MOON PHASE
CALCULER LA PHASE DE LA LUNE - MOON PHASE
Information sur la source
Description
Ce Scripte vous permettra de connaître, à une date donnée, l'illumination de la Lune, son age, sa distance en km par rapport à la Terre, son angle en degrés, sa distance par rapport au soleil, et son angle par rapport au soleil. Adaptation en php du fameux et excellent scripte Astro-MoonPhase de Brett Hamilton écrit en Perl. http://search.cpan.org/~brett/Astro-MoonPhas e-0.60/
Source
- <?
- /*
- Adaptation en php du fameux et excellent scripte Astro-MoonPhase de Brett Hamilton écrit en Perl.
- http://search.cpan.org/~brett/Astro-MoonPhase-0.60/
-
- Ce Scripte vous permettra de connaître, à une date donnée, l'illumination de la Lune, son age,
- sa distance en km par rapport à la Terre, son angle en degrés, sa distance par rapport au soleil,
- et son angle par rapport au soleil.
-
- */
- class Moon
- {
- function phase($Year, $Month, $Day, $Hour, $Minutes, $Seconds)
- {
- $DateSec = mktime($Hour, $Minutes, $Seconds, $Month, $Day, $Year, 0);
-
- ini_set(precision, "20"); //Defini la precision des calcules
-
- # Astronomical constants.
- $Epoch = 2444238.5; # 1980 January 0.0
-
- # Constants defining the Sun's apparent orbit.
- $Elonge = 278.833540; # ecliptic longitude of the Sun at epoch 1980.0
- $Elongp = 282.596403; # ecliptic longitude of the Sun at perigee
- $Eccent = 0.016718; # eccentricity of Earth's orbit
- $Sunsmax = 1.495985e8; # semi-major axis of Earth's orbit, km
- $Sunangsiz = 0.533128; # sun's angular size, degrees, at semi-major axis distance
-
- # Elements of the Moon's orbit, epoch 1980.0.
- $Mmlong = 64.975464; # moon's mean longitude at the epoch
- $Mmlongp = 349.383063; # mean longitude of the perigee at the epoch
- $Mlnode = 151.950429; # mean longitude of the node at the epoch
- $Minc = 5.145396; # inclination of the Moon's orbit
- $Mecc = 0.054900; # eccentricity of the Moon's orbit
- $Mangsiz = 0.5181; # moon's angular size at distance a from Earth
- $Msmax = 384401.0; # semi-major axis of Moon's orbit in km
- $Mparallax = 0.9507; # parallax at distance a from Earth
- $Synmonth = 29.53058868; # synodic month (new Moon to new Moon)
-
- $pdate = Moon::jtime($DateSec);
-
- $pphase; # illuminated fraction
- $mage; # age of moon in days
- $dist; # distance in kilometres
- $angdia; # angular diameter in degrees
- $sudist; # distance to Sun
- $suangdia; # sun's angular diameter
-
-
- # Calculation of the Sun's position.
-
- $Day = $pdate - $Epoch; # date within epoch
- $N = Moon::fixangle((360 / 365.2422) * $Day); # mean anomaly of the Sun
- $M = Moon::fixangle($N + $Elonge - $Elongp); # convert from perigee
- # co-ordinates to epoch 1980.0
- $Ec = Moon::kepler($M, $Eccent); # solve equation of Kepler
- $Ec = sqrt((1 + $Eccent) / (1 - $Eccent)) * tan($Ec / 2);
- $Ec = 2 * Moon::todeg(atan($Ec)); # true anomaly
- $Lambdasun = Moon::fixangle($Ec + $Elongp); # Sun's geocentric ecliptic
- # longitude
- # Orbital distance factor.
- $F = ((1 + $Eccent * cos(Moon::torad($Ec))) / (1 - $Eccent * $Eccent));
- $SunDist = $Sunsmax / $F; # distance to Sun in km
- $SunAng = $F * $Sunangsiz; # Sun's angular size in degrees
-
-
- # Calculation of the Moon's position.
-
- # Moon's mean longitude.
- $ml = Moon::fixangle(13.1763966 * $Day + $Mmlong);
-
- # Moon's mean anomaly.
- $MM = Moon::fixangle($ml - 0.1114041 * $Day - $Mmlongp);
-
- # Moon's ascending node mean longitude.
- $MN = Moon::fixangle($Mlnode - 0.0529539 * $Day);
-
- # Evection.
- $Ev = 1.2739 * sin(Moon::torad(2 * ($ml - $Lambdasun) - $MM));
-
- # Annual equation.
- $Ae = 0.1858 * sin(Moon::torad($M));
-
- # Correction term.
- $A3 = 0.37 * sin(Moon::torad($M));
-
- # Corrected anomaly.
- $MmP = $MM + $Ev - $Ae - $A3;
-
- # Correction for the equation of the centre.
- $mEc = 6.2886 * sin(Moon::torad($MmP));
-
- # Another correction term.
- $A4 = 0.214 * sin(Moon::torad(2 * $MmP));
-
- # Corrected longitude.
- $lP = $ml + $Ev + $mEc - $Ae + $A4;
-
- # Variation.
- $V = 0.6583 * sin(Moon::torad(2 * ($lP - $Lambdasun)));
-
- # True longitude.
- $lPP = $lP + $V;
-
- # Corrected longitude of the node.
- $NP = $MN - 0.16 * sin(Moon::torad($M));
-
- # Y inclination coordinate.
- $y = sin(Moon::torad($lPP - $NP)) * cos(Moon::torad($Minc));
-
- # X inclination coordinate.
- $x = cos(Moon::torad($lPP - $NP));
-
- # Ecliptic longitude.
- $Lambdamoon = Moon::todeg(atan2($y, $x));
- $Lambdamoon += $NP;
-
- # Ecliptic latitude.
- $BetaM = Moon::todeg(asin(sin(Moon::torad($lPP - $NP)) * sin(Moon::torad($Minc))));
-
- # Calculation of the phase of the Moon.
-
- # Age of the Moon in degrees.
- $MoonAge = $lPP - $Lambdasun;
-
- # Phase of the Moon.
- $MoonPhase = (1 - cos(Moon::torad($MoonAge))) / 2;
-
- # Calculate distance of moon from the centre of the Earth.
-
- $MoonDist = ($Msmax * (1 - $Mecc * $Mecc)) /
- (1 + $Mecc * cos(Moon::torad($MmP + $mEc)));
-
- # Calculate Moon's angular diameter.
-
- $MoonDFrac = $MoonDist / $Msmax;
- $MoonAng = $Mangsiz / $MoonDFrac;
-
- # Calculate Moon's parallax.
-
- $MoonPar = $Mparallax / $MoonDFrac;
-
- $pphase = $MoonPhase; # illuminated fraction
- $mage = $Synmonth * (Moon::fixangle($MoonAge) / 360.0); # age of moon in days
- $dist = $MoonDist; # distance in kilometres
- $angdia = $MoonAng; # angular diameter in degrees
- $sudist = $SunDist; # distance to Sun
- $suangdia = $SunAng; # sun's angular diameter
- $mpfrac = Moon::fixangle($MoonAge) / 360.0;
- return array( $pphase, $mage, $dist, $angdia, $sudist, $suangdia, $mpfrac, $mpfrac );
- }
-
- function fixangle($x) { return ($x - 360.0 * (floor($x / 360.0))); } # fix angle
- function torad($x) { return ($x * (M_PI / 180.0)); } # deg->rad
- function todeg($x) { return ($x * (180.0 / M_PI)); } # rad->deg
-
- function jtime($t)
- {
- $julian = ($t / 86400) + 2440587.5; # (seconds /(seconds per day)) + julian date of epoch 2440587.5 / 86400 = 28,24753472222 Days
- return ($julian);
- }
-
- function kepler($m, $ecc)
- {
- $EPSILON = 1e-6;
-
- $m = Moon::torad($m);
- $e = $m;
- while (abs($delta) > $EPSILON)
- {
- $delta = $e - $ecc * sin($e) - $m;
- $e -= $delta / (1 - $ecc * cos($e));
- }
- return ($e);
- }
-
- }
-
-
- //Exemple d'utilisation :
-
- //Pour le 11 Avril 2009 à 00h00
- list($MoonPhase, $MoonAge, $MoonDist, $MoonAng, $SunDist, $SunAng, $mpfrac) = Moon::phase(2009, 04, 11, 00, 00, 01);
- echo "La Lune est éclairée à ".number_format($MoonPhase*100, 2, ',', '')."%"."<br>";
- echo "Son age est de ".number_format($MoonAge, 0, ',', '')." jours"."<br>";
- echo "Et elle se situe à une distance de ".number_format($MoonDist, 0, ',', '')." km par rapport à la Terre."."<br>";
-
-
- //Vous pouvez voir le scripte en fonctionnement sur www.CropCirclesDataBase.org
- //dans la rubrique calendrier.
- ?>
<?
/*
Adaptation en php du fameux et excellent scripte Astro-MoonPhase de Brett Hamilton écrit en Perl.
http://search.cpan.org/~brett/Astro-MoonPhase-0.60/
Ce Scripte vous permettra de connaître, à une date donnée, l'illumination de la Lune, son age,
sa distance en km par rapport à la Terre, son angle en degrés, sa distance par rapport au soleil,
et son angle par rapport au soleil.
*/
class Moon
{
function phase($Year, $Month, $Day, $Hour, $Minutes, $Seconds)
{
$DateSec = mktime($Hour, $Minutes, $Seconds, $Month, $Day, $Year, 0);
ini_set(precision, "20"); //Defini la precision des calcules
# Astronomical constants.
$Epoch = 2444238.5; # 1980 January 0.0
# Constants defining the Sun's apparent orbit.
$Elonge = 278.833540; # ecliptic longitude of the Sun at epoch 1980.0
$Elongp = 282.596403; # ecliptic longitude of the Sun at perigee
$Eccent = 0.016718; # eccentricity of Earth's orbit
$Sunsmax = 1.495985e8; # semi-major axis of Earth's orbit, km
$Sunangsiz = 0.533128; # sun's angular size, degrees, at semi-major axis distance
# Elements of the Moon's orbit, epoch 1980.0.
$Mmlong = 64.975464; # moon's mean longitude at the epoch
$Mmlongp = 349.383063; # mean longitude of the perigee at the epoch
$Mlnode = 151.950429; # mean longitude of the node at the epoch
$Minc = 5.145396; # inclination of the Moon's orbit
$Mecc = 0.054900; # eccentricity of the Moon's orbit
$Mangsiz = 0.5181; # moon's angular size at distance a from Earth
$Msmax = 384401.0; # semi-major axis of Moon's orbit in km
$Mparallax = 0.9507; # parallax at distance a from Earth
$Synmonth = 29.53058868; # synodic month (new Moon to new Moon)
$pdate = Moon::jtime($DateSec);
$pphase; # illuminated fraction
$mage; # age of moon in days
$dist; # distance in kilometres
$angdia; # angular diameter in degrees
$sudist; # distance to Sun
$suangdia; # sun's angular diameter
# Calculation of the Sun's position.
$Day = $pdate - $Epoch; # date within epoch
$N = Moon::fixangle((360 / 365.2422) * $Day); # mean anomaly of the Sun
$M = Moon::fixangle($N + $Elonge - $Elongp); # convert from perigee
# co-ordinates to epoch 1980.0
$Ec = Moon::kepler($M, $Eccent); # solve equation of Kepler
$Ec = sqrt((1 + $Eccent) / (1 - $Eccent)) * tan($Ec / 2);
$Ec = 2 * Moon::todeg(atan($Ec)); # true anomaly
$Lambdasun = Moon::fixangle($Ec + $Elongp); # Sun's geocentric ecliptic
# longitude
# Orbital distance factor.
$F = ((1 + $Eccent * cos(Moon::torad($Ec))) / (1 - $Eccent * $Eccent));
$SunDist = $Sunsmax / $F; # distance to Sun in km
$SunAng = $F * $Sunangsiz; # Sun's angular size in degrees
# Calculation of the Moon's position.
# Moon's mean longitude.
$ml = Moon::fixangle(13.1763966 * $Day + $Mmlong);
# Moon's mean anomaly.
$MM = Moon::fixangle($ml - 0.1114041 * $Day - $Mmlongp);
# Moon's ascending node mean longitude.
$MN = Moon::fixangle($Mlnode - 0.0529539 * $Day);
# Evection.
$Ev = 1.2739 * sin(Moon::torad(2 * ($ml - $Lambdasun) - $MM));
# Annual equation.
$Ae = 0.1858 * sin(Moon::torad($M));
# Correction term.
$A3 = 0.37 * sin(Moon::torad($M));
# Corrected anomaly.
$MmP = $MM + $Ev - $Ae - $A3;
# Correction for the equation of the centre.
$mEc = 6.2886 * sin(Moon::torad($MmP));
# Another correction term.
$A4 = 0.214 * sin(Moon::torad(2 * $MmP));
# Corrected longitude.
$lP = $ml + $Ev + $mEc - $Ae + $A4;
# Variation.
$V = 0.6583 * sin(Moon::torad(2 * ($lP - $Lambdasun)));
# True longitude.
$lPP = $lP + $V;
# Corrected longitude of the node.
$NP = $MN - 0.16 * sin(Moon::torad($M));
# Y inclination coordinate.
$y = sin(Moon::torad($lPP - $NP)) * cos(Moon::torad($Minc));
# X inclination coordinate.
$x = cos(Moon::torad($lPP - $NP));
# Ecliptic longitude.
$Lambdamoon = Moon::todeg(atan2($y, $x));
$Lambdamoon += $NP;
# Ecliptic latitude.
$BetaM = Moon::todeg(asin(sin(Moon::torad($lPP - $NP)) * sin(Moon::torad($Minc))));
# Calculation of the phase of the Moon.
# Age of the Moon in degrees.
$MoonAge = $lPP - $Lambdasun;
# Phase of the Moon.
$MoonPhase = (1 - cos(Moon::torad($MoonAge))) / 2;
# Calculate distance of moon from the centre of the Earth.
$MoonDist = ($Msmax * (1 - $Mecc * $Mecc)) /
(1 + $Mecc * cos(Moon::torad($MmP + $mEc)));
# Calculate Moon's angular diameter.
$MoonDFrac = $MoonDist / $Msmax;
$MoonAng = $Mangsiz / $MoonDFrac;
# Calculate Moon's parallax.
$MoonPar = $Mparallax / $MoonDFrac;
$pphase = $MoonPhase; # illuminated fraction
$mage = $Synmonth * (Moon::fixangle($MoonAge) / 360.0); # age of moon in days
$dist = $MoonDist; # distance in kilometres
$angdia = $MoonAng; # angular diameter in degrees
$sudist = $SunDist; # distance to Sun
$suangdia = $SunAng; # sun's angular diameter
$mpfrac = Moon::fixangle($MoonAge) / 360.0;
return array( $pphase, $mage, $dist, $angdia, $sudist, $suangdia, $mpfrac, $mpfrac );
}
function fixangle($x) { return ($x - 360.0 * (floor($x / 360.0))); } # fix angle
function torad($x) { return ($x * (M_PI / 180.0)); } # deg->rad
function todeg($x) { return ($x * (180.0 / M_PI)); } # rad->deg
function jtime($t)
{
$julian = ($t / 86400) + 2440587.5; # (seconds /(seconds per day)) + julian date of epoch 2440587.5 / 86400 = 28,24753472222 Days
return ($julian);
}
function kepler($m, $ecc)
{
$EPSILON = 1e-6;
$m = Moon::torad($m);
$e = $m;
while (abs($delta) > $EPSILON)
{
$delta = $e - $ecc * sin($e) - $m;
$e -= $delta / (1 - $ecc * cos($e));
}
return ($e);
}
}
//Exemple d'utilisation :
//Pour le 11 Avril 2009 à 00h00
list($MoonPhase, $MoonAge, $MoonDist, $MoonAng, $SunDist, $SunAng, $mpfrac) = Moon::phase(2009, 04, 11, 00, 00, 01);
echo "La Lune est éclairée à ".number_format($MoonPhase*100, 2, ',', '')."%"."<br>";
echo "Son age est de ".number_format($MoonAge, 0, ',', '')." jours"."<br>";
echo "Et elle se situe à une distance de ".number_format($MoonDist, 0, ',', '')." km par rapport à la Terre."."<br>";
//Vous pouvez voir le scripte en fonctionnement sur www.CropCirclesDataBase.org
//dans la rubrique calendrier.
?>
Conclusion
Vous pouvez voir le scripte en fonctionnement sur www.CropCirclesDataBase.org dans la rubrique calendrier.
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : SONDAGE..RE : SONDAGE.. par phpAnonyme
Cliquez pour lire la suite par phpAnonyme RE : SONDAGE..RE : SONDAGE.. par TychoBrahe
Cliquez pour lire la suite par TychoBrahe
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|