Skip to content

Commit 2de6196

Browse files
authored
Merge pull request #75 from WimDeMeester/master
Calculate the diameter of the Sun, Moon and planets.
2 parents 9a375fb + 71c4b2c commit 2de6196

12 files changed

Lines changed: 485 additions & 7292 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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/deepskylog/AstronomyLibrary/Targets/Mercury.php

Lines changed: 199 additions & 7292 deletions
Large diffs are not rendered by default.

src/deepskylog/AstronomyLibrary/Targets/Moon.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,21 @@ public function lastQuarterMoonDate(Carbon $date): Carbon
779779

780780
return Time::fromJd($JDE);
781781
}
782+
783+
/**
784+
* Calculate the diameter of the Moon. You can get the diamter
785+
* by using the getDiameter method.
786+
*
787+
* @param Carbon $date The date
788+
*
789+
* @return None
790+
*
791+
* Chapter 55 of Astronomical Algorithms
792+
*/
793+
public function calculateDiameter(Carbon $date)
794+
{
795+
$distance = $this->calculateHeliocentricCoordinates($date)[2];
796+
797+
$this->setDiameter(round(2 * 358473400 / $distance, 1));
798+
}
782799
}

src/deepskylog/AstronomyLibrary/Targets/Neptune.php

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

22132213
return round(-7.05 + 5 * log10($R * $delta), 1);
22142214
}
2215+
2216+
/**
2217+
* Calculate the diameter of Neptune. You can get the diamter
2218+
* by using the getDiameter method.
2219+
*
2220+
* @param Carbon $date The date
2221+
*
2222+
* @return None
2223+
*
2224+
* Chapter 55 of Astronomical Algorithms
2225+
*/
2226+
public function calculateDiameter(Carbon $date)
2227+
{
2228+
$helio_coords = $this->calculateHeliocentricCoordinates($date);
2229+
2230+
$earth = new Earth();
2231+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
2232+
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
2233+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
2234+
$y = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * sin(deg2rad($helio_coords[0])) -
2235+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * sin(deg2rad($helio_coords_earth[0]));
2236+
$z = $helio_coords[2] * sin(deg2rad($helio_coords[1])) -
2237+
$helio_coords_earth[2] * sin(deg2rad($helio_coords_earth[1]));
2238+
$delta = sqrt($x ** 2 + $y ** 2 + $z ** 2);
2239+
2240+
$this->setDiameter(round(2 * 33.50 / $delta, 1));
2241+
}
22152242
}

src/deepskylog/AstronomyLibrary/Targets/Saturn.php

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

61006100
return round(-8.68 + 5 * log10($R * $delta) + 0.044 * abs($deltaU) - 2.60 * sin(abs($B)) + 1.25 * sin($B) ** 2, 2);
61016101
}
6102+
6103+
/**
6104+
* Calculate the diameter of Jupiter. You can get the diamter
6105+
* by using the getDiameter method.
6106+
*
6107+
* @param Carbon $date The date
6108+
*
6109+
* @return None
6110+
*
6111+
* Chapter 55 of Astronomical Algorithms
6112+
*/
6113+
public function calculateDiameter(Carbon $date)
6114+
{
6115+
$helio_coords = $this->calculateHeliocentricCoordinates($date);
6116+
6117+
$earth = new Earth();
6118+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
6119+
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
6120+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
6121+
$y = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * sin(deg2rad($helio_coords[0])) -
6122+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * sin(deg2rad($helio_coords_earth[0]));
6123+
$z = $helio_coords[2] * sin(deg2rad($helio_coords[1])) -
6124+
$helio_coords_earth[2] * sin(deg2rad($helio_coords_earth[1]));
6125+
$delta = sqrt($x ** 2 + $y ** 2 + $z ** 2);
6126+
6127+
$this->setDiameter(round(2 * 82.73 / $delta, 1));
6128+
}
61026129
}

src/deepskylog/AstronomyLibrary/Targets/Sun.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,23 @@ public function getPhysicalEphemeris(Carbon $date, float $deltaT): array
805805

806806
return [$P, $B0, $L0];
807807
}
808+
809+
/**
810+
* Calculate the diameter of the Sun. You can get the diamter
811+
* by using the getDiameter method.
812+
*
813+
* @param Carbon $date The date
814+
*
815+
* @return None
816+
*
817+
* Chapter 55 of Astronomical Algorithms
818+
*/
819+
public function calculateDiameter(Carbon $date)
820+
{
821+
$earth = new Earth();
822+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
823+
$R = $helio_coords_earth[2];
824+
825+
$this->setDiameter(round(2 * 959.63 / $R, 1));
826+
}
808827
}

src/deepskylog/AstronomyLibrary/Targets/Uranus.php

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

42764276
return round(-6.85 + 5 * log10($R * $delta), 1);
42774277
}
4278+
4279+
/**
4280+
* Calculate the diameter of Uranus. You can get the diamter
4281+
* by using the getDiameter method.
4282+
*
4283+
* @param Carbon $date The date
4284+
*
4285+
* @return None
4286+
*
4287+
* Chapter 55 of Astronomical Algorithms
4288+
*/
4289+
public function calculateDiameter(Carbon $date)
4290+
{
4291+
$helio_coords = $this->calculateHeliocentricCoordinates($date);
4292+
4293+
$earth = new Earth();
4294+
$helio_coords_earth = $earth->calculateHeliocentricCoordinates($date);
4295+
$x = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * cos(deg2rad($helio_coords[0])) -
4296+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * cos(deg2rad($helio_coords_earth[0]));
4297+
$y = $helio_coords[2] * cos(deg2rad($helio_coords[1])) * sin(deg2rad($helio_coords[0])) -
4298+
$helio_coords_earth[2] * cos(deg2rad($helio_coords_earth[1])) * sin(deg2rad($helio_coords_earth[0]));
4299+
$z = $helio_coords[2] * sin(deg2rad($helio_coords[1])) -
4300+
$helio_coords_earth[2] * sin(deg2rad($helio_coords_earth[1]));
4301+
$delta = sqrt($x ** 2 + $y ** 2 + $z ** 2);
4302+
4303+
$this->setDiameter(round(2 * 35.02 / $delta, 1));
4304+
}
42784305
}

0 commit comments

Comments
 (0)