Skip to content

Commit

Permalink
Merge pull request #28 from WimDeMeester/master
Browse files Browse the repository at this point in the history
Methods to check if three bodies are in a straight line and the deviation from the straight line.
  • Loading branch information
WimDeMeester authored Jul 31, 2020
2 parents cb3d29f + 53c4393 commit 72a6ed1
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 10 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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
Expand Down Expand Up @@ -204,6 +208,7 @@ public function convertToHorizontal(

/**
* Converts the equatorial coordinates to galactic coordinates.
* Chapter 13 of Astronomical Algorithms.
*
* @return GalacticCoordinates The galactic coordinates
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/deepskylog/AstronomyLibrary/Targets/Moon.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
8 changes: 8 additions & 0 deletions src/deepskylog/AstronomyLibrary/Targets/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
**/
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
**/
Expand All @@ -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
**/
Expand All @@ -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
**/
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/deepskylog/AstronomyLibrary/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
*
Expand All @@ -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
*
Expand Down
Loading

0 comments on commit 72a6ed1

Please sign in to comment.