<p>After some thought, it seems <strong>the procedure is fine, except that a diligent care is needed in the last step of Mapping to [-90, 90]</strong>.</p>
<p>It seems a more careful way to handle this is not by plugging <span class="math-container">$n=0$</span> and them map the results to [-90, 90], but rather to select the <span class="math-container">$n$</span> value (only one can do) that would effect <span class="math-container">$\lambda$</span> in range [-90, 90] .</p>
<p>For instance, in the working example in the question, the solution (76.5927,45.0000) simply does not solve the original equation; this is because <span class="math-container">$\lambda$</span>=−256.5927° (which indeed should solve the original equation) cannot map to any valid <span class="math-container">$\lambda$</span> in range of [-90, +90], because the <span class="math-container">$arctan$</span> is <span class="math-container">$-128.29$</span> hence possible mathematical solution would can also be <span class="math-container">$103.4073$</span> (by <span class="math-container">$n=1$</span>) - but this is not in our required range. The second solution of <span class="math-container">$+285.0953$</span> can indeed be mapped into valid value if <span class="math-container">$n=-1$</span> hence this solution will work.</p>
<p>Now, there are cases of course where we have to get 2 valid solutions (one for the <span class="math-container">$+$</span> the other for the <span class="math-container">$-$</span>). For example, when <span class="math-container">$\delta=0$</span> we must get 2 solution with opposite signs of latitude.</p>
<p>To conclude, if we have a valid solution between [-90, 90] after plugging some <span class="math-container">$n$</span>, I can't see why it should not solve the original equation, and if a value solves the original equation, I cannot see why it should not work physically.</p>

