forked from BoostGSoC18/astronomy
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the Coordinate System Framework (#146)
To fix the position of any astronomical object, this coordinate system framework provides tools to assign a different pair of numbers to every point in the sky. Each system takes its name from the fundamental plane which it uses as a reference This framework contains Base class coord_sys and the four Coordinate System 1. Equatorial Coordinate System equatorial_coord.hpp 2. Horizon Coordinate System horizon_coord.hpp 3. Ecliptic Coordinate System ecliptic_coord.hpp 4. Galactic Coordinate System galactic_coord.hpp
- Loading branch information
Showing
17 changed files
with
1,352 additions
and
4 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
include/boost/astronomy/coordinate/coord_sys/coord_sys.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*============================================================================= | ||
Copyright 2020 Syed Ali Hasan <alihasan9922@gmail.com> | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file License.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
=============================================================================*/ | ||
|
||
#ifndef BOOST_ASTRONOMY_COORD_SYS_HPP | ||
#define BOOST_ASTRONOMY_COORD_SYS_HPP | ||
|
||
#include <cstddef> | ||
#include <type_traits> | ||
#include <boost/static_assert.hpp> | ||
#include <boost/geometry/core/cs.hpp> | ||
#include <boost/units/get_dimension.hpp> | ||
#include <boost/geometry/geometries/point.hpp> | ||
#include <boost/geometry/algorithms/transform.hpp> | ||
|
||
namespace boost { namespace astronomy { namespace coordinate { | ||
|
||
namespace bg = boost::geometry; | ||
|
||
typedef bg::degree degree; | ||
typedef bg::radian radian; | ||
|
||
template | ||
< | ||
std::size_t DimensionCount, | ||
typename CoordinateSystem, | ||
typename CoordinateType=double | ||
> | ||
struct coord_sys | ||
{ | ||
///@cond INTERNAL | ||
BOOST_STATIC_ASSERT_MSG((DimensionCount == 2), | ||
"DimensionCount is expected to be 2"); | ||
BOOST_STATIC_ASSERT_MSG((std::is_arithmetic<CoordinateType>::value), | ||
"Coordinate Type must be an arithmetic type"); | ||
///@endcond | ||
protected: | ||
bg::model::point<CoordinateType, DimensionCount, CoordinateSystem> point; | ||
|
||
public: | ||
typedef CoordinateSystem system; | ||
typedef CoordinateType type; | ||
|
||
bg::model::point<CoordinateType, DimensionCount, CoordinateSystem> get_point() const | ||
{ | ||
return this->point; | ||
} | ||
}; //coord_sys | ||
|
||
}}} | ||
|
||
#endif //BOOST_ASTRONOMY_COORD_SYS_HPP |
192 changes: 192 additions & 0 deletions
192
include/boost/astronomy/coordinate/coord_sys/ecliptic_coord.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
/*============================================================================= | ||
Copyright 2020 Syed Ali Hasan <alihasan9922@gmail.com> | ||
Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
file License.txt or copy at https://www.boost.org/LICENSE_1_0.txt) | ||
=============================================================================*/ | ||
|
||
#ifndef BOOST_ASTRONOMY_ECLIPTIC_COORD_HPP | ||
#define BOOST_ASTRONOMY_ECLIPTIC_COORD_HPP | ||
|
||
#include <iostream> | ||
#include <boost/static_assert.hpp> | ||
#include <boost/geometry/core/cs.hpp> | ||
#include <boost/units/get_dimension.hpp> | ||
#include <boost/geometry/geometries/point.hpp> | ||
#include <boost/units/systems/si/plane_angle.hpp> | ||
#include <boost/units/systems/si/dimensionless.hpp> | ||
#include <boost/units/physical_dimensions/plane_angle.hpp> | ||
#include <boost/astronomy/coordinate/coord_sys/coord_sys.hpp> | ||
|
||
/** | ||
* The plane containing the Earth’s orbit around the Sun is called | ||
* the ecliptic and the other planets in our Solar System also move | ||
* in orbits close to this plane. | ||
* | ||
* When making calculations on objects in the Solar System it is | ||
* therefore often convenient to define positions with respect to | ||
* the ecliptic, that is, to use the ecliptic coordinate system. | ||
* | ||
* Ecliptic Latitude | ||
* The ecliptic plane is extended until it intersects the celestial | ||
* sphere to create an “ecliptic equator” as the reference point from | ||
* which Ecliptic Latitudes are measured. The Ecliptic Latitude, denoted | ||
* by β, is the angular distance that an object P lies above or below the | ||
* ecliptic plane and falls within the range ±90◦. | ||
* Latitudes above the ecliptic plane are positive angles while latitudes | ||
* below the ecliptic plane are negative angles. An object, such as the Sun, | ||
* whose orbit lies entirely within the ecliptic plane has an ecliptic latitude | ||
* of 0◦. | ||
* | ||
* Ecliptic Longitude | ||
* The Ecliptic Longitude, designated by λ, measures how far away an object is | ||
* from the First Point of Aries. The Ecliptic Longitude is in the range [0◦, 360◦] | ||
* and measured along the ecliptic toward the First Point of Aries. | ||
*/ | ||
|
||
namespace boost { namespace astronomy { namespace coordinate { | ||
|
||
namespace bu = boost::units; | ||
namespace bg = boost::geometry; | ||
|
||
template | ||
< | ||
typename CoordinateType = double, | ||
typename LatQuantity = bu::quantity<bu::si::plane_angle, CoordinateType>, | ||
typename LonQuantity = bu::quantity<bu::si::plane_angle, CoordinateType> | ||
> | ||
struct ecliptic_coord : public coord_sys | ||
<2, bg::cs::spherical<bg::radian>, CoordinateType> | ||
{ | ||
///@cond INTERNAL | ||
BOOST_STATIC_ASSERT_MSG( | ||
((std::is_same<typename bu::get_dimension<LatQuantity>::type, | ||
bu::plane_angle_dimension>::value) && | ||
(std::is_same<typename bu::get_dimension<LonQuantity>::type, | ||
bu::plane_angle_dimension>::value)), | ||
"Latitude and Longitude must be of plane angle type"); | ||
BOOST_STATIC_ASSERT_MSG((std::is_floating_point<CoordinateType>::value), | ||
"CoordinateType must be a floating-point type"); | ||
///@endcond | ||
public: | ||
typedef LatQuantity quantity1; | ||
typedef LonQuantity quantity2; | ||
|
||
//Default constructor | ||
ecliptic_coord() {} | ||
|
||
ecliptic_coord | ||
( | ||
LatQuantity const &Lat, | ||
LonQuantity const &Lon | ||
) | ||
{ | ||
this->set_lat_lon(Lat, Lon); | ||
} | ||
|
||
//Create a tuple of Ecliptic Latitude and Ecliptic Longitude | ||
std::tuple<LatQuantity, LonQuantity> get_lat_lon() const | ||
{ | ||
return std::make_tuple(this->get_lat(), this->get_lon()); | ||
} | ||
|
||
//Get Ecliptic Latitude | ||
LatQuantity get_lat() const | ||
{ | ||
return static_cast<LatQuantity> | ||
( | ||
bu::quantity<bu::si::plane_angle, CoordinateType>::from_value | ||
(bg::get<0>(this->point)) | ||
); | ||
} | ||
|
||
//Get Ecliptic Longitude | ||
LonQuantity get_lon() const | ||
{ | ||
return static_cast<LonQuantity> | ||
( | ||
bu::quantity<bu::si::plane_angle, CoordinateType>::from_value | ||
(bg::get<1>(this->point)) | ||
); | ||
} | ||
|
||
//Set value of Ecliptic Latitude and Ecliptic Longitude | ||
void set_lat_lon | ||
( | ||
LatQuantity const &Lat, | ||
LonQuantity const &Lon | ||
) | ||
{ | ||
this->set_lat(Lat); | ||
this->set_lon(Lon); | ||
} | ||
|
||
//Set Ecliptic Latitude | ||
void set_lat(LatQuantity const &Lat) | ||
{ | ||
bg::set<0> | ||
( | ||
this->point, | ||
static_cast<bu::quantity<bu::si::plane_angle, CoordinateType>>(Lat).value() | ||
); | ||
} | ||
|
||
//Set Ecliptic Longitude | ||
void set_lon(LonQuantity const &Lon) | ||
{ | ||
bg::set<1> | ||
( | ||
this->point, | ||
static_cast<bu::quantity<bu::si::plane_angle, CoordinateType>>(Lon).value() | ||
); | ||
} | ||
|
||
}; //ecliptic_coord | ||
|
||
//Make Ecliptic Coordinate | ||
template | ||
< | ||
typename CoordinateType, | ||
template<typename Unit2, typename CoordinateType_> class LatQuantity, | ||
template<typename Unit1, typename CoordinateType_> class LonQuantity, | ||
typename Unit1, | ||
typename Unit2 | ||
> | ||
ecliptic_coord | ||
< | ||
CoordinateType, | ||
LatQuantity<Unit2, CoordinateType>, | ||
LonQuantity<Unit1, CoordinateType> | ||
> make_ecliptic_coord | ||
( | ||
LatQuantity<Unit2, CoordinateType> const &Lat, | ||
LonQuantity<Unit1, CoordinateType> const &Lon | ||
) | ||
{ | ||
return ecliptic_coord | ||
< | ||
CoordinateType, | ||
LatQuantity<Unit2, CoordinateType>, | ||
LonQuantity<Unit1, CoordinateType> | ||
> (Lat, Lon); | ||
} | ||
|
||
//Print Ecliptic Coordinates | ||
template | ||
< | ||
typename CoordinateType, | ||
class LatQuantity, | ||
class LonQuantity | ||
> | ||
std::ostream &operator << (std::ostream &out, ecliptic_coord | ||
<CoordinateType, LatQuantity, LonQuantity> const &point) { | ||
out << "Ecliptic Coordinate (Ecliptic Latitude: " | ||
<< point.get_lat() << ", Ecliptic Longitude: " | ||
<< point.get_lon() << ")"; | ||
|
||
return out; | ||
} | ||
|
||
}}} | ||
|
||
#endif //BOOST_ASTRONOMY_ECLIPTIC_COORD_HPP |
Oops, something went wrong.