Skip to content

Commit 20f2611

Browse files
committed
Diameter of Sun, Moon, Planets
1 parent c2ea71b commit 20f2611

12 files changed

Lines changed: 855 additions & 7662 deletions

File tree

changelog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes to `laravel-astronomy-library` will be documented in this file.
44

5+
## Version 5.6
6+
7+
### Added
8+
9+
- Methods to calculate the diameter of the Sun, Moon and planets.
10+
11+
### Changed
12+
13+
- Corrected calculation of coordinates of Mercury.
14+
515
## Version 5.5
616

717
### Added

readme.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,12 @@ $moon->newMoonDate($date);
534534
$moon->firstQuarterMoonDate($date);
535535
$moon->fullMoonDate($date);
536536
$moon->lastQuarterMoonDate($date);
537+
538+
// Calculate the diameter of the sun, moon, planets
539+
$mercury = new Mercury();
540+
$date = Carbon::create(1992, 12, 20, 0, 0, 0, 'UTC');
541+
$mercury->calculateDiameter($date);
542+
$diameter = $mercury->getDiameter();
537543
```
538544

539545
## Change log

src/deepskylog/AstronomyLibrary/Targets/Jupiter.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3769,4 +3769,31 @@ public function magnitude(Carbon $date): float
37693769

37703770
return round(-8.93 + 5 * log10($R * $delta), 1);
37713771
}
3772+
3773+
/**
3774+
* Calculate the diameter of Jupiter. You can get the diamter
3775+
* by using the getDiameter method.
3776+
*
3777+
* @param Carbon $date The date
3778+
*
3779+
* @return None
3780+
*
3781+
* Chapter 55 of Astronomical Algorithms
3782+
*/
3783+
public function calculateDiameter(Carbon $date)
3784+
{
3785+
$helio_coords = $this->calculateHeliocentricCoordinates($date);
3786+
3787+
$earth = new Earth();
3788+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
3789+
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
3790+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
3791+
$y = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * sin(deg2rad($helio_coords[0])) -
3792+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * sin(deg2rad($helio_coords_earth[0]));
3793+
$z = $helio_coords[2] * sin(deg2rad($helio_coords[1])) -
3794+
$helio_coords_earth[2] * sin(deg2rad($helio_coords_earth[1]));
3795+
$delta = sqrt($x ** 2 + $y ** 2 + $z ** 2);
3796+
3797+
$this->setDiameter(round(2 * 98.44 / $delta, 1));
3798+
}
37723799
}

src/deepskylog/AstronomyLibrary/Targets/Mars.php

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace deepskylog\AstronomyLibrary\Targets;
1515

1616
use Carbon\Carbon;
17-
use deepskylog\AstronomyLibrary\Coordinates\Coordinate;
1817
use deepskylog\AstronomyLibrary\Time;
18+
use deepskylog\AstronomyLibrary\Coordinates\Coordinate;
1919

2020
/**
2121
* The target class describing Mars.
@@ -47,15 +47,15 @@ class Mars extends Planet
4747
public function calculateMeanOrbitalElements(Carbon $date)
4848
{
4949
$jd = Time::getJd($date);
50-
$T = ($jd - 2451545.0) / 36525.0;
50+
$T = ($jd - 2451545.0) / 36525.0;
5151

52-
$L = (new Coordinate(355.433000 + 19141.6964471 * $T + 0.00031052 * $T ** 2 + 0.000000016 * $T ** 3, 0, 360))->getCoordinate();
53-
$a = 1.523679342;
54-
$e = 0.09340065 + 0.000090484 * $T - 0.0000000806 * $T ** 2 - 0.00000000025 * $T ** 3;
55-
$i = (new Coordinate(1.849726 - 0.0006011 * $T + 0.00001276 * $T ** 2 - 0.000000007 * $T ** 3, 0, 360))->getCoordinate();
52+
$L = (new Coordinate(355.433000 + 19141.6964471 * $T + 0.00031052 * $T ** 2 + 0.000000016 * $T ** 3, 0, 360))->getCoordinate();
53+
$a = 1.523679342;
54+
$e = 0.09340065 + 0.000090484 * $T - 0.0000000806 * $T ** 2 - 0.00000000025 * $T ** 3;
55+
$i = (new Coordinate(1.849726 - 0.0006011 * $T + 0.00001276 * $T ** 2 - 0.000000007 * $T ** 3, 0, 360))->getCoordinate();
5656
$omega = (new Coordinate(49.558093 + 0.7720959 * $T + 0.00001557 * $T ** 2 + 0.000002267 * $T ** 3, 0, 360))->getCoordinate();
57-
$pi = (new Coordinate(336.060234 + 1.8410449 * $T - 0.00013477 * $T ** 2 + 0.000000536 * $T ** 3, 0, 360))->getCoordinate();
58-
$M = $L - $pi;
57+
$pi = (new Coordinate(336.060234 + 1.8410449 * $T - 0.00013477 * $T ** 2 + 0.000000536 * $T ** 3, 0, 360))->getCoordinate();
58+
$M = $L - $pi;
5959

6060
return [$L, $a, $e, $i, $omega, $pi, $M];
6161
}
@@ -78,15 +78,15 @@ public function calculateMeanOrbitalElements(Carbon $date)
7878
public function calculateMeanOrbitalElementsJ2000(Carbon $date)
7979
{
8080
$jd = Time::getJd($date);
81-
$T = ($jd - 2451545.0) / 36525.0;
81+
$T = ($jd - 2451545.0) / 36525.0;
8282

83-
$L = (new Coordinate(355.433000 + 19140.2993039 * $T + 0.00000262 * $T ** 2 - 0.000000003 * $T ** 3, 0, 360))->getCoordinate();
84-
$a = 1.523679342;
85-
$e = 0.09340065 + 0.000090484 * $T - 0.0000000806 * $T ** 2 - 0.00000000025 * $T ** 3;
86-
$i = (new Coordinate(1.849726 - 0.0081477 * $T - 0.00002255 * $T ** 2 - 0.000000029 * $T ** 3, 0, 360))->getCoordinate();
83+
$L = (new Coordinate(355.433000 + 19140.2993039 * $T + 0.00000262 * $T ** 2 - 0.000000003 * $T ** 3, 0, 360))->getCoordinate();
84+
$a = 1.523679342;
85+
$e = 0.09340065 + 0.000090484 * $T - 0.0000000806 * $T ** 2 - 0.00000000025 * $T ** 3;
86+
$i = (new Coordinate(1.849726 - 0.0081477 * $T - 0.00002255 * $T ** 2 - 0.000000029 * $T ** 3, 0, 360))->getCoordinate();
8787
$omega = (new Coordinate(49.558093 - 0.2950250 * $T - 0.00064048 * $T ** 2 - 0.000001964 * $T ** 3, 0, 360))->getCoordinate();
88-
$pi = (new Coordinate(336.060234 + 0.4439016 * $T - 0.00017313 * $T ** 2 + 0.000000518 * $T ** 3, 0, 360))->getCoordinate();
89-
$M = $L - $pi;
88+
$pi = (new Coordinate(336.060234 + 0.4439016 * $T - 0.00017313 * $T ** 2 + 0.000000518 * $T ** 3, 0, 360))->getCoordinate();
89+
$M = $L - $pi;
9090

9191
return [$L, $a, $e, $i, $omega, $pi, $M];
9292
}
@@ -5628,17 +5628,17 @@ public function calculateHeliocentricCoordinates(Carbon $date): array
56285628
*/
56295629
public function opposition(Carbon $date): Carbon
56305630
{
5631-
$A = 2452097.382;
5632-
$B = 779.936104;
5631+
$A = 2452097.382;
5632+
$B = 779.936104;
56335633
$M0 = 181.9573;
56345634
$M1 = 48.705244;
56355635

56365636
$Y = $date->year + $date->dayOfYear / (365 + $date->format('L'));
56375637

5638-
$k = ceil((365.2425 * $Y + 1721060 - $A) / ($B));
5638+
$k = ceil((365.2425 * $Y + 1721060 - $A) / ($B));
56395639
$JDE0 = $A + $k * $B;
5640-
$M = deg2rad($M0 + $k * $M1);
5641-
$T = ($JDE0 - 2451545) / 36525;
5640+
$M = deg2rad($M0 + $k * $M1);
5641+
$T = ($JDE0 - 2451545) / 36525;
56425642

56435643
$diff = -0.3088 + 0.0000 * $T + 0.00002 * $T * $T
56445644
+ (-17.6965 + 0.0363 * $T + 0.00005 * $T * $T) * sin($M)
@@ -5668,17 +5668,17 @@ public function opposition(Carbon $date): Carbon
56685668
*/
56695669
public function conjunction(Carbon $date): Carbon
56705670
{
5671-
$A = 2451707.414;
5672-
$B = 779.936104;
5671+
$A = 2451707.414;
5672+
$B = 779.936104;
56735673
$M0 = 157.6047;
56745674
$M1 = 48.705244;
56755675

56765676
$Y = $date->year + $date->dayOfYear / (365 + $date->format('L'));
56775677

5678-
$k = ceil((365.2425 * $Y + 1721060 - $A) / ($B));
5678+
$k = ceil((365.2425 * $Y + 1721060 - $A) / ($B));
56795679
$JDE0 = $A + $k * $B;
5680-
$M = deg2rad($M0 + $k * $M1);
5681-
$T = ($JDE0 - 2451545) / 36525;
5680+
$M = deg2rad($M0 + $k * $M1);
5681+
$T = ($JDE0 - 2451545) / 36525;
56825682

56835683
$diff = 0.3102 - 0.0001 * $T + 0.00001 * $T * $T
56845684
+ (9.7273 - 0.0156 * $T + 0.00001 * $T * $T) * sin($M)
@@ -5751,11 +5751,11 @@ public function aphelionDate(Carbon $date): Carbon
57515751
public function magnitude(Carbon $date): float
57525752
{
57535753
$helio_coords = $this->calculateHeliocentricCoordinates($date);
5754-
$R = $helio_coords[2];
5754+
$R = $helio_coords[2];
57555755

5756-
$earth = new Earth();
5756+
$earth = new Earth();
57575757
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
5758-
$R0 = $helio_coords_earth[2];
5758+
$R0 = $helio_coords_earth[2];
57595759

57605760
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
57615761
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
@@ -5769,4 +5769,31 @@ public function magnitude(Carbon $date): float
57695769

57705770
return round(-1.3 + 5 * log10($R * $delta) + 0.01486 * $i, 1);
57715771
}
5772+
5773+
/**
5774+
* Calculate the diameter of Mars. You can get the diamter
5775+
* by using the getDiameter method.
5776+
*
5777+
* @param Carbon $date The date
5778+
*
5779+
* @return None
5780+
*
5781+
* Chapter 55 of Astronomical Algorithms
5782+
*/
5783+
public function calculateDiameter(Carbon $date)
5784+
{
5785+
$helio_coords = $this->calculateHeliocentricCoordinates($date);
5786+
5787+
$earth = new Earth();
5788+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
5789+
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
5790+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
5791+
$y = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * sin(deg2rad($helio_coords[0])) -
5792+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * sin(deg2rad($helio_coords_earth[0]));
5793+
$z = $helio_coords[2] * sin(deg2rad($helio_coords[1])) -
5794+
$helio_coords_earth[2] * sin(deg2rad($helio_coords_earth[1]));
5795+
$delta = sqrt($x ** 2 + $y ** 2 + $z ** 2);
5796+
5797+
$this->setDiameter(round(2 * 4.68 / $delta, 1));
5798+
}
57725799
}

0 commit comments

Comments
 (0)