From 45ea0ea113d0709f70a996ea6c3fc38aa0aa84d4 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Fri, 5 Nov 2021 20:27:58 -0400 Subject: [PATCH] Fixed #131 - Added phase_fraction in C, C#. The C and C# Illumination functions now return a `phase_fraction` result to complement `phase_angle`. This makes them consistent with the Python and JavaScript versions. --- generate/template/astronomy.c | 2 ++ generate/template/astronomy.cs | 4 ++++ source/c/README.md | 1 + source/c/astronomy.c | 2 ++ source/c/astronomy.h | 1 + source/csharp/README.md | 1 + source/csharp/astronomy.cs | 4 ++++ 7 files changed, 15 insertions(+) diff --git a/generate/template/astronomy.c b/generate/template/astronomy.c index 03236173..f0ab3c44 100644 --- a/generate/template/astronomy.c +++ b/generate/template/astronomy.c @@ -466,6 +466,7 @@ static astro_illum_t IllumError(astro_status_t status) result.time = TimeError(); result.mag = NAN; result.phase_angle = NAN; + result.phase_fraction = NAN; result.helio_dist = NAN; result.ring_tilt = NAN; @@ -5364,6 +5365,7 @@ astro_illum_t Astronomy_Illumination(astro_body_t body, astro_time_t time) illum.time = time; illum.mag = mag; illum.phase_angle = phase.angle; + illum.phase_fraction = (1.0 + cos(DEG2RAD * phase.angle)) / 2.0; illum.helio_dist = helio_dist; illum.ring_tilt = ring_tilt; diff --git a/generate/template/astronomy.cs b/generate/template/astronomy.cs index d82fc27a..c5e01ae2 100644 --- a/generate/template/astronomy.cs +++ b/generate/template/astronomy.cs @@ -1358,6 +1358,9 @@ namespace CosineKitty /// The angle in degrees between the Sun and the Earth, as seen from the body. Indicates the body's phase as seen from the Earth. public readonly double phase_angle; + /// A value in the range [0.0, 1.0] indicating what fraction of the body's apparent disc is illuminated, as seen from the Earth. + public readonly double phase_fraction; + /// The distance between the Sun and the body at the observation time. public readonly double helio_dist; @@ -1369,6 +1372,7 @@ namespace CosineKitty this.time = time; this.mag = mag; this.phase_angle = phase_angle; + this.phase_fraction = (1.0 + Math.Cos(Astronomy.DEG2RAD * phase_angle)) / 2.0; this.helio_dist = helio_dist; this.ring_tilt = ring_tilt; } diff --git a/source/c/README.md b/source/c/README.md index c2aba08e..8a68fe0d 100644 --- a/source/c/README.md +++ b/source/c/README.md @@ -3252,6 +3252,7 @@ Returned by the functions [`Astronomy_Illumination`](#Astronomy_Illumination) an | [`astro_time_t`](#astro_time_t) | `time` | The date and time of the observation. | | `double` | `mag` | The visual magnitude of the body. Smaller values are brighter. | | `double` | `phase_angle` | The angle in degrees between the Sun and the Earth, as seen from the body. Indicates the body's phase as seen from the Earth. | +| `double` | `phase_fraction` | A value in the range [0.0, 1.0] indicating what fraction of the body's apparent disc is illuminated, as seen from the Earth. | | `double` | `helio_dist` | The distance between the Sun and the body at the observation time. | | `double` | `ring_tilt` | For Saturn, the tilt angle in degrees of its rings as seen from Earth. For all other bodies, 0. | diff --git a/source/c/astronomy.c b/source/c/astronomy.c index 0fba4197..53c8b427 100644 --- a/source/c/astronomy.c +++ b/source/c/astronomy.c @@ -466,6 +466,7 @@ static astro_illum_t IllumError(astro_status_t status) result.time = TimeError(); result.mag = NAN; result.phase_angle = NAN; + result.phase_fraction = NAN; result.helio_dist = NAN; result.ring_tilt = NAN; @@ -6590,6 +6591,7 @@ astro_illum_t Astronomy_Illumination(astro_body_t body, astro_time_t time) illum.time = time; illum.mag = mag; illum.phase_angle = phase.angle; + illum.phase_fraction = (1.0 + cos(DEG2RAD * phase.angle)) / 2.0; illum.helio_dist = helio_dist; illum.ring_tilt = ring_tilt; diff --git a/source/c/astronomy.h b/source/c/astronomy.h index 06f3175b..4609ff1b 100644 --- a/source/c/astronomy.h +++ b/source/c/astronomy.h @@ -573,6 +573,7 @@ typedef struct astro_time_t time; /**< The date and time of the observation. */ double mag; /**< The visual magnitude of the body. Smaller values are brighter. */ double phase_angle; /**< The angle in degrees between the Sun and the Earth, as seen from the body. Indicates the body's phase as seen from the Earth. */ + double phase_fraction; /**< A value in the range [0.0, 1.0] indicating what fraction of the body's apparent disc is illuminated, as seen from the Earth. */ double helio_dist; /**< The distance between the Sun and the body at the observation time. */ double ring_tilt; /**< For Saturn, the tilt angle in degrees of its rings as seen from Earth. For all other bodies, 0. */ } diff --git a/source/csharp/README.md b/source/csharp/README.md index 00dd443e..cc7ea648 100644 --- a/source/csharp/README.md +++ b/source/csharp/README.md @@ -2181,6 +2181,7 @@ to report the visual magnitude and illuminated fraction of a celestial body at a | [`AstroTime`](#AstroTime) | `time` | The date and time of the observation. | | `double` | `mag` | The visual magnitude of the body. Smaller values are brighter. | | `double` | `phase_angle` | The angle in degrees between the Sun and the Earth, as seen from the body. Indicates the body's phase as seen from the Earth. | +| `double` | `phase_fraction` | A value in the range [0.0, 1.0] indicating what fraction of the body's apparent disc is illuminated, as seen from the Earth. | | `double` | `helio_dist` | The distance between the Sun and the body at the observation time. | | `double` | `ring_tilt` | For Saturn, the tilt angle in degrees of its rings as seen from Earth. For all other bodies, 0. | diff --git a/source/csharp/astronomy.cs b/source/csharp/astronomy.cs index d79bf2ae..3d545e0d 100644 --- a/source/csharp/astronomy.cs +++ b/source/csharp/astronomy.cs @@ -1358,6 +1358,9 @@ namespace CosineKitty /// The angle in degrees between the Sun and the Earth, as seen from the body. Indicates the body's phase as seen from the Earth. public readonly double phase_angle; + /// A value in the range [0.0, 1.0] indicating what fraction of the body's apparent disc is illuminated, as seen from the Earth. + public readonly double phase_fraction; + /// The distance between the Sun and the body at the observation time. public readonly double helio_dist; @@ -1369,6 +1372,7 @@ namespace CosineKitty this.time = time; this.mag = mag; this.phase_angle = phase_angle; + this.phase_fraction = (1.0 + Math.Cos(Astronomy.DEG2RAD * phase_angle)) / 2.0; this.helio_dist = helio_dist; this.ring_tilt = ring_tilt; }