CC BY-SA 4.0
2021-10-31T22:51:00.987Z
@uhoh, not sure I understand what exactly is meant by $arctan$ problem. It interesting the arctan here yielded result in about $−128.29$ or $+142$ - as most calculators simply return values between $-90$ and $90$. Had the calculator returned a regular value,  I think we can safety have $n=0$ - So I don't expect any special problem with using regular $arctan$ functions
d_e
CC BY-SA 4.0
2021-10-31T23:18:25.203Z
Okay, then it doesn't, thanks! I'll repost only the 2nd part.
uhoh
CC BY-SA 4.0
2021-10-31T23:19:39.890Z
For [spherical trigonometry expressions there are usually alternate forms](https://en.wikipedia.org/wiki/Spherical_trigonometry#Identities) that avoid certain computational idiosyncrasies, and these can be generated using [trigonometric identities](https://en.wikipedia.org/wiki/List_of_trigonometric_identities) and [substitutions](https://en.wikipedia.org/wiki/Trigonometric_substitution). I wonder if something like that might be helpful here?
uhoh
CC BY-SA 4.0
2021-11-01T15:34:53.627Z
What you've written is helpful. I was using the *atan2* function which was likely incorrect; using *tan* and discarding values outside the interval $[-90,90]$ seems to work. I need to perform some more calculations to be sure.
sbooth
CC BY-SA 4.0
2021-11-01T19:18:40.633Z
@uhoh, interesting question. I'm not an expert on that. but my hunch says what we have now is pretty neat already and working.
d_e
CC BY-SA 4.0
2021-10-31T22:31:16.610Z
2021-10-31T22:31:16.610Z
d_e
<p>I'm attempting to calculate lines of equal solar altitude, essentially a generalized case of the Earth terminator for solar altitude <span class="math-container">$ h $</span>.</p>
<p>For a given sun position with declination <span class="math-container">$ \delta $</span> and right ascension <span class="math-container">$ \alpha $</span>, I believe the positive north latitude <span class="math-container">$ \lambda $</span> and positive east longitude <span class="math-container">$ \varphi $</span> may be calculated using the equation</p>
<p><span class="math-container">$$
\sin h = \sin \delta \cdot \sin \lambda + \cos \delta \cdot \cos \lambda \cdot \cos \omega
$$</span></p>
<p>where <span class="math-container">$ \omega $</span> is the hour angle <span class="math-container">$ \omega = GST + \varphi - \alpha $</span>.</p>
<p><a href="https://www.wolframalpha.com/input/?i2d=true&amp;i=sin%5C%2840%29h%5C%2841%29%20%3D%20sin%5C%2840%29delta%5C%2841%29%20*%20sin%5C%2840%29lambda%5C%2841%29%20%2B%20cos%5C%2840%29delta%5C%2841%29%20*%20cos%5C%2840%29lambda%5C%2841%29*%20cos%5C%2840%29omega%5C%2841%29%5C%2844%29%20solve%20for%20lambda" rel="nofollow noreferrer">WolframAlpha</a> gives the solution as</p>
<p><span class="math-container">$$
\lambda = 2 \cdot \left( { \arctan{ \left( { \sin \delta \pm \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } } \over { \cos \delta \cdot \cos \omega + \sin h } \right) } } + \pi \cdot n \right)
$$</span></p>
<p>How should the correct value for <span class="math-container">$ \lambda $</span> be determined from the multiple solutions? Intuitively the answer is clear when viewed on a globe (<a href="https://drajmarsh.bitbucket.io/earthsun.html" rel="nofollow noreferrer">excellent visualization</a>) but how can it be expressed mathematically?</p>
<p>I've generated some sample plots using <span class="math-container">$ n = 0 $</span>, where green represents <span class="math-container">$ \sin \delta + \sqrt \ldots $</span>, red represents <span class="math-container">$ \sin \delta - \sqrt \ldots $</span>, and the yellow dot represents the sun's location.</p>
<p>For <span class="math-container">$ h = -0.8333 ° $</span> the correct solution is the curve in green:</p>
<p><a href="https://i.sstatic.net/TuhhB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/TuhhB.png" alt="sunrise/sunset curves" /></a></p>
<p>For <span class="math-container">$ h = -18 ° $</span> the correct solution is the ellipse on the right with green lower half and red upper half:</p>
<p><a href="https://i.sstatic.net/WYzQz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WYzQz.png" alt="astronomical twilight curves" /></a></p>
<p>Alternatively, is there a different/better method to use?</p>
<h2>Worked Example</h2>
<p>Here is an example, with additions based on the answer from <em>d_e</em>, to illustrate the issue (or in case I've made a math error).</p>
<p><span class="math-container">$$
h = -0.8333 °
$$</span>
<span class="math-container">$$
\delta = -14.0670 °
$$</span></p>
<p>Taking <span class="math-container">$ \varphi = 45 ° $</span> and <span class="math-container">$ \omega = 3.3059 rad $</span>:</p>
<p>numerators:</p>
<p><span class="math-container">$$
\sin \delta + \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } = 0.7442
$$</span></p>
<p><span class="math-container">$$
\sin \delta - \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } = -1.2303
$$</span></p>
<p>denominator:</p>
<p><span class="math-container">$$
\cos \delta \cdot \cos \omega + \sin h = -0.9715
$$</span></p>
<h3>Using <em>atan</em></h3>
<p>Latitude values using manual division and the <em>atan</em> function:</p>
<p><span class="math-container">$$
2 \cdot \arctan{ \left( 0.7442 \over -0.9715 \right) } = -74.9047 °
$$</span>
<span class="math-container">$$
2 \cdot \arctan{ \left( -1.2303 \over -0.9715 \right) } = 103.4073 °
$$</span></p>
<p>I believe the value <span class="math-container">$103.4073 °$</span> should be discarded because it is outside the interval <span class="math-container">$[-90 °,90 °]$</span>.</p>
<h3>Using <em>atan2</em></h3>
<p>Latitude values using the <em>atan2</em> function:</p>
<p><span class="math-container">$$
2 \cdot atan2{ \left( 0.7442 \over -0.9715 \right) } = 285.0953°
$$</span>
<span class="math-container">$$
2 \cdot atan2{ \left( -1.2303 \over -0.9715 \right) } = -256.5927°
$$</span></p>
<p>Mapping these values to <span class="math-container">$ [-90 °,90 °] $</span> gives <span class="math-container">$ -74.9047 ° $</span> and <span class="math-container">$ 76.5927 ° $</span>.</p>
<p>Plugging those back into the original equation:</p>
<p>The coordinate <span class="math-container">$ (-74.9047,45.0000) $</span> corresponds to a solar altitude of <span class="math-container">$ -0.8333 ° $</span></p>
<p>The coordinate <span class="math-container">$ (76.5927,45.0000) $</span> corresponds to a solar altitude of <span class="math-container">$ -27.2789 ° $</span> and should be discarded.</p>

