Skip to content

Commit 3ea1a64

Browse files
authored
Merge pull request #71 from WimDeMeester/master
Added the moon phase ratio of the moon.
2 parents 47ce846 + db94593 commit 3ea1a64

4 files changed

Lines changed: 44 additions & 6 deletions

File tree

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ All notable changes to `laravel-astronomy-library` will be documented in this fi
66

77
### Added
88

9-
- Added the moon phase ratio to the calculation of the illumination of the moon.
9+
- Added the moon phase ratio of the moon.
1010

1111
## Version 5.4
1212

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ $moon->calculateEquatorialCoordinates($date, $geo_coords, $heightOfLocation);
525525

526526
// Calculate the illumination of the moon
527527
$moon->illuminatedFraction($date);
528+
529+
// Calculate the moon phase ration (0-1) of the moon
530+
$moon->getPhaseRatio($date);
528531
```
529532

530533
## Change log

src/deepskylog/AstronomyLibrary/Targets/Moon.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/Unit/TargetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ public function testMoonIllumination()
958958
{
959959
$date = Carbon::create(1992, 4, 12, 0, 0, 0, 'UTC');
960960
$moon = new Moon();
961-
$illum = $moon->illuminatedFraction($date)[0];
961+
$illum = $moon->illuminatedFraction($date);
962962

963963
$this->assertEqualsWithDelta(0.680, $illum, 0.001);
964964
}

0 commit comments

Comments
 (0)