Skip to content

Commit 462c18d

Browse files
committed
wip
1 parent 84e6b43 commit 462c18d

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

src/celastro/astro.cpp

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,40 +56,49 @@ negateIf(double& d, bool condition)
5656

5757

5858
// Computes the luminosity of a perfectly reflective disc.
59-
// It can be used as an upper bound for the irradiance of an object when culling invisible objects.
59+
// It is also used as an upper bound for the irradiance of an object when culling invisible objects.
6060
// The function translates luminosity into luminosity of the same units
6161
// (distanceFromSun and objRadius must also be in the same units).
62-
static float reflectedLuminosity(float sunLuminosity,
63-
float distanceFromSun,
64-
float objRadius)
62+
float reflectedLuminosity(float sunLuminosity,
63+
float distanceFromSun,
64+
float objRadius)
6565
{
6666
float lengthRatio = objRadius / distanceFromSun;
6767
return sunLuminosity * 0.25 * lengthRatio * lengthRatio;
6868
}
6969

7070

71-
// Return the absolute magnitude of a star with lum times solar absolute luminosity
71+
// The following notation rules apply in the functions below and in the code in general:
72+
// - Luminosity is implied in solar units (in SI, flux is measured in W)
73+
// - Irradiance is implied in vegan units (in SI, it is measured in W/m^2)
74+
75+
// Absolute magnitude is the logarithmic inverse of luminosity.
76+
// Apparent magnitude is the logarithmic inverse of irradiance.
77+
78+
79+
// Luminosity conversions:
80+
7281
float
7382
lumToAbsMag(float lum)
7483
{
7584
return SOLAR_ABSMAG - std::log(lum) * LN_MAG;
7685
}
7786

78-
// Return the apparent magnitude of a star with lum times solar luminosity viewed at lyrs light years
7987
float
8088
lumToAppMag(float lum, float lyrs)
8189
{
8290
return absToAppMag(lumToAbsMag(lum), lyrs);
8391
}
8492

85-
// Return the irradiance of a star in Vega units with lum times solar luminosity viewed at the distance in km
8693
float
8794
lumToIrradiance(float lum, float km)
8895
{
8996
return lum * SOLAR_POWER / (math::sphereArea(km * 1000) * VEGAN_IRRADIANCE);
9097
}
9198

9299

100+
// Magnitude conversions:
101+
93102
float
94103
absMagToLum(float mag)
95104
{
@@ -108,14 +117,17 @@ absMagToIrradiance(float mag, float km)
108117
return lumToIrradiance(absMagToLum(mag), km);
109118
}
110119

111-
// Conversions between the magnitude system and irradiance in Vega units
120+
121+
// Logarithmic magnitude system <-> linear irradiance system in Vega units:
122+
112123
float
113124
magToIrradiance(float mag)
114125
{
115126
return std::exp(- mag / LN_MAG);
116127
// slower solution:
117128
// return std::pow(10.0f, -0.4f * mag);
118129
}
130+
119131
float
120132
irradianceToMag(float irradiance)
121133
{
@@ -124,14 +136,17 @@ irradianceToMag(float irradiance)
124136
// return -2.5f * std::log10(irradiance);
125137
}
126138

127-
// Conversions between the faintest star magnitude system and exposure
139+
140+
// Faintest star magnitude system <-> exposure time:
141+
128142
float
129143
faintestMagToExposure(float faintestMag)
130144
{
131145
return std::exp(faintestMag / LN_MAG) * IRRADIATION_LIMIT;
132146
// slower solution:
133147
// return std::pow(10.0f, 0.4f * faintestMag) * IRRADIATION_LIMIT;
134148
}
149+
135150
float
136151
exposureToFaintestMag(float exposure)
137152
{
@@ -140,6 +155,7 @@ exposureToFaintestMag(float exposure)
140155
// return 2.5f * std::log10(exposure / IRRADIATION_LIMIT);
141156
}
142157

158+
143159
void
144160
decimalToDegMinSec(double angle, int& degrees, int& minutes, double& seconds)
145161
{

src/celastro/astro.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ constexpr inline auto JUPITER_RADIUS = detail::enable_if_fp<T>(71492.0L);
7272
template<typename T>
7373
constexpr inline auto SOLAR_RADIUS = detail::enable_if_fp<T>(696000.0L);
7474

75-
static float reflectedLuminosity(float sunLuminosity, float distanceFromSun, float objRadius);
75+
float reflectedLuminosity(float sunLuminosity, float distanceFromSun, float objRadius);
7676

7777
// Magnitude conversions
7878
float lumToAbsMag(float lum);

src/celengine/body.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,9 @@ float Body::getLuminosity(const Star& sun,
824824
float Body::getLuminosity(float sunLuminosity,
825825
float distanceFromSun) const
826826
{
827-
return getReflectivity() * astro::reflectedLuminosity(float sunLuminosity,
828-
float distanceFromSun,
829-
float radius);
827+
return getReflectivity() * astro::reflectedLuminosity(sunLuminosity,
828+
distanceFromSun,
829+
radius);
830830
}
831831

832832

@@ -893,8 +893,8 @@ float Body::getIrradiance(float sunLuminosity,
893893
float distanceFromViewer) const
894894
{
895895
// Compute the reflected flux (luminosity) in SI units
896-
float reflectedFlux = astro::SOLAR_POWER * getLuminosity(float sunLuminosity,
897-
float distanceFromSun);
896+
float reflectedFlux = astro::SOLAR_POWER * getLuminosity(sunLuminosity,
897+
distanceFromSun);
898898

899899
// Compute the irradiance at the observer's distance from the planet
900900
float obsIrradiance = reflectedFlux / math::sphereArea(distanceFromViewer * 1000); // km to m

0 commit comments

Comments
 (0)