From f3a86aeece5502b1de45e9f1e75bc724b90b91f5 Mon Sep 17 00:00:00 2001 From: wolgemoth <25903926+loui1024@users.noreply.github.com> Date: Wed, 1 May 2024 16:25:54 +0100 Subject: [PATCH] Version 1.0.0 --- README.md | 20 ++++- VSOP.hpp | 216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 VSOP.hpp diff --git a/README.md b/README.md index ba420e0..e0ab003 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ -# vsop87-wrapper -A wrapper class providing a clean interface for working with Greg Miller's VSOP87-Multilang +# VSOP87 Wrapper + +### About + +This project implements a wrapper providing with a clean interface for those for working with the C++ version of Greg Miller's VSOP87-Multilang and the glm maths library. + +If you find a bug or have a feature-request, please raise an issue. + +### Dependencies + +#### [VSOP87-Multilang](http://www.celestialprogramming.com/vsop87-multilang/index.html) +#### [OpenGL Mathematics 0.9.9.8 (GLM)](https://www.opengl.org/sdk/libs/GLM/) + +### Instructions + +The implementation is header-only and written in templated C++17. You should need not need to make any adjustments to your project settings or compiler flags. + +Simply include the header and its dependencies in your project and you are ready to start! \ No newline at end of file diff --git a/VSOP.hpp b/VSOP.hpp new file mode 100644 index 0000000..11eef09 --- /dev/null +++ b/VSOP.hpp @@ -0,0 +1,216 @@ +#ifndef LOUIERIKSSON_VSOP_HPP +#define LOUIERIKSSON_VSOP_HPP + +#include +#include + +namespace LouiEriksson { + + /** + * @mainpage Version 1.0.0 + * + * @brief Class representing the VSOP astronomical coordinate system. + * + * The VSOP class provides functions for obtaining position information of celestial bodies. + * + * @tparam T The underlying type of the vector components. + * @tparam Q The precision of the vector components. + */ + template + struct VSOP final { + + private: + + /** + * @brief Changes the handedness of a 3D vector. + * + * This function takes a 3D vector and returns a new vector with changed handedness. + * + * @tparam T The underlying type of the vector components. + * @tparam P The precision of the vector components. + * @param[in] _vec The input vector. + * @return The new vector with changed handedness. + */ + template + static constexpr glm::vec<3, T, Q> ChangeHandedness(const glm::vec<3, T, Q>& _vec) { + return { -_vec.x, _vec.z, _vec.y }; + } + + public: + + struct Position final { + + private: + + glm::vec<3, T, Q> m_Spherical; + glm::vec<3, T, Q> m_Cartesian; + glm::qua< T, Q> m_Rotation; + + public: + + constexpr const glm::vec<3, T, Q>& Spherical() const noexcept { return m_Spherical; } + constexpr const glm::vec<3, T, Q>& Cartesian() const noexcept { return m_Cartesian; } + constexpr const glm::qua< T, Q>& Rotation() const noexcept { return m_Rotation; } + + constexpr Position(const glm::vec<3, T, Q>& _spherical, const glm::vec<3, T, Q>& _cartesian, const glm::vec<3, T, Q>& _rotation) noexcept : + m_Spherical(_spherical), + m_Cartesian(_cartesian), + m_Rotation (_rotation ) {} + + constexpr Position() noexcept : + m_Spherical{}, + m_Cartesian{}, + m_Rotation {} {} + }; + + struct V87 final { + + struct A final { + + static Position GetSol() { + return { + {}, + { 0.0, 0.0, 0.0 }, + {} + }; + } + + static Position GetMercury(const double& _time) { + + double tmp[3]; + + vsop87a_full::getMercury(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetVenus(const double& _time) { + + double tmp[3]; + + vsop87a_full::getVenus(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetEarth(const double& _time) { + + double tmp[3]; + + vsop87a_full::getEarth(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetEMB(const double& _time) { + + double tmp[3]; + + vsop87a_full::getEmb(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetMoon(const Position& _earth, const Position& _emb) { + + auto e1 = ChangeHandedness(_earth.Cartesian()); + auto e2 = ChangeHandedness( _emb.Cartesian()); + + double tmp[3]; + + vsop87a_full::getMoon(&e1[0], &e2[0], tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {}, + }; + } + + static Position GetMars(const double& _time) { + + double tmp[3]; + + vsop87a_full::getMars(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetJupiter(const double& _time) { + + double tmp[3]; + + vsop87a_full::getJupiter(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetSaturn(const double& _time) { + + double tmp[3]; + + vsop87a_full::getSaturn(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetUranus(const double& _time) { + + double tmp[3]; + + vsop87a_full::getUranus(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + + static Position GetNeptune(const double& _time) { + + double tmp[3]; + + vsop87a_full::getNeptune(_time, tmp); + + return { + {}, + { ChangeHandedness({ tmp[0], tmp[1], tmp[2] }) }, + {} + }; + } + }; + }; + }; + +} // LouiEriksson + +#endif //LOUIERIKSSON_VSOP_HPP \ No newline at end of file