@@ -365,15 +365,15 @@ private function _calculateEquatorialCoordinates(Carbon $date, GeographicalCoord
365365 }
366366
367367 /**
368- * Calculates the illuminated fraction of the planet .
368+ * Calculates the illuminated fraction of the moon .
369369 *
370370 * @param Carbon $date The date for which to calculate the fraction
371371 *
372- * @return array The illuminated fraction, the phase ratio
372+ * @return float The illuminated fraction, the phase ratio
373373 *
374374 * See chapter 58 of Astronomical Algorithms
375375 */
376- public function illuminatedFraction (Carbon $ date ): array
376+ public function illuminatedFraction (Carbon $ date ): float
377377 {
378378 // T = julian centuries since epoch J2000.0
379379 $ T = (Time::getJd ($ date ) - 2451545.0 ) / 36525.0 ;
@@ -396,6 +396,41 @@ public function illuminatedFraction(Carbon $date): array
396396
397397 $ i = $ i - floor ($ i / 360.0 ) * 360.0 ;
398398
399- return [round ((1 + cos (deg2rad ($ i ))) / 2 , 3 ), $ i / 360 ];
399+ return round ((1 + cos (deg2rad ($ i ))) / 2 , 3 );
400+ }
401+
402+ /**
403+ * Calculates the phase ration of the moon (0 - 1).
404+ *
405+ * @param Carbon $date The date for which to calculate the phase ration
406+ *
407+ * @return float The phase ratio
408+ *
409+ * See chapter 58 of Astronomical Algorithms
410+ */
411+ public function getPhaseRatio (Carbon $ date ): float
412+ {
413+ // T = julian centuries since epoch J2000.0
414+ $ T = (Time::getJd ($ date ) - 2451545.0 ) / 36525.0 ;
415+
416+ // Mean elongation of the moon
417+ $ D = (new Coordinate (297.8501921 + 445267.1114023 * $ T - 0.0018819 * $ T ** 2 + $ T ** 3 / 545868.0 - $ T ** 4 / 113065000.0 ))->getCoordinate ();
418+
419+ // Sun's mean anomaly
420+ $ M = (new Coordinate (357.5291092 + 35999.0502909 * $ T - 0.0001536 * $ T ** 2 + $ T ** 3 / 24490000.0 ))->getCoordinate ();
421+
422+ // Moon's mean anomaly
423+ $ M_accent = (new Coordinate (134.9633964 + 477198.8675055 * $ T + 0.0087414 * $ T ** 2 + $ T ** 3 / 69699.0 - $ T ** 4 / 14712000.0 ))->getCoordinate ();
424+
425+ $ i = 180 - $ D - 6.289 * sin (deg2rad ($ M_accent ))
426+ + 2.100 * sin (deg2rad ($ M ))
427+ - 1.274 * sin (deg2rad (2 * $ D - $ M_accent ))
428+ - 0.658 * sin (deg2rad (2 * $ D ))
429+ - 0.214 * sin (deg2rad (2 * $ M_accent ))
430+ - 0.110 * sin (deg2rad ($ D ));
431+
432+ $ i = $ i - floor ($ i / 360.0 ) * 360.0 ;
433+
434+ return $ i / 360 ;
400435 }
401436}
0 commit comments