Skip to content

Commit

Permalink
Merge pull request #27 from WimDeMeester/master
Browse files Browse the repository at this point in the history
Calculate angular separation.
  • Loading branch information
WimDeMeester authored Jun 15, 2020
2 parents 9b3149e + c03e56b commit cb3d29f
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 34 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.4

### Added

- Added methods to calculate the angular separation between two objects.

## Version 4.3

### Added
Expand Down
66 changes: 33 additions & 33 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ $horizontal = $coords->convertToHorizontal($geo_coords, $siderial_time);
$galactic = $coords->convertToGalactic();
$parallacticAngle = $coords->getParallacticAngle($geo_coords, $siderial_time);
$hour_angle = $coords->getHourAngle($siderial_time);
$angular_separation = $coords->angularSeparation($coords2)->getCoordinate();
```

### Coordinate methods on ecliptical coordinates
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function printDeclination(): string
*/
public function printRA(): string
{
return $this->getRA()->convertToHours;
return $this->getRA()->convertToHours();
}

/**
Expand Down Expand Up @@ -278,4 +278,53 @@ public function getHourAngle(Carbon $siderial_time): float

return ($sid - $this->getRA()->getCoordinate()) * 15.0;
}

/**
* Returns the angular separation between these coordinates and other
* equatorial coordinates.
*
* @param EquatorialCoordinates $coords2 the coordinates of the second object
*
* @return Coordinate The angular separation between the two objects
*/
public function angularSeparation(
self $coords2
): Coordinate {
$d = rad2deg(
acos(
sin(deg2rad($this->getDeclination()->getCoordinate())) *
sin(deg2rad($coords2->getDeclination()->getCoordinate()))
+ cos(deg2rad($this->getDeclination()->getCoordinate())) *
cos(deg2rad($coords2->getDeclination()->getCoordinate())) *
cos(
deg2rad(
$this->getRA()->getCoordinate() * 15.0
- $coords2->getRA()->getCoordinate() * 15.0
)
)
)
);

if ($d < 0.16) {
$d = sqrt(
(
$this->getRA()->getCoordinate() * 15.0
- $coords2->getRA()->getCoordinate() * 15.0
) * cos(
deg2rad(
(
$this->getDeclination()->getCoordinate()
+ $coords2->getDeclination()->getCoordinate()
) / 2
)
) ** 2 +
(
$this->getDeclination()->getCoordinate()
- $coords2->getDeclination()->getCoordinate()
)
);
}

return new Coordinate($d);
}
}
28 changes: 28 additions & 0 deletions tests/Unit/EquatorialCoordinatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,32 @@ public function testParallacticAngle()
$equa->getParallacticAngle($geo, $astrolib->getApparentSiderialTime())
);
}

/**
* Test angular separation.
*
* @return None
*/
public function testAngularSeparation()
{
// Arcturus and Spica
$equa1 = new EquatorialCoordinates(14.2610277778, 19.1825);
$equa2 = new EquatorialCoordinates(13.4198888, -11.1614);

$this->assertEqualsWithDelta(
$equa1->angularSeparation($equa2)->getCoordinate(),
32.7930,
0.0001
);

// Aldebaran and Antares
$equa1 = new EquatorialCoordinates(4.598677519444444, 16.509302361111111);
$equa2 = new EquatorialCoordinates(16.490127694444444, -26.432002611111111);

$this->assertEqualsWithDelta(
$equa1->angularSeparation($equa2)->getCoordinate(),
169.9627,
0.0001
);
}
}

0 comments on commit cb3d29f

Please sign in to comment.