diff --git a/changelog.md b/changelog.md index e50f885..ff325b3 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,12 @@ All notable changes to `laravel-astronomy-library` will be documented in this file. +## Version 4.5 + +### Added + +- Added methods to check if three bodies are in a straight line and to calculate the deviation from a straight line. + ## Version 4.4 ### Added diff --git a/readme.md b/readme.md index d049f29..c89c5be 100644 --- a/readme.md +++ b/readme.md @@ -195,6 +195,12 @@ $galactic = $coords->convertToGalactic(); $parallacticAngle = $coords->getParallacticAngle($geo_coords, $siderial_time); $hour_angle = $coords->getHourAngle($siderial_time); $angular_separation = $coords->angularSeparation($coords2)->getCoordinate(); + +// Check if three bodies are in a straight line +$castor = new EquatorialCoordinates(7.571222, 31.89756); +$pollux = new EquatorialCoordinates(7.750002778, 28.03681); +$mars = new EquatorialCoordinates(8.022644129, 21.472188347); +$isInStraightLine = $mars->isInStraightLine($castor, $pollux); ``` ### Coordinate methods on ecliptical coordinates diff --git a/src/deepskylog/AstronomyLibrary/Coordinates/EclipticalCoordinates.php b/src/deepskylog/AstronomyLibrary/Coordinates/EclipticalCoordinates.php index a3094a4..b15a189 100644 --- a/src/deepskylog/AstronomyLibrary/Coordinates/EclipticalCoordinates.php +++ b/src/deepskylog/AstronomyLibrary/Coordinates/EclipticalCoordinates.php @@ -108,6 +108,7 @@ public function printLatitude(): string /** * Converts the ecliptical coordinates to equatorial coordinates. + * Chapter 13 of Astronomical Algorithms. * * @param float $nutObliquity The nutation in obliquity * @@ -141,6 +142,7 @@ public function convertToEquatorial(float $nutObliquity): EquatorialCoordinates /** * Converts the ecliptical coordinates to equatorial coordinates in * the J2000 equinox. + * Chapter 13 of Astronomical Algorithms. * * @return EquatorialCoordinates The equatorial coordinates */ @@ -152,6 +154,7 @@ public function convertToEquatorialJ2000(): EquatorialCoordinates /** * Converts the ecliptical coordinates to equatorial coordinates in * the B1950 equinox. + * Chapter 13 of Astronomical Algorithms. * * @return EquatorialCoordinates The equatorial coordinates */ diff --git a/src/deepskylog/AstronomyLibrary/Coordinates/EquatorialCoordinates.php b/src/deepskylog/AstronomyLibrary/Coordinates/EquatorialCoordinates.php index 8eb7fca..b1e3197 100644 --- a/src/deepskylog/AstronomyLibrary/Coordinates/EquatorialCoordinates.php +++ b/src/deepskylog/AstronomyLibrary/Coordinates/EquatorialCoordinates.php @@ -111,6 +111,7 @@ public function printRA(): string /** * Converts the equatorial coordinates to ecliptical coordinates in * the current equinox. + * Chapter 13 of Astronomical Algorithms. * * @param float $nutObliquity The nutation in obliquity * @@ -144,6 +145,7 @@ public function convertToEcliptical(float $nutObliquity): EclipticalCoordinates /** * Converts the equatorial coordinates to ecliptical coordinates in * the J2000 equinox. + * Chapter 13 of Astronomical Algorithms. * * @return EclipticalCoordinates The ecliptical coordinates */ @@ -155,6 +157,7 @@ public function convertToEclipticalJ2000(): EclipticalCoordinates /** * Converts the equatorial coordinates to ecliptical coordinates in * the B1950 equinox. + * Chapter 13 of Astronomical Algorithms. * * @return EclipticalCoordinates The ecliptical coordinates */ @@ -165,6 +168,7 @@ public function convertToEclipticalB1950(): EclipticalCoordinates /** * Converts the equatorial coordinates to local horizontal coordinates. + * Chapter 13 of Astronomical Algorithms. * * @param GeographicalCoordinates $geo_coords the geographical * coordinates @@ -204,6 +208,7 @@ public function convertToHorizontal( /** * Converts the equatorial coordinates to galactic coordinates. + * Chapter 13 of Astronomical Algorithms. * * @return GalacticCoordinates The galactic coordinates */ @@ -236,7 +241,7 @@ public function convertToGalactic(): GalacticCoordinates * Returns the parallactic angle of the object. The parallactic angle is * negative before and positive after the passage throught the southern * meridian. This is the effect of the moon that is lying down at moonrise. - * Astronomical Algorithms - chapter 13. + * Chapter 14 of Astronomical Algorithms. * * @param GeographicalCoordinates $geo_coords the geographical * coordinates @@ -282,6 +287,7 @@ public function getHourAngle(Carbon $siderial_time): float /** * Returns the angular separation between these coordinates and other * equatorial coordinates. + * Chapter 17 of Astronomical Algorithms. * * @param EquatorialCoordinates $coords2 the coordinates of the second object * @@ -327,4 +333,92 @@ public function angularSeparation( return new Coordinate($d); } + + /** + * Returns true if the three bodies are in a straight line. + * Chapter 19 of Astronomical Algorithms. + * + * @param EquatorialCoordinates $coords2 The coordinates of the second object + * @param EquatorialCoordinates $coords3 The coordinates of the thirds object + * @param float $threshold The threshold for the method + * (default value is 10e-06) + * + * @return bool True if the three bodies are in a straight line + */ + public function isInStraightLine( + self $coords2, + self $coords3, + float $threshold = 1e-6 + ): bool { + $result = tan(deg2rad($this->getDeclination()->getCoordinate())) * + sin( + deg2rad( + $coords2->getRA()->getCoordinate() * 15.0 + - $coords3->getRA()->getCoordinate() * 15.0 + ) + ) + tan(deg2rad($coords2->getDeclination()->getCoordinate())) * + sin( + deg2rad( + $coords3->getRA()->getCoordinate() * 15.0 + - $this->getRA()->getCoordinate() * 15.0 + ) + ) + tan(deg2rad($coords3->getDeclination()->getCoordinate())) * + sin( + deg2rad( + $this->getRA()->getCoordinate() * 15.0 + - $coords2->getRA()->getCoordinate() * 15.0 + ) + ); + + if (abs($result) < $threshold) { + return true; + } + + return false; + } + + /** + * Returns the deviation from a straight line. + * Chapter 19 of Astronomical Algorithms. + * + * @param EquatorialCoordinates $coords2 The coordinates of the first object + * @param EquatorialCoordinates $coords3 The coordinates of the second object + * + * @return Coordinate the deviation from the straight line + */ + public function deviationFromStraightLine( + self $coords2, + self $coords3 + ): Coordinate { + $X1 = cos(deg2rad($coords2->getDeclination()->getCoordinate())) * + cos(deg2rad($coords2->getRA()->getCoordinate() * 15.0)); + $Y1 = cos(deg2rad($coords2->getDeclination()->getCoordinate())) * + sin(deg2rad($coords2->getRA()->getCoordinate() * 15.0)); + $Z1 = sin(deg2rad($coords2->getDeclination()->getCoordinate())); + + $X2 = cos(deg2rad($coords3->getDeclination()->getCoordinate())) * + cos(deg2rad($coords3->getRA()->getCoordinate() * 15.0)); + $Y2 = cos(deg2rad($coords3->getDeclination()->getCoordinate())) * + sin(deg2rad($coords3->getRA()->getCoordinate() * 15.0)); + $Z2 = sin(deg2rad($coords3->getDeclination()->getCoordinate())); + + $A = $Y1 * $Z2 - $Z1 * $Y2; + $B = $Z1 * $X2 - $X1 * $Z2; + $C = $X1 * $Y2 - $Y1 * $X2; + + $m = tan(deg2rad($this->getRA()->getCoordinate() * 15.0)); + $n = tan(deg2rad($this->getDeclination()->getCoordinate())) + / cos(deg2rad($this->getRA()->getCoordinate() * 15.0)); + + $omega = rad2deg( + abs( + asin( + ($A + $B * $m + $C * $n) / + (sqrt($A * $A + $B * $B + $C * $C) * sqrt(1 + $m * $m + $n * $n)) + ) + ) + ); + + return new Coordinate($omega, 0.0, 90.0); + } } diff --git a/src/deepskylog/AstronomyLibrary/Coordinates/GalacticCoordinates.php b/src/deepskylog/AstronomyLibrary/Coordinates/GalacticCoordinates.php index 0b12103..3709e91 100644 --- a/src/deepskylog/AstronomyLibrary/Coordinates/GalacticCoordinates.php +++ b/src/deepskylog/AstronomyLibrary/Coordinates/GalacticCoordinates.php @@ -108,6 +108,7 @@ public function printLatitude(): string /** * Converts the galactic coordinates to equatorial coordinates. + * Chapter 13 of Astronomical Algorithms. * * @return EquatorialCoordinates The equatorial coordinates */ diff --git a/src/deepskylog/AstronomyLibrary/Coordinates/HorizontalCoordinates.php b/src/deepskylog/AstronomyLibrary/Coordinates/HorizontalCoordinates.php index f93f4f0..3abcf3d 100644 --- a/src/deepskylog/AstronomyLibrary/Coordinates/HorizontalCoordinates.php +++ b/src/deepskylog/AstronomyLibrary/Coordinates/HorizontalCoordinates.php @@ -110,6 +110,7 @@ public function printAltitude(): string /** * Converts the local horizontal coordinates to equatorial coordinates. + * Chapter 13 of Astronomical Algorithms. * * @param GeographicalCoordinates $geo_coords the geographical * coordinates @@ -178,8 +179,9 @@ public function convertToEquatorial( /** * Calculates the refaction (in minutes of arc) if the apparent * height is given. + * Chapter 16 of Astronomical Algorithms. * - * @return float The refraction in minutes of arc. + * @return float the refraction in minutes of arc */ public function calculateRefractionFromApparentAltitude(): float { @@ -196,8 +198,9 @@ public function calculateRefractionFromApparentAltitude(): float /** * Calculates the refaction (in minutes of arc) if the true * height is given. + * Chapter 16 of Astronomical Algorithms. * - * @return float The refraction in minutes of arc. + * @return float the refraction in minutes of arc */ public function calculateRefractionFromTrueAltitude(): float { diff --git a/src/deepskylog/AstronomyLibrary/Targets/Moon.php b/src/deepskylog/AstronomyLibrary/Targets/Moon.php index 9344560..0f190ec 100644 --- a/src/deepskylog/AstronomyLibrary/Targets/Moon.php +++ b/src/deepskylog/AstronomyLibrary/Targets/Moon.php @@ -38,7 +38,7 @@ public function __construct() /** * Calculates the horizontal moon parallax. * - * To implement from chapter 29. + * To implement from chapter 30. * * @return float the horizontal moon parallax */ diff --git a/src/deepskylog/AstronomyLibrary/Targets/Target.php b/src/deepskylog/AstronomyLibrary/Targets/Target.php index 00db2a9..98410fb 100644 --- a/src/deepskylog/AstronomyLibrary/Targets/Target.php +++ b/src/deepskylog/AstronomyLibrary/Targets/Target.php @@ -209,6 +209,7 @@ public function getEquatorialCoordinatesTomorrow(): EquatorialCoordinates /** * Get the transit time of this object. + * Chapter 15 of Astronomical Algorithms. * * @return Carbon the transit time of the object **/ @@ -225,6 +226,7 @@ public function getTransit(): Carbon /** * Get the rising time of this object. + * Chapter 15 of Astronomical Algorithms. * * @return Carbon The rising time of the object or null if the object does not * set @@ -242,6 +244,7 @@ public function getRising(): ?Carbon /** * Get the setting time of this object. + * Chapter 15 of Astronomical Algorithms. * * @return Carbon The setting time of the object or null if the object does * not set @@ -259,6 +262,7 @@ public function getSetting(): ?Carbon /** * Get the maximum height of the target during the year. + * Chapter 15 of Astronomical Algorithms. * * @return Coordinate the maximum height of the target during the year **/ @@ -278,6 +282,7 @@ public function getMaxHeight(): ?Coordinate * no astronomical darkness during the night, the maximum height * during the nautical brightness is taken. If there is also no * nautical brightness, null is returned. + * Chapter 15 of Astronomical Algorithms. * * @return Coordinate the maximum height of the target during the year **/ @@ -294,6 +299,7 @@ public function getMaxHeightAtNight(): ?Coordinate /** * Get the best time to observe this target at the given date. + * Chapter 15 of Astronomical Algorithms. * * @return Carbon The best time to observe the target at the given date **/ @@ -310,6 +316,7 @@ public function getBestTimeToObserve(): ?Carbon /** * Calculate rising and the setting of the object. + * Chapter 15 of Astronomical Algorithms. * * @param GeographicalCoordinates $geo_coords The geographical * coordinates of the observer @@ -654,6 +661,7 @@ public function calculateEphemerides( /** * Calculates the height of the object at a given moment. + * Chapter 15 of Astronomical Algorithms. * * @param float $theta0 Theta0 of the target * @param float $time The time to calculate the diff --git a/src/deepskylog/AstronomyLibrary/Time.php b/src/deepskylog/AstronomyLibrary/Time.php index 83e8287..0b5d3f0 100644 --- a/src/deepskylog/AstronomyLibrary/Time.php +++ b/src/deepskylog/AstronomyLibrary/Time.php @@ -140,7 +140,7 @@ public static function fromJd(float $jd): Carbon /** * Returns the dynamical time as the time + delta t. - * Chapter 9 in Astronomical Algorithms. + * Chapter 10 in Astronomical Algorithms. * * @param Carbon $date The date * @@ -153,7 +153,7 @@ public static function dynamicalTime(Carbon $date): Carbon /** * Calculates delta t for the given date. - * Chapter 9 in Astronomical Algorithms. + * Chapter 10 in Astronomical Algorithms. * * @param Carbon $date The date * @@ -221,7 +221,7 @@ public static function deltaT(Carbon $date): float /** * Calculates the mean siderial time for the given date. - * Chapter 11 in Astronomical Algorithms. + * Chapter 12 in Astronomical Algorithms. * * @param Carbon $date The date * @param GeographicalCoordinates $coords The geographical coordinates @@ -265,7 +265,7 @@ public static function meanSiderialTime( /** * Calculates the apparent siderial time for the given date. - * Chapter 11 in Astronomical Algorithms. + * Chapter 12 in Astronomical Algorithms. * * @param Carbon $date The date * @param GeographicalCoordinates $coords The geographical coordinates @@ -296,7 +296,7 @@ public static function apparentSiderialTime( /** * Calculates the apparent siderial time for the given date, at midnight, * in Greenwich. - * Chapter 11 in Astronomical Algorithms. + * Chapter 12 in Astronomical Algorithms. * * @param Carbon $date The date * @@ -316,7 +316,7 @@ public static function apparentSiderialTimeGreenwich( /** * Calculates the nutation for the given julian day. - * Chapter 21 of Astronomical Algorithms. + * Chapter 22 of Astronomical Algorithms. * * @param float $jd The Julian day * diff --git a/tests/Unit/EquatorialCoordinatesTest.php b/tests/Unit/EquatorialCoordinatesTest.php index 13b5b99..d27e880 100644 --- a/tests/Unit/EquatorialCoordinatesTest.php +++ b/tests/Unit/EquatorialCoordinatesTest.php @@ -216,4 +216,60 @@ public function testAngularSeparation() 0.0001 ); } + + /** + * Test bodies in straight line. + * + * @return None + */ + public function testBodiesInStraightLine() + { + // Castor + $castor = new EquatorialCoordinates(7.571222, 31.89756); + // Pollux + $pollux = new EquatorialCoordinates(7.750002778, 28.03681); + + // Mars on Sep 30, 1994 + $mars = new EquatorialCoordinates(7.97293055, 21.58983); + $this->assertFalse($mars->isInStraightLine($castor, $pollux)); + + // Mars on Oct 1, 1994, 5h TD + $mars = new EquatorialCoordinates(8.022644129, 21.472188347); + $this->assertTrue($mars->isInStraightLine($castor, $pollux)); + } + + /** + * Test deviation of three bodies from a straight line. + * + * @return None + */ + public function testDeviationFromStraightLine() + { + // Delta Ori + $delta = new EquatorialCoordinates(5.5334444, -0.29913888); + // Epsilon Ori + $eps = new EquatorialCoordinates(5.60355833, -1.20194444); + // Ksi Ori + $ksi = new EquatorialCoordinates(5.679311111, -1.94258333); + $this->assertEqualsWithDelta( + $eps->deviationFromStraightLine($delta, $ksi)->getCoordinate(), + 0.089876, + 0.001 + ); + + // Alpha Uma + $alpha = new EquatorialCoordinates(11.062129444, 61.750894444); + + // Beta Uma + $beta = new EquatorialCoordinates(11.030689444, 56.3824027778); + + // Polaris + $polaris = new EquatorialCoordinates(2.530195556, 89.26408889); + + $this->assertEqualsWithDelta( + $polaris->deviationFromStraightLine($alpha, $beta)->getCoordinate(), + 1.91853, + 0.001 + ); + } }