<p>Calculating H (local hour angle) requires knowing the local sidereal time θ and the RA of the moon.  H = θ - RA.
Calculating the LST is not too difficult, but getting the RA of the moon is more involved, described in Ch 47 of Meeus' Astronomical Algorithms. It could be obtained more quickly by just scraping the value from somewhere using cURL.  Once you have these values, then calculating q is straightforward.</p>

CC BY-SA 4.0
2022-02-05T06:02:34.570Z
2022-02-05T13:20:45.060Z
2022-02-05T13:20:45.060Z
user45239
<p>I just finish my blog detailing 3 ways to get Moon phase as seen from your location. The actual working codings are included.
<a href="http://bthoven.blogspot.com/2022/02/formulas-to-determine-or-create.html?view=classic" rel="nofollow noreferrer">3 ways to get Moon phase as seen at your location</a></p>

CC BY-SA 4.0
2022-02-15T16:15:17.433Z
This answer can be expanded. If not it is considered to be a link-only answer. better to be in the comments section
Kavin Ishwaran
CC BY-SA 4.0
2022-02-15T16:15:32.990Z
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/28902)
Kavin Ishwaran
CC BY-SA 4.0
2022-05-07T18:17:57.360Z
While this is an interesting answer, my question was not about the moon phase, but rather the angle and position of the sun reflected on the moon. The calculation of the moon phase isn't difficult, and easily solvable in Meeus's Astronomical Algorithms. The answers given are just further links to other implementations.
Danny F
CC BY-SA 4.0
2022-02-15T13:36:06.723Z
2022-02-15T13:36:06.723Z
bthoven
<p>Your understanding of the illumination is correct. k is the ratio of the illuminated length BC to the diameter AC. New Moon has an illumination of 0, Full Moon an illumination of 1, and the quarter phase an illumination of 0.5.</p>

<p>The position angle is measured counterclockwise from north (celestial north, along a line of right ascension) to the bright limb C. You need to calculate the parallactic angle, q, which is the angle from "up" to celestial north. From chapter 14 (in the 2009 version)
$$
\tan q = \frac{\sin H}{\tan \phi \; \cos \delta - \sin \delta \; \cos H}
$$
where $\phi$ is the geographical latitude, $\delta$ is the declination of the Moon, and H is the hour angle. The diagram below shows a positive value for both q and PA.</p>

<p><a href="https://i.sstatic.net/zQevl.png" rel="noreferrer"><img src="https://i.sstatic.net/zQevl.png" alt="Parallactic and Position Angles"></a></p>

CC BY-SA 4.0
2018-05-10T09:00:59.183Z
You answered a question factually correctly.  Thank you.  However, I still want to implement this programmatically.  I'm going to have to ask in Stackoverflow to figure out how to do this.
Danny F
CC BY-SA 4.0
2021-07-14T16:05:56.490Z
BTW, what's the proper name for the angle **PA-q**, i.e. mathematical difference between the position angle and parallactic angle, which describes the tilt of the bright limb of the Moon "as seen"?
whtyger
CC BY-SA 4.0
2018-05-08T12:46:37.250Z
2018-05-08T14:07:12.860Z
2018-05-08T14:07:12.860Z
JohnHoltz
<p>With Astronomical Algorithms by J. Meeus (1998)
I have obtained the relevant illuminated fraction of the disk and position angle.</p>

<p>But they're numbers (all Greek to me!) I know, Meeus explains that they're ratios of the lengths of the illuminated limb and areas.</p>

<p>Okay, so I have a ratio.  How do I implement that together with the position angle to work out the direction of the illuminated limb and the amount illuminated?</p>

<p>I'm assuming that the ratio 1.0 is totally illuminated (i.e. Full Moon)
and 0.0 is nothing (i.e. New Moon).</p>

<p>and then there is the position angle, I'm assuming that the direction in degrees is starting at 0 pointing upwards.  Is that the crescent shape direction i.e. the horns are pointing away from the directional angle?</p>

<p>I would like to be able plot this so that I can show visually the moon's illuminated fraction and direction for any day in any given year.</p>

<p>As I said, I have the numbers, I'm trying to translate that into a more visually appealling and meaningful result.</p>

<p>Meeus says this is the selenocentric elongation of the Earth from the Sun (Phase Angle) - i.   </p>

<p>the formula for illuminated fraction k is:</p>

<p>k = ( 1 + cos i ) / 2</p>

<p>tan i = (R sin l) / (D - (R cos l))</p>

<p>R = distance Earth-Sun
D = distance Earth-Moon
l = geocentric elongation</p>

<p>Meeus calls k the ratio of the lengths BC:AC
the same as the ratio of the areas: NBSC:NASC</p>

<p>Where</p>

<p><a href="https://i.sstatic.net/rOTD1.jpg" rel="noreferrer"><img src="https://i.sstatic.net/rOTD1.jpg" alt="Illuminated Fraction of Moon"></a></p>

