@ -1,138 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#include "coordinates.hpp" | |||||
#include <cmath> | |||||
namespace astro | |||||
{ | |||||
double3 rectangular_to_spherical(const double3& rectangular) | |||||
{ | |||||
const double xx_yy = rectangular.x * rectangular.x + rectangular.y * rectangular.y; | |||||
return double3 | |||||
{ | |||||
std::sqrt(xx_yy + rectangular.z * rectangular.z), | |||||
std::atan2(rectangular.z, std::sqrt(xx_yy)), | |||||
std::atan2(rectangular.y, rectangular.x) | |||||
}; | |||||
} | |||||
double3 spherical_to_rectangular(const double3& spherical) | |||||
{ | |||||
return double3 | |||||
{ | |||||
spherical[0] * std::cos(spherical[1]) * std::cos(spherical[2]), | |||||
spherical[0] * std::cos(spherical[1]) * std::sin(spherical[2]), | |||||
spherical[0] * std::sin(spherical[1]), | |||||
}; | |||||
} | |||||
double3x3 ecliptic_to_equatorial(double ecl) | |||||
{ | |||||
const double c_ecl = std::cos(ecl); | |||||
const double s_ecl = std::sin(ecl); | |||||
return double3x3 | |||||
{ | |||||
1.0, 0.0, 0.0, | |||||
0.0, c_ecl, s_ecl, | |||||
0.0, -s_ecl, c_ecl | |||||
}; | |||||
} | |||||
double3x3 ecliptic_to_horizontal(double ecl, double lat, double lst) | |||||
{ | |||||
const double c_ecl = std::cos(ecl); | |||||
const double s_ecl = std::sin(ecl); | |||||
const double c_lat = std::cos(lat); | |||||
const double s_lat = std::sin(lat); | |||||
const double c_lst = std::cos(lst); | |||||
const double s_lst = std::sin(lst); | |||||
return double3x3 | |||||
{ | |||||
s_lat * c_lst, s_lst, c_lat * c_lst, | |||||
s_lat * s_lst * c_ecl - c_lat * s_ecl, -c_lst * c_ecl, c_lat * s_lst * c_ecl + s_lat * s_ecl, | |||||
s_lat * s_lst * -s_ecl - c_lat * c_ecl, c_lst * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl | |||||
}; | |||||
} | |||||
double3x3 equatorial_to_ecliptic(double ecl) | |||||
{ | |||||
const double c_ecl = std::cos(ecl); | |||||
const double s_ecl = std::sin(ecl); | |||||
return double3x3 | |||||
{ | |||||
1.0, 0.0, 0.0, | |||||
0.0, c_ecl, -s_ecl, | |||||
0.0, s_ecl, c_ecl | |||||
}; | |||||
} | |||||
double3x3 equatorial_to_horizontal(double lat, double lst) | |||||
{ | |||||
const double c_lat = std::cos(lat); | |||||
const double s_lat = std::sin(lat); | |||||
const double c_lst = std::cos(lst); | |||||
const double s_lst = std::sin(lst); | |||||
return double3x3 | |||||
{ | |||||
s_lat * c_lst, s_lst, c_lat * c_lst, | |||||
s_lat * s_lst, -c_lst, c_lat * s_lst, | |||||
-c_lat, 0.0, s_lat | |||||
}; | |||||
} | |||||
double3x3 horizontal_to_equatorial(double lat, double lst) | |||||
{ | |||||
const double c_lat = std::cos(lat); | |||||
const double s_lat = std::sin(lat); | |||||
const double c_lst = std::cos(lst); | |||||
const double s_lst = std::sin(lst); | |||||
return double3x3 | |||||
{ | |||||
c_lst * s_lat, s_lst * s_lat, -c_lat, | |||||
s_lst, c_lst, 0.0, | |||||
c_lst * c_lat, s_lst * c_lat, s_lat | |||||
}; | |||||
} | |||||
double3x3 horizontal_to_ecliptic(double ecl, double lat, double lst) | |||||
{ | |||||
const double c_ecl = std::cos(ecl); | |||||
const double s_ecl = std::sin(ecl); | |||||
const double c_lat = std::cos(lat); | |||||
const double s_lat = std::sin(lat); | |||||
const double c_lst = std::cos(lst); | |||||
const double s_lst = std::sin(lst); | |||||
return double3x3 | |||||
{ | |||||
s_lat * c_lst, s_lat * s_lst * c_ecl - c_lat * s_ecl, s_lat * s_lst * -s_ecl - c_lat * c_ecl, | |||||
s_lst, -c_lst * c_ecl, c_lst * s_ecl, | |||||
c_lat * c_lst, c_lat * s_lst * c_ecl + s_lat * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl | |||||
}; | |||||
} | |||||
} // namespace astro |
@ -1,108 +0,0 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_ASTRO_COORDINATES_HPP | |||||
#define ANTKEEPER_ASTRO_COORDINATES_HPP | |||||
#include "utility/fundamental-types.hpp" | |||||
namespace astro | |||||
{ | |||||
/** | |||||
* Converts rectangular coordinates to spherical coordinates. | |||||
* | |||||
* @param rectangular Rectangular coordinates. | |||||
* @return Equivalent spherical coordinates, in the ISO order of radial distance, polar angle (radians), and azimuthal angle (radians). | |||||
*/ | |||||
double3 rectangular_to_spherical(const double3& rectangular); | |||||
/** | |||||
* Convert spherical coordinates to rectangular coordinates. | |||||
* | |||||
* @param spherical Spherical coordinates, in the ISO order of radial distance, polar angle (radians), and azimuthal angle (radians). | |||||
* @return Equivalent rectangular coordinates. | |||||
*/ | |||||
double3 spherical_to_rectangular(const double3& spherical); | |||||
/** | |||||
* Produces a matrix which transforms rectangular coordinates from ecliptic space to equatorial space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 ecliptic_to_equatorial(double ecl); | |||||
/** | |||||
* Produces a matrix which transforms coordinates from ecliptic space to horizontal space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 ecliptic_to_horizontal(double ecl, double lat, double lst); | |||||
/** | |||||
* Produces a matrix which transforms rectangular coordinates from equatorial space to ecliptic space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 equatorial_to_ecliptic(double ecl); | |||||
/** | |||||
* Produces a matrix which transforms rectangular coordinates from equatorial space to horizontal space. | |||||
* | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 equatorial_to_horizontal(double lat, double lst); | |||||
/** | |||||
* Produces a matrix which transforms rectangular coordinates from horizontal space to equatorial space. | |||||
* | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 horizontal_to_equatorial(double lat, double lst); | |||||
/** | |||||
* Produces a matrix which transforms rectangular coordinates from horizontal space to ecliptic space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Transformation matrix. | |||||
*/ | |||||
double3x3 horizontal_to_ecliptic(double ecl, double lat, double lst); | |||||
/// Matrix which transforms coordinates from horizontal space to a right-handed coordinate system. | |||||
constexpr double3x3 horizontal_to_right_handed = | |||||
{ | |||||
0.0, 0.0, 1.0, | |||||
1.0, 0.0, 0.0, | |||||
0.0, -1.0, 0.0 | |||||
}; | |||||
} // namespace astro | |||||
#endif // ANTKEEPER_ASTRO_COORDINATES_HPP |
@ -0,0 +1,34 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_HPP | |||||
#define ANTKEEPER_COORDINATES_HPP | |||||
#include "utility/fundamental-types.hpp" | |||||
/// Functions for converting between coordinate systems. | |||||
namespace coordinates {} | |||||
#include "ecliptic.hpp" | |||||
#include "equatorial.hpp" | |||||
#include "horizontal.hpp" | |||||
#include "rectangular.hpp" | |||||
#include "spherical.hpp" | |||||
#endif // ANTKEEPER_COORDINATES_HPP |
@ -0,0 +1,220 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_ECLIPTIC_HPP | |||||
#define ANTKEEPER_COORDINATES_ECLIPTIC_HPP | |||||
#include "coordinates/rectangular.hpp" | |||||
#include "coordinates/spherical.hpp" | |||||
#include "utility/fundamental-types.hpp" | |||||
#include <cmath> | |||||
namespace coordinates { | |||||
namespace rectangular { | |||||
/// Rectangular coordinate system with the plane of the Earth's orbit as the fundamental plane. This is a right-handed coordinate system with the x-axis pointing to the vernal equinox, the y-axis pointing east, and the z-axis is the north orbital pole. | |||||
namespace ecliptic { | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from ecliptic space into equatorial space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_equatorial(T ecl); | |||||
/** | |||||
* Rotates rectangular coordinates from ecliptic space into equatorial space. | |||||
* | |||||
* @param v Rectangular coordinates in ecliptic space. | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Rectangular coordinates in equatorial space. | |||||
* | |||||
* @note If more than one point is being rotated, it is recommended to use the rotation matrix directly. | |||||
* | |||||
* @see coordinates::ecliptic::rectangular::to_equatorial(T) | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl); | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from ecliptic space into local horizontal space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_horizontal(T ecl, T lat, T lst); | |||||
/** | |||||
* Rotates rectangular coordinates from ecliptic space into local horizontal space. | |||||
* | |||||
* @param v Rectangular coordinates in ecliptic space. | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rectangular coordinates in local horizontal space. | |||||
* | |||||
* @note If more than one point is being rotated, it is recommended to use the rotation matrix directly. | |||||
* | |||||
* @see coordinates::ecliptic::rectangular::to_horizontal(T, T, T) | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst); | |||||
} // namespace ecliptic | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
/// Spherical equatorial coordinate system. | |||||
namespace ecliptic { | |||||
/** | |||||
* Rotates spherical coordinates from ecliptic space into equatorial space. | |||||
* | |||||
* @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians). | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians). | |||||
* | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl); | |||||
/** | |||||
* Rotates spherical coordinates from ecliptic space into local horizontal space. | |||||
* | |||||
* @param v Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians). | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians). | |||||
* | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst); | |||||
} // namespace ecliptic | |||||
} // namespace spherical | |||||
namespace rectangular { | |||||
namespace ecliptic { | |||||
template <class T> | |||||
math::matrix3<T> to_equatorial(T ecl) | |||||
{ | |||||
const T c_ecl = std::cos(ecl); | |||||
const T s_ecl = std::sin(ecl); | |||||
return math::matrix3<T> | |||||
{ | |||||
T(1.0), T(0.0), T(0.0), | |||||
T(0.0), c_ecl, s_ecl, | |||||
T(0.0), -s_ecl, c_ecl | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl) | |||||
{ | |||||
return to_equatorial<T>(ecl) * v; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> to_horizontal(T ecl, T lat, T lst) | |||||
{ | |||||
const T c_ecl = std::cos(ecl); | |||||
const T s_ecl = std::sin(ecl); | |||||
const T c_lat = std::cos(lat); | |||||
const T s_lat = std::sin(lat); | |||||
const T c_lst = std::cos(lst); | |||||
const T s_lst = std::sin(lst); | |||||
return math::matrix3<T> | |||||
{ | |||||
s_lat * c_lst, s_lst, c_lat * c_lst, | |||||
s_lat * s_lst * c_ecl - c_lat * s_ecl, -c_lst * c_ecl, c_lat * s_lst * c_ecl + s_lat * s_ecl, | |||||
s_lat * s_lst * -s_ecl - c_lat * c_ecl, c_lst * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst) | |||||
{ | |||||
return to_horizontal<T>(ecl, lat, lst) * v; | |||||
} | |||||
} // namespace ecliptic | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
namespace ecliptic { | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T ecl) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::ecliptic::to_equatorial<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
ecl | |||||
) | |||||
); | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T ecl, T lat, T lst) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::ecliptic::to_horizontal<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
ecl, | |||||
lat, | |||||
lst | |||||
) | |||||
); | |||||
} | |||||
} // namespace ecliptic | |||||
} // namespace spherical | |||||
} // namespace coordinates | |||||
#endif // ANTKEEPER_COORDINATES_ECLIPTIC_HPP |
@ -0,0 +1,208 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_EQUATORIAL_HPP | |||||
#define ANTKEEPER_COORDINATES_EQUATORIAL_HPP | |||||
#include "coordinates/rectangular.hpp" | |||||
#include "coordinates/spherical.hpp" | |||||
#include "utility/fundamental-types.hpp" | |||||
#include <cmath> | |||||
namespace coordinates { | |||||
namespace rectangular { | |||||
/// Rectangular coordinate system with the Earth's equator as the fundamental plane. This is a right-handed coordinate system with the x-axis pointing to the vernal equinox, the y-axis pointing east, and the z-axis is the north celestial pole. | |||||
namespace equatorial { | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from equatorial space into ecliptic space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_ecliptic(T ecl); | |||||
/** | |||||
* Rotates rectangular coordinates from equatorial space into ecliptic space. | |||||
* | |||||
* @param v Rectangular coordinates in equatorial space. | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Rectangular coordinates in ecliptic space. | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl); | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from equatorial space into local horizontal space. | |||||
* | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_horizontal(T lat, T lst); | |||||
/** | |||||
* Rotates rectangular coordinates from equatorial space into local horizontal space. | |||||
* | |||||
* @param v Rectangular coordinates in equatorial space. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rectangular coordinates in local horizontal space. | |||||
* | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T lat, T lst); | |||||
} // namespace equatorial | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
/// Spherical equatorial coordinate system. | |||||
namespace equatorial { | |||||
/** | |||||
* Rotates spherical coordinates from equatorial space into ecliptic space. | |||||
* | |||||
* @param v Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians). | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @return Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians). | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl); | |||||
/** | |||||
* Rotates spherical coordinates from equatorial space into local horizontal space. | |||||
* | |||||
* @param v Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians). | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians). | |||||
* | |||||
* @see coordinates::horizontal | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T lat, T lst); | |||||
} // namespace equatorial | |||||
} // namespace spherical | |||||
namespace rectangular { | |||||
namespace equatorial { | |||||
template <class T> | |||||
math::matrix3<T> to_ecliptic(T ecl) | |||||
{ | |||||
const T c_ecl = std::cos(ecl); | |||||
const T s_ecl = std::sin(ecl); | |||||
return math::matrix3<T> | |||||
{ | |||||
T(1.0), T(0.0), T(0.0), | |||||
T(0.0), c_ecl, -s_ecl, | |||||
T(0.0), s_ecl, c_ecl | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl) | |||||
{ | |||||
return to_ecliptic(ecl) * v; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> to_horizontal(T lat, T lst) | |||||
{ | |||||
const T c_lat = std::cos(lat); | |||||
const T s_lat = std::sin(lat); | |||||
const T c_lst = std::cos(lst); | |||||
const T s_lst = std::sin(lst); | |||||
return math::matrix3<T> | |||||
{ | |||||
s_lat * c_lst, s_lst, c_lat * c_lst, | |||||
s_lat * s_lst, -c_lst, c_lat * s_lst, | |||||
-c_lat, T(0.0), s_lat | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T lat, T lst) | |||||
{ | |||||
return to_horizontal(lat, lst) * v; | |||||
} | |||||
} // namespace equatorial | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
namespace equatorial { | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::equatorial::to_ecliptic<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
ecl | |||||
) | |||||
); | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_horizontal(const math::vector3<T>& v, T lat, T lst) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::equatorial::to_horizontal<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
lat, | |||||
lst | |||||
) | |||||
); | |||||
} | |||||
} // namepace equatorial | |||||
} // namespace spherical | |||||
} // namespace coordinates | |||||
#endif // ANTKEEPER_COORDINATES_EQUATORIAL_HPP |
@ -0,0 +1,220 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_HORIZONTAL_HPP | |||||
#define ANTKEEPER_COORDINATES_HORIZONTAL_HPP | |||||
#include "coordinates/rectangular.hpp" | |||||
#include "coordinates/spherical.hpp" | |||||
#include "utility/fundamental-types.hpp" | |||||
#include <cmath> | |||||
namespace coordinates { | |||||
namespace rectangular { | |||||
/// Rectangular local horizontal coordinate system in which the x-axis points north, the y-axis points east, and the z-axis points to the vertical. | |||||
namespace horizontal { | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from local horizontal space into equatorial space. | |||||
* | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_equatorial(T lat, T lst); | |||||
/** | |||||
* Rotates rectangular coordinates from local horizontal space into equatorial space. | |||||
* | |||||
* @param v Rectangular coordinates in local horizontal space. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rectangular coordinates in equatorial space. | |||||
* | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T lat, T lst); | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates from local horizontal space into ecliptic space. | |||||
* | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rotation matrix. | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> to_ecliptic(T ecl, T lat, T lst); | |||||
/** | |||||
* Rotates rectangular coordinates from local horizontal space into ecliptic space. | |||||
* | |||||
* @param v Rectangular coordinates in local horizontal space. | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Rectangular coordinates in ecliptic space. | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl, T lat, T lst); | |||||
} // namespace horizontal | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
/// Spherical local horizontal coordinate system. | |||||
namespace horizontal { | |||||
/** | |||||
* Rotates spherical coordinates from local horizontal space into equatorial space. | |||||
* | |||||
* @param v Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians). | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Spherical coordinates in equatorial space, in the ISO order of radial distance, declination (radians), and right ascension (radians). | |||||
* | |||||
* @see coordinates::equatorial | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T lat, T lst); | |||||
/** | |||||
* Rotates spherical coordinates from local horizontal space into ecliptic space. | |||||
* | |||||
* @param v Spherical coordinates in local horizontal space, in the ISO order of radial distance, altitude (radians), and azimuth (radians). | |||||
* @param ecl Obliquity of the ecliptic, in radians. | |||||
* @param lat Observer's latitude, in radians. | |||||
* @param lst Local sidereal time, in radians. | |||||
* @return Spherical coordinates in ecliptic space, in the ISO order of radial distance, ecliptic latitude (radians), and ecliptic longitude (radians). | |||||
* | |||||
* @see coordinates::ecliptic | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl, T lat, T lst); | |||||
} // namespace horizontal | |||||
} // namespace spherical | |||||
namespace rectangular { | |||||
namespace horizontal { | |||||
template <class T> | |||||
math::matrix3<T> to_equatorial(T lat, T lst) | |||||
{ | |||||
const T c_lat = std::cos(lat); | |||||
const T s_lat = std::sin(lat); | |||||
const T c_lst = std::cos(lst); | |||||
const T s_lst = std::sin(lst); | |||||
return math::matrix3<T> | |||||
{ | |||||
c_lst * s_lat, s_lst * s_lat, -c_lat, | |||||
s_lst, c_lst, T(0.0), | |||||
c_lst * c_lat, s_lst * c_lat, s_lat | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T lat, T lst) | |||||
{ | |||||
return to_equatorial<T>(lat, lst) * v; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> to_ecliptic(T ecl, T lat, T lst) | |||||
{ | |||||
const T c_ecl = std::cos(ecl); | |||||
const T s_ecl = std::sin(ecl); | |||||
const T c_lat = std::cos(lat); | |||||
const T s_lat = std::sin(lat); | |||||
const T c_lst = std::cos(lst); | |||||
const T s_lst = std::sin(lst); | |||||
return math::matrix3<T> | |||||
{ | |||||
s_lat * c_lst, s_lat * s_lst * c_ecl - c_lat * s_ecl, s_lat * s_lst * -s_ecl - c_lat * c_ecl, | |||||
s_lst, -c_lst * c_ecl, c_lst * s_ecl, | |||||
c_lat * c_lst, c_lat * s_lst * c_ecl + s_lat * s_ecl, c_lat * s_lst * -s_ecl + s_lat * c_ecl | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl, T lat, T lst) | |||||
{ | |||||
return to_ecliptic<T>(ecl, lat, lst) * v; | |||||
} | |||||
} // namespace horizontal | |||||
} // namespace rectangular | |||||
namespace spherical { | |||||
namespace horizontal { | |||||
template <class T> | |||||
math::vector3<T> to_equatorial(const math::vector3<T>& v, T lat, T lst) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::horizontal::to_equatorial<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
lat, | |||||
lst | |||||
) | |||||
); | |||||
} | |||||
template <class T> | |||||
math::vector3<T> to_ecliptic(const math::vector3<T>& v, T ecl, T lat, T lst) | |||||
{ | |||||
return coordinates::rectangular::to_spherical<T> | |||||
( | |||||
coordinates::rectangular::horizontal::to_ecliptic<T> | |||||
( | |||||
coordinates::spherical::to_rectangular<T>(v), | |||||
ecl, | |||||
lat, | |||||
lst | |||||
) | |||||
); | |||||
} | |||||
} // namespace horizontal | |||||
} // namespace spherical | |||||
} // namespace coordinates | |||||
#endif // ANTKEEPER_COORDINATES_HORIZONTAL_HPP |
@ -0,0 +1,175 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_RECTANGULAR_HPP | |||||
#define ANTKEEPER_COORDINATES_RECTANGULAR_HPP | |||||
#include "utility/fundamental-types.hpp" | |||||
#include <cmath> | |||||
namespace coordinates { | |||||
/// Rectangular (Cartesian) coordinate systems. | |||||
namespace rectangular { | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates about the x-axis by a given angle. | |||||
* | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotation matrix. | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> rotate_x(T angle); | |||||
/** | |||||
* Rotates rectangular coordinates about the x-axis. | |||||
* | |||||
* @param v Rectangular coordinates to rotate. | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotated rectangular coordinates. | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> rotate_x(const math::vector3<T>& v, T angle); | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates about the y-axis by a given angle. | |||||
* | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotation matrix. | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> rotate_y(T angle); | |||||
/** | |||||
* Rotates rectangular coordinates about the y-axis. | |||||
* | |||||
* @param v Rectangular coordinates to rotate. | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotated rectangular coordinates. | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> rotate_y(const math::vector3<T>& v, T angle); | |||||
/** | |||||
* Produces a matrix which rotates rectangular coordinates about the z-axis by a given angle. | |||||
* | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotation matrix. | |||||
*/ | |||||
template <class T> | |||||
math::matrix3<T> rotate_z(T angle); | |||||
/** | |||||
* Rotates rectangular coordinates about the z-axis. | |||||
* | |||||
* @param v Rectangular coordinates to rotate. | |||||
* @param angle Angle of rotation, in radians. | |||||
* @return Rotated rectangular coordinates. | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> rotate_z(const math::vector3<T>& v, T angle); | |||||
/** | |||||
* Converts rectangular coordinates to spherical coordinates. | |||||
* | |||||
* @param v Rectangular coordinates. | |||||
* @return Spherical coordinates, in the ISO order of radial distance, polar angle (radians), and azimuthal angle (radians). | |||||
* | |||||
* @see coordinates::spherical | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_spherical(const math::vector3<T>& v); | |||||
template <class T> | |||||
math::vector3<T> to_spherical(const math::vector3<T>& v) | |||||
{ | |||||
const T xx_yy = v.x * v.x + v.y * v.y; | |||||
return math::vector3<T> | |||||
{ | |||||
std::sqrt(xx_yy + v.z * v.z), | |||||
std::atan2(v.z, std::sqrt(xx_yy)), | |||||
std::atan2(v.y, v.x) | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> rotate_x(T angle) | |||||
{ | |||||
const T c = std::cos(angle); | |||||
const T s = std::sin(angle); | |||||
return math::matrix3<T> | |||||
{ | |||||
T(1), T(0), T(0), | |||||
T(0), c, -s, | |||||
T(0), s, c | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> rotate_x(const math::vector3<T>& v, T angle) | |||||
{ | |||||
return rotate_x(angle) * v; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> rotate_y(T angle) | |||||
{ | |||||
const T c = std::cos(angle); | |||||
const T s = std::sin(angle); | |||||
return math::matrix3<T> | |||||
{ | |||||
c, T(0), s, | |||||
T(0), T(1), T(0), | |||||
-s, T(0), c | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> rotate_y(const math::vector3<T>& v, T angle) | |||||
{ | |||||
return rotate_y(angle) * v; | |||||
} | |||||
template <class T> | |||||
math::matrix3<T> rotate_z(T angle) | |||||
{ | |||||
const T c = std::cos(angle); | |||||
const T s = std::sin(angle); | |||||
return math::matrix3<T> | |||||
{ | |||||
c, -s, T(0), | |||||
s, c, T(0), | |||||
T(0), T(0), T(1) | |||||
}; | |||||
} | |||||
template <class T> | |||||
math::vector3<T> rotate_z(const math::vector3<T>& v, T angle) | |||||
{ | |||||
return rotate_z(angle) * v; | |||||
} | |||||
} // namespace rectangular | |||||
} // namespace coordinates | |||||
#endif // ANTKEEPER_COORDINATES_RECTANGULAR_HPP |
@ -0,0 +1,58 @@ | |||||
/* | |||||
* Copyright (C) 2021 Christopher J. Howard | |||||
* | |||||
* This file is part of Antkeeper source code. | |||||
* | |||||
* Antkeeper source code is free software: you can redistribute it and/or modify | |||||
* it under the terms of the GNU General Public License as published by | |||||
* the Free Software Foundation, either version 3 of the License, or | |||||
* (at your option) any later version. | |||||
* | |||||
* Antkeeper source code is distributed in the hope that it will be useful, | |||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
* GNU General Public License for more details. | |||||
* | |||||
* You should have received a copy of the GNU General Public License | |||||
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
#ifndef ANTKEEPER_COORDINATES_SPHERICAL_HPP | |||||
#define ANTKEEPER_COORDINATES_SPHERICAL_HPP | |||||
#include "utility/fundamental-types.hpp" | |||||
#include <cmath> | |||||
namespace coordinates { | |||||
/// Spherical coordinate systems. | |||||
namespace spherical { | |||||
/** | |||||
* Converts spherical coordinates to rectangular coordinates. | |||||
* | |||||
* @param v Spherical coordinates, in the ISO order of radial distance, polar angle (radians), and azimuthal angle (radians). | |||||
* @return Rectangular coordinates. | |||||
* | |||||
* @see coordinates::rectangular | |||||
*/ | |||||
template <class T> | |||||
math::vector3<T> to_rectangular(const math::vector3<T>& v); | |||||
template <class T> | |||||
math::vector3<T> to_rectangular(const math::vector3<T>& v) | |||||
{ | |||||
const T x = v[0] * std::cos(v[1]); | |||||
return math::vector3<T> | |||||
{ | |||||
x * std::cos(v[2]), | |||||
x * std::sin(v[2]), | |||||
v[0] * std::sin(v[1]), | |||||
}; | |||||
} | |||||
} // namespace spherical | |||||
} // namespace coordinates | |||||
#endif // ANTKEEPER_COORDINATES_SPHERICAL_HPP |