CC BY-SA 4.0
2021-10-29T17:50:49.740Z
The solutions can be verified using the original equation and solving for $h$ using the calculated lat/long and checking against the desired $h$, but it seems like there should be a better way.
sbooth
CC BY-SA 4.0
2021-10-30T20:43:45.340Z
@sbooth, which δ and RA of the Sun did you set to plot this? if we take δ=0 for example, and h=-0.83 as in the example, we should indeed have 2 answers for every longitude line (otherwise the symmetry breaks) -so both green and red have to be correct.
d_e
CC BY-SA 4.0
2021-10-30T21:40:22.693Z
@d_e I added a worked example, hopefully there are no math errors.
sbooth
CC BY-SA 4.0
2021-10-24T19:43:36.487Z
All are correct. The ambiguity in $n$ is only one walk around the globe - thus representing the same place. Without loss of generality you can assume n=0. What other solution do you want which is "more" mathematical than the equation for $\lambda$ you quote?
planetmaker
CC BY-SA 4.0
2021-10-24T20:06:14.223Z
I'm looking for a way to discriminate between correct mathematical solutions and the correct physical solution. In the -18° example, the ellipse on the left (with green top and red bottom) represents the line for $h = +18°$ as best I can tell, despite being a solution of the equation for $\lambda$ using -18° for $h$.
sbooth
CC BY-SA 4.0
2021-10-25T08:40:04.113Z
Why not simply select a random point on each ellipse and calculate what is the Sun's altitude? it will clearly give us a definite single number of the altitude angle- then we know if this ellipse is good for us.
d_e
<the-sun><earth><mathematics>
Calculate lines of equal solar altitude
sbooth
# Calculate lines of equal solar altitude

(Asked by: username_0 on 2021-10-24)

I'm attempting to calculate lines of equal solar altitude, essentially a generalized case of the Earth terminator for solar altitude $ h $.

For a given sun position with declination $ \delta $ and right ascension $ \alpha $, I believe the positive north latitude $ \lambda $ and positive east longitude $ \varphi $ may be calculated using the equation

$$
\sin h = \sin \delta \cdot \sin \lambda + \cos \delta \cdot \cos \lambda \cdot \cos \omega
$$

where $ \omega $ is the hour angle $ \omega = GST + \varphi - \alpha $.

[WolframAlpha](https://www.wolframalpha.com/input/?i2d=true&i=sin%5C%2840%29h%5C%2841%29%20%3D%20sin%5C%2840%29delta%5C%2841%29%20*%20sin%5C%2840%29lambda%5C%2841%29%20%2B%20cos%5C%2840%29delta%5C%2841%29%20*%20cos%5C%2840%29lambda%5C%2841%29*%20cos%5C%2840%29omega%5C%2841%29%5C%2844%29%20solve%20for%20lambda) gives the solution as

$$
\lambda = 2 \cdot \left( { \arctan{ \left( { \sin \delta \pm \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } } \over { \cos \delta \cdot \cos \omega + \sin h } \right) } } + \pi \cdot n \right)
$$

