Browse Source

Add utility function to convert between visual magnitude and lux

master
C. J. Howard 2 years ago
parent
commit
b8b1c33d08
6 changed files with 88 additions and 4 deletions
  1. +0
    -1
      CMakeLists.txt
  2. +1
    -0
      src/astro/astro.hpp
  3. +1
    -1
      src/astro/blackbody.hpp
  4. +2
    -2
      src/astro/color-index.hpp
  5. +36
    -0
      src/astro/illuminance.cpp
  6. +48
    -0
      src/astro/illuminance.hpp

+ 0
- 1
CMakeLists.txt View File

@ -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

+ 1
- 0
src/astro/astro.hpp View File

@ -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

+ 1
- 1
src/astro/blackbody.hpp View File

@ -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

+ 2
- 2
src/astro/color-index.hpp View File

@ -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);

+ 36
- 0
src/astro/illuminance.cpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "illuminance.hpp"
#include <cmath>
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

+ 48
- 0
src/astro/illuminance.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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

Loading…
Cancel
Save