From b8b1c33d080c757f849ebdd3a864e8c72879fb63 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Thu, 6 May 2021 19:53:39 +0800 Subject: [PATCH] Add utility function to convert between visual magnitude and lux --- CMakeLists.txt | 1 - src/astro/astro.hpp | 1 + src/astro/blackbody.hpp | 2 +- src/astro/color-index.hpp | 4 ++-- src/astro/illuminance.cpp | 36 +++++++++++++++++++++++++++++ src/astro/illuminance.hpp | 48 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 src/astro/illuminance.cpp create mode 100644 src/astro/illuminance.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bc40e61..d4aa351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,6 @@ find_package(SDL2 REQUIRED COMPONENTS SDL2::SDL2-static SDL2::SDL2main CONFIG) find_package(OpenAL REQUIRED CONFIG) find_library(physfs REQUIRED NAMES physfs-static PATHS "${CMAKE_PREFIX_PATH}/lib") - # Determine dependencies set(STATIC_LIBS dr_wav diff --git a/src/astro/astro.hpp b/src/astro/astro.hpp index f818809..f8ce409 100644 --- a/src/astro/astro.hpp +++ b/src/astro/astro.hpp @@ -29,6 +29,7 @@ namespace astro {} #include "color-index.hpp" #include "constants.hpp" #include "coordinates.hpp" +#include "illuminance.hpp" #include "orbit.hpp" #endif // ANTKEEPER_ASTRO_HPP diff --git a/src/astro/blackbody.hpp b/src/astro/blackbody.hpp index 8731bdc..2f5d254 100644 --- a/src/astro/blackbody.hpp +++ b/src/astro/blackbody.hpp @@ -29,7 +29,7 @@ namespace astro * Calculates the color of an ideal black-body radiator, given its temperature in Kelvin. * * @param t Temperature, in Kelvin. - * @return Correlated color, in linear RGB space. + * @return Correlated color, in linear sRGB. * * @see https://en.wikipedia.org/wiki/Planckian_locus * @see https://en.wikipedia.org/wiki/CIE_1960_color_space diff --git a/src/astro/color-index.hpp b/src/astro/color-index.hpp index 682fae7..0d3dd95 100644 --- a/src/astro/color-index.hpp +++ b/src/astro/color-index.hpp @@ -26,10 +26,10 @@ namespace astro /** * Approximates the temperature of a star, given its B-V index. * - * @see Ballesteros, F. J. (2012). "New insights into black bodies". EPL 97 (2012) 34008. - * * @param bv B-V index. * @return Temperature, in Kelvin. + * + * @see Ballesteros, F. J. (2012). "New insights into black bodies". EPL 97 (2012) 34008. */ double bv_to_k(double bv); diff --git a/src/astro/illuminance.cpp b/src/astro/illuminance.cpp new file mode 100644 index 0000000..3d39452 --- /dev/null +++ b/src/astro/illuminance.cpp @@ -0,0 +1,36 @@ +/* + * 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 . + */ + +#include "illuminance.hpp" +#include + +namespace astro +{ + +double vmag_to_lux(double mv) +{ + return std::pow(10.0, (-14.18 - mv) * 0.4); +} + +double lux_to_vmag(double ev) +{ + return -14.18 - 2.5 * std::log(ev); +} + +} // namespace astro diff --git a/src/astro/illuminance.hpp b/src/astro/illuminance.hpp new file mode 100644 index 0000000..0c57f94 --- /dev/null +++ b/src/astro/illuminance.hpp @@ -0,0 +1,48 @@ +/* + * 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 . + */ + +#ifndef ANTKEEPER_ASTRO_ILLUMINANCE_HPP +#define ANTKEEPER_ASTRO_ILLUMINANCE_HPP + +namespace astro +{ + +/** + * Converts apparent (visual) magnitude to lux. + * + * @param mv Illuminance in apparent magnitude. + * @return Illuminance in lux. + * + * @see https://en.wikipedia.org/wiki/Illuminance + */ +double vmag_to_lux(double mv); + +/** + * Converts lux to apparent (visual) magnitude. + * + * @param ev Illuminance in lux. + * @return Illuminance in apparent magnitude. + * + * @see https://en.wikipedia.org/wiki/Illuminance + */ +double lux_to_vmag(double ev); + +} // namespace astro + +#endif // ANTKEEPER_ASTRO_ILLUMINANCE_HPP