From 4d6fb59ea5969903f40546247fe904b13ca33e63 Mon Sep 17 00:00:00 2001 From: Emma Broman Date: Fri, 9 Oct 2020 11:39:00 +0200 Subject: [PATCH] Add helper function to convert from ICRS to galactic coords Also includes creating a util file for coordinate conversions --- include/openspace/util/coordinateconversion.h | 44 +++++++++++++++++ .../tasks/exoplanetsdatapreparationtask.cpp | 24 ++------- src/CMakeLists.txt | 2 + src/util/coordinateconversion.cpp | 49 +++++++++++++++++++ 4 files changed, 100 insertions(+), 19 deletions(-) create mode 100644 include/openspace/util/coordinateconversion.h create mode 100644 src/util/coordinateconversion.cpp diff --git a/include/openspace/util/coordinateconversion.h b/include/openspace/util/coordinateconversion.h new file mode 100644 index 0000000000..1218761f40 --- /dev/null +++ b/include/openspace/util/coordinateconversion.h @@ -0,0 +1,44 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2020 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#ifndef __OPENSPACE_CORE___COORDINATECONVERSION___H__ +#define __OPENSPACE_CORE___COORDINATECONVERSION___H__ + +#include + +namespace openspace { + +/** +* Converts from ICRS coordinates to galactic cartesian coordinates. +* \param ra Right ascension, given in decimal degrees +* \param dec Declination, given in decimal degrees +* \param distance The distance, or radius, to the position given in any unit. +* \return A position in galactic cartesian coordinates, given in the same unit as the +* distance parameter. +*/ +glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance); + +} // namespace openspace + +#endif // __OPENSPACE_CORE___COORDINATECONVERSION___H__ diff --git a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp index 5213ec752b..f1f8643d1d 100644 --- a/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp +++ b/modules/exoplanets/tasks/exoplanetsdatapreparationtask.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -295,25 +296,10 @@ void ExoplanetsDataPreparationTask::perform(const Task::ProgressCallback& progre bool hasIcrsCoords = !std::isnan(ra) && !std::isnan(dec) && hasDistance; if (!foundPositionFromSpeck && hasIcrsCoords) { - // Convert ICRS Equatorial Ra and Dec to Galactic - const glm::mat3 conversionMatrix = glm::mat3( - // Col 0 - glm::vec3(-0.0548755604162154, 0.4941094278755837, -0.8676661490190047), - // Col 1 - glm::vec3(-0.8734370902348850, -0.4448296299600112, -0.1980763734312015), - // Col 2 - glm::vec3(-0.4838350155487132, 0.7469822444972189, 0.4559837761750669) - ); - - glm::vec3 rICRS = glm::vec3( - cos(glm::radians(ra)) * cos(glm::radians(dec)), - sin(glm::radians(ra)) * cos(glm::radians(dec)), - sin(glm::radians(dec)) - ); - glm::vec3 rGalactic = conversionMatrix * rICRS; - p.positionX = distanceInParsec * rGalactic.x; - p.positionY = distanceInParsec * rGalactic.y; - p.positionZ = distanceInParsec * rGalactic.z; + glm::dvec3 pos = icrsToGalacticCartesian(ra, dec, distanceInParsec); + p.positionX = static_cast(pos.x); + p.positionY = static_cast(pos.y); + p.positionZ = static_cast(pos.z); } // Create look-up table diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 70f0d93979..f6273777b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -170,6 +170,7 @@ set(OPENSPACE_SOURCE ${OPENSPACE_BASE_DIR}/src/util/blockplaneintersectiongeometry.cpp ${OPENSPACE_BASE_DIR}/src/util/boxgeometry.cpp ${OPENSPACE_BASE_DIR}/src/util/camera.cpp + ${OPENSPACE_BASE_DIR}/src/util/coordinateconversion.cpp ${OPENSPACE_BASE_DIR}/src/util/distanceconversion.cpp ${OPENSPACE_BASE_DIR}/src/util/factorymanager.cpp ${OPENSPACE_BASE_DIR}/src/util/httprequest.cpp @@ -357,6 +358,7 @@ set(OPENSPACE_HEADER ${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentjobmanager.inl ${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentqueue.h ${OPENSPACE_BASE_DIR}/include/openspace/util/concurrentqueue.inl + ${OPENSPACE_BASE_DIR}/include/openspace/util/coordinateconversion.h ${OPENSPACE_BASE_DIR}/include/openspace/util/distanceconstants.h ${OPENSPACE_BASE_DIR}/include/openspace/util/distanceconversion.h ${OPENSPACE_BASE_DIR}/include/openspace/util/factorymanager.h diff --git a/src/util/coordinateconversion.cpp b/src/util/coordinateconversion.cpp new file mode 100644 index 0000000000..0fedafb08f --- /dev/null +++ b/src/util/coordinateconversion.cpp @@ -0,0 +1,49 @@ +/***************************************************************************************** + * * + * OpenSpace * + * * + * Copyright (c) 2014-2020 * + * * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this * + * software and associated documentation files (the "Software"), to deal in the Software * + * without restriction, including without limitation the rights to use, copy, modify, * + * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * + * permit persons to whom the Software is furnished to do so, subject to the following * + * conditions: * + * * + * The above copyright notice and this permission notice shall be included in all copies * + * or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * + * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + ****************************************************************************************/ + +#include + +namespace openspace { + +glm::dvec3 icrsToGalacticCartesian(float ra, float dec, double distance) { + // Convert to Galactic Coordinates from ICRS right ascension and declination + // https://gea.esac.esa.int/archive/documentation/GDR2/Data_processing/ + // chap_cu3ast/sec_cu3ast_intro/ssec_cu3ast_intro_tansforms.html#SSS1 + const glm::dmat3 conversionMatrix = glm::dmat3({ + -0.0548755604162154, 0.4941094278755837, -0.8676661490190047, // col 0 + -0.8734370902348850, -0.4448296299600112, -0.1980763734312015, // col 1 + -0.4838350155487132, 0.7469822444972189, 0.4559837761750669 // col 2 + }); + + glm::dvec3 rICRS = glm::dvec3( + cos(glm::radians(ra)) * cos(glm::radians(dec)), + sin(glm::radians(ra)) * cos(glm::radians(dec)), + sin(glm::radians(dec)) + ); + glm::dvec3 rGalactic = conversionMatrix * rICRS; // on the unit sphere + + return distance * rGalactic; +} + +} // namespace openspace