CC BY-SA 4.0
2018-05-08T13:58:37.217Z
If celestial north is up, this diagram shows an illuminated fraction of 0.35 and a position angle of 290$^\circ$.
Mike G
CC BY-SA 4.0
2021-08-25T15:00:10.340Z
@MikeG Thanks, but how do you know that? and which angle is the position angle in the diagram?
Danny F
CC BY-SA 4.0
2021-08-25T19:02:44.717Z
I measured the image: C is 290° counterclockwise from the top, and CB = 0.35 CA.
Mike G
CC BY-SA 4.0
2021-08-28T22:57:07.480Z
What makes you think this is to scale or represents the actual measurement?  Please note that Meeus in fact doesn't use any values in his descriptions and algorithms, he only uses them in his working examples.  In any event, what use is a diagram without a reference point, date, location, time etc.?  I think you're missing the point of the question.
Danny F
CC BY-SA 4.0
2021-08-29T21:25:57.893Z
Obviously the diagram above is only an example. If you need clarification beyond the accepted answer, I suggest posting a new question focusing on that issue so we're less likely to latch onto the wrong thing.
Mike G
CC BY-SA 4.0
2022-02-06T04:12:39.887Z
Many of Meeus' techniques are from an era when computation was slow.  If you want to draw a diagram of the moon, you're better off using modern techniques from computer graphics.  You can use methods from his book to compute the position of the observer, Sun and Moon.  Then use ray tracing and texturization to draw the moon.  Meeus' technique might be slightly faster, but at the expense of implementing and learning algorithms that serve only one purpose.
Greg Miller
CC BY-SA 4.0
2022-02-06T08:12:12.790Z
@GregMiller do you have a better, more comprehensive, modern and updated book that has algorithms for both programmer and astronomer?  reviewing the latest books on the subject, Meeus' work stands out and has not been surpassed in any shape or form.  The exceptions being Planetary Programs and Tables from -4000 to +2800: Tables for the Motion of the Sun and the Five Bright Planets by P. Bretagnon and Lunar Tables and Programs from 4000 B.C. to A.D. 8000 by M. Chapront-Touze, J. Chapront.  However these alternatives are very complex (they do offer less precision) and are limited in scope
Danny F
CC BY-SA 4.0
2022-02-06T14:56:52.100Z
There isn't anything that covers it from an astronomical perspective, you'd need to buy a general graphics programming book and apply it to astronomy.  The algorithm you're asking about is featured on the cover of the 2nd edition of his "Astronomical Fomulae for Calculators" published in 1982, and the concepts are unchanged in the latest edition of Astronomical Algorithms.  Back then, the idea of producing a photorealistic rendering of the moon was unheard of.  At some point you'll have to loop over every pixel of the moon to determine if it's in shadow or not...[continued].
Greg Miller
CC BY-SA 4.0
2022-02-06T15:02:23.047Z
...That's not in Meuus' book.  If you look at ray tracing, or other rendering algorithms, you'll find it more directly solves the problem you want to solve.  I won't make any recommendations, as what I have is pretty old too.  But you can find numerous tutorials on-line for "texturing a sphere".  But, if you find Meuus' algorithms easier to follow, but all means stick with those, it's solving the same problem.
Greg Miller
<the-moon><observational-astronomy><celestial-mechanics>
Implementation of formulae for Meeus for the Moon
Danny F
# Implementation of formulae for Meeus for the Moon

(Asked by: username_0 on 2018-05-07)

With Astronomical Algorithms by J. Meeus (1998)
I have obtained the relevant illuminated fraction of the disk and position angle.

But they're numbers (all Greek to me!) I know, Meeus explains that they're ratios of the lengths of the illuminated limb and areas.

Okay, so I have a ratio. How do I implement that together with the position angle to work out the direction of the illuminated limb and the amount illuminated?

I'm assuming that the ratio 1.0 is totally illuminated (i.e. Full Moon)
and 0.0 is nothing (i.e. New Moon).

and then there is the position angle, I'm assuming that the direction in degrees is starting at 0 pointing upwards. Is that the crescent shape direction i.e. the horns are pointing away from the directional angle?

I would like to be able plot this so that I can show visually the moon's illuminated fraction and direction for any day in any given year.

As I said, I have the numbers, I'm trying to translate that into a more visually appealling and meaningful result.

Meeus says this is the selenocentric elongation of the Earth from the Sun (Phase Angle) - i.

the formula for illuminated fraction k is:

k = ( 1 + cos i ) / 2

tan i = (R sin l) / (D - (R cos l))

R = distance Earth-Sun
D = distance Earth-Moon
l = geocentric elongation

Meeus calls k the ratio of the lengths BC:AC
the same as the ratio of the areas: NBSC:NASC

Where

[![Illuminated Fraction of Moon](https://i.sstatic.net/rOTD1.jpg)](https://i.sstatic.net/rOTD1.jpg)

**Tags:** the-moon, observational-astronomy, celestial-mechanics

> **Comments:**
> **username_1**: If celestial north is up, this diagram shows an illuminated fraction of 0.35 and a position angle of 290$^\circ$.  
> **username_0**: @username_1 Thanks, but how do you know that? and which angle is the position angle in the diagram?  
> **username_1**: I measured the image: C is 290° counterclockwise from the top, and CB = 0.35 CA.  
> **username_0**: What makes you think this is to scale or represents the actual measurement?  Please note that Meeus in fact doesn't use any values in his descriptions and algorithms, he only uses them in his working examples.  In any event, what use is a diagram without a reference point, date, location, time etc.?  I think you're missing the point of the question.  
> **username_1**: Obviously the diagram above is only an example. If you need clarification beyond the accepted answer, I suggest posting a new question focusing on that issue so we're less likely to latch onto the wrong thing.  
> **username_2**: Many of Meeus' techniques are from an era when computation was slow.  If you want to draw a diagram of the moon, you're better off using modern techniques from computer graphics.  You can use methods from his book to compute the position of the observer, Sun and Moon.  Then use ray tracing and texturization to draw the moon.  Meeus' technique might be slightly faster, but at the expense of implementing and learning algorithms that serve only one purpose.  
> **username_0**: @username_2 do you have a better, more comprehensive, modern and updated book that has algorithms for both programmer and astronomer?  reviewing the latest books on the subject, Meeus' work stands out and has not been surpassed in any shape or form.  The exceptions being Planetary Programs and Tables from -4000 to +2800: Tables for the Motion of the Sun and the Five Bright Planets by P. Bretagnon and Lunar Tables and Programs from 4000 B.C. to A.D. 8000 by M. Chapront-Touze, J. Chapront.  However these alternatives are very complex (they do offer less precision) and are limited in scope  
> **username_2**: There isn't anything that covers it from an astronomical perspective, you'd need to buy a general graphics programming book and apply it to astronomy.  The algorithm you're asking about is featured on the cover of the 2nd edition of his "Astronomical Fomulae for Calculators" published in 1982, and the concepts are unchanged in the latest edition of Astronomical Algorithms.  Back then, the idea of producing a photorealistic rendering of the moon was unheard of.  At some point you'll have to loop over every pixel of the moon to determine if it's in shadow or not...[continued].  
> **username_2**: ...That's not in Meuus' book.  If you look at ray tracing, or other rendering algorithms, you'll find it more directly solves the problem you want to solve.  I won't make any recommendations, as what I have is pretty old too.  But you can find numerous tutorials on-line for "texturing a sphere".  But, if you find Meuus' algorithms easier to follow, but all means stick with those, it's solving the same problem.  

---

## 3 answers

### Answer by username_6 on 2018-05-08. Score: 6 | Accepted answer

Your understanding of the illumination is correct. k is the ratio of the illuminated length BC to the diameter AC. New Moon has an illumination of 0, Full Moon an illumination of 1, and the quarter phase an illumination of 0.5.

The position angle is measured counterclockwise from north (celestial north, along a line of right ascension) to the bright limb C. You need to calculate the parallactic angle, q, which is the angle from "up" to celestial north. From chapter 14 (in the 2009 version)
$$
\tan q = \frac{\sin H}{\tan \phi \; \cos \delta - \sin \delta \; \cos H}
$$
where $\phi$ is the geographical latitude, $\delta$ is the declination of the Moon, and H is the hour angle. The diagram below shows a positive value for both q and PA.

[![Parallactic and Position Angles](https://i.sstatic.net/zQevl.png)](https://i.sstatic.net/zQevl.png)

> **Comments:**
> **username_0**: You answered a question factually correctly.  Thank you.  However, I still want to implement this programmatically.  I'm going to have to ask in Stackoverflow to figure out how to do this.  
> **username_7**: BTW, what's the proper name for the angle **PA-q**, i.e. mathematical difference between the position angle and parallactic angle, which describes the tilt of the bright limb of the Moon "as seen"?  

---

### Answer by username_3 on 2022-02-05. Score: 0

Calculating H (local hour angle) requires knowing the local sidereal time θ and the RA of the moon. H = θ - RA.
Calculating the LST is not too difficult, but getting the RA of the moon is more involved, described in Ch 47 of Meeus' Astronomical Algorithms. It could be obtained more quickly by just scraping the value from somewhere using cURL. Once you have these values, then calculating q is straightforward.


---

### Answer by username_4 on 2022-02-15. Score: -1

I just finish my blog detailing 3 ways to get Moon phase as seen from your location. The actual working codings are included.
[3 ways to get Moon phase as seen at your location](http://username_4.blogspot.com/2022/02/formulas-to-determine-or-create.html?view=classic)

> **Comments:**
> **username_5**: This answer can be expanded. If not it is considered to be a link-only answer. better to be in the comments section  
> **username_5**: While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/28902)  
> **username_0**: While this is an interesting answer, my question was not about the moon phase, but rather the angle and position of the sun reflected on the moon. The calculation of the moon phase isn't difficult, and easily solvable in Meeus's Astronomical Algorithms. The answers given are just further links to other implementations.  

---