How should the correct value for $ \lambda $ be determined from the multiple solutions? Intuitively the answer is clear when viewed on a globe ([excellent visualization](https://drajmarsh.bitbucket.io/earthsun.html)) but how can it be expressed mathematically?

I've generated some sample plots using $ n = 0 $, where green represents $ \sin \delta + \sqrt \ldots $, red represents $ \sin \delta - \sqrt \ldots $, and the yellow dot represents the sun's location.

For $ h = -0.8333 ° $ the correct solution is the curve in green:

[![sunrise/sunset curves](https://i.sstatic.net/TuhhB.png)](https://i.sstatic.net/TuhhB.png)

For $ h = -18 ° $ the correct solution is the ellipse on the right with green lower half and red upper half:

[![astronomical twilight curves](https://i.sstatic.net/WYzQz.png)](https://i.sstatic.net/WYzQz.png)

Alternatively, is there a different/better method to use?

## Worked Example

Here is an example, with additions based on the answer from *d\_e*, to illustrate the issue (or in case I've made a math error).

$$
h = -0.8333 °
$$
$$
\delta = -14.0670 °
$$

Taking $ \varphi = 45 ° $ and $ \omega = 3.3059 rad $:

numerators:

$$
\sin \delta + \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } = 0.7442
$$

$$
\sin \delta - \sqrt { \cos^2 \delta \cdot \cos^2 \omega + \sin^2 \delta - \sin^2 h } = -1.2303
$$

denominator:

$$
\cos \delta \cdot \cos \omega + \sin h = -0.9715
$$

### Using *atan*

Latitude values using manual division and the *atan* function:

$$
2 \cdot \arctan{ \left( 0.7442 \over -0.9715 \right) } = -74.9047 °
$$
$$
2 \cdot \arctan{ \left( -1.2303 \over -0.9715 \right) } = 103.4073 °
$$

I believe the value $103.4073 °$ should be discarded because it is outside the interval $[-90 °,90 °]$.

### Using *atan2*

Latitude values using the *atan2* function:

$$
2 \cdot atan2{ \left( 0.7442 \over -0.9715 \right) } = 285.0953°
$$
$$
2 \cdot atan2{ \left( -1.2303 \over -0.9715 \right) } = -256.5927°
$$

Mapping these values to $ [-90 °,90 °] $ gives $ -74.9047 ° $ and $ 76.5927 ° $.

Plugging those back into the original equation:

The coordinate $ (-74.9047,45.0000) $ corresponds to a solar altitude of $ -0.8333 ° $

The coordinate $ (76.5927,45.0000) $ corresponds to a solar altitude of $ -27.2789 ° $ and should be discarded.

**Tags:** the-sun, earth, mathematics
> **Comments:**
> **username_2**: All are correct. The ambiguity in $n$ is only one walk around the globe - thus representing the same place. Without loss of generality you can assume n=0. What other solution do you want which is "more" mathematical than the equation for $\lambda$ you quote?  
> **username_0**: I'm looking for a way to discriminate between correct mathematical solutions and the correct physical solution. In the -18° example, the ellipse on the left (with green top and red bottom) represents the line for $h = +18°$ as best I can tell, despite being a solution of the equation for $\lambda$ using -18° for $h$.  
> **username_1**: Why not simply select a random point on each ellipse and calculate what is the Sun's altitude? it will clearly give us a definite single number of the altitude angle- then we know if this ellipse is good for us.  
> **username_0**: The solutions can be verified using the original equation and solving for $h$ using the calculated lat/long and checking against the desired $h$, but it seems like there should be a better way.  
> **username_1**: @sbooth, which δ and RA of the Sun did you set to plot this? if we take δ=0 for example, and h=-0.83 as in the example, we should indeed have 2 answers for every longitude line (otherwise the symmetry breaks) -so both green and red have to be correct.  
> **username_0**: @d_e I added a worked example, hopefully there are no math errors.  

---

## 1 answers

### Answer by username_1 on 2021-10-31. Score: 3

After some thought, it seems **the procedure is fine, except that a diligent care is needed in the last step of Mapping to [-90, 90]**.

It seems a more careful way to handle this is not by plugging $n=0$ and them map the results to [-90, 90], but rather to select the $n$ value (only one can do) that would effect $\lambda$ in range [-90, 90] .

For instance, in the working example in the question, the solution (76.5927,45.0000) simply does not solve the original equation; this is because $\lambda$=−256.5927° (which indeed should solve the original equation) cannot map to any valid $\lambda$ in range of [-90, +90], because the $arctan$ is $-128.29$ hence possible mathematical solution would can also be $103.4073$ (by $n=1$) - but this is not in our required range. The second solution of $+285.0953$ can indeed be mapped into valid value if $n=-1$ hence this solution will work.

Now, there are cases of course where we have to get 2 valid solutions (one for the $+$ the other for the $-$). For example, when $\delta=0$ we must get 2 solution with opposite signs of latitude.

To conclude, if we have a valid solution between [-90, 90] after plugging some $n$, I can't see why it should not solve the original equation, and if a value solves the original equation, I cannot see why it should not work physically.

> **Comments:**
> **username_1**: @uhoh, not sure I understand what exactly is meant by $arctan$ problem. It interesting the arctan here yielded result in about $−128.29$ or $+142$ - as most calculators simply return values between $-90$ and $90$. Had the calculator returned a regular value,  I think we can safety have $n=0$ - So I don't expect any special problem with using regular $arctan$ functions  
> **username_3**: Okay, then it doesn't, thanks! I'll repost only the 2nd part.  
> **username_3**: For [spherical trigonometry expressions there are usually alternate forms](https://en.wikipedia.org/wiki/Spherical_trigonometry#Identities) that avoid certain computational idiosyncrasies, and these can be generated using [trigonometric identities](https://en.wikipedia.org/wiki/List_of_trigonometric_identities) and [substitutions](https://en.wikipedia.org/wiki/Trigonometric_substitution). I wonder if something like that might be helpful here?  
> **username_0**: What you've written is helpful. I was using the *atan2* function which was likely incorrect; using *tan* and discarding values outside the interval $[-90,90]$ seems to work. I need to perform some more calculations to be sure.  
> **username_1**: @uhoh, interesting question. I'm not an expert on that. but my hunch says what we have now is pretty neat already and working.  

---

