How to calculate the moon phase angle? I need to calculate the exact moon phase angle for each our of a day. I have my position in lat and long and a unix timestamp. At the end i would like to be able to caluculate the moon brightness with this formula: https://patents.google.com/patent/DE10113295A1

const moonPhaseAngle = Math.cos(( 2 * ( ( phase * 100 ) / 100 ) -1));

const moonBrightness = 10 * Math.sin( altitude ) * ( .5 + ( .5 * Math.cos( moonPhaseAngle ) ) );


This is my actual progress through web search.
Thank you for helping me!
I refer to the book : Astronomical Algorithms (Second Edition) by Jean Meeus.

To calculate the values of position angle of the bright limb and position angle you will need to calculate  the apparent RA and DEC of the Sun and the Moon.

Code the equations for the Sun RA and DEC using Chapter 25. Please note that L0 (equ. 28.2)  is in error To calculate T (Julian century you will need to compute Julian day (Chapter 7).

Code equations for the Moon RA and Dec from the equations given in Chapter 47.

For the calculation of Apparent RA and Dec you will need to compute Nutation and Obliquity - Equations in Chapter 22.


BTW. For all my calculations I have &quot;standardized&quot; on using the equations on page 144 for the variables : D, M, Mdash, F, and Omega.
Fyi compare the equations for M given in this book ie. equations 25.2 and 47.3

Chapter 48 provides a formula (48.1) for the illuminated fraction of the moons disc.

5.1 I used 48.2 and 48.3
Addition:
5.2 To use equation 48.5 you will need to obtain or write the atan code yourself to resolve the angle X in the correct quadrant - I wrote a routine: ATAN2(sin_tl,cos_bl).
I have coded all the above to run on my HP Prime graphing calculator and they have proved to be very, very accurate.
For the purpose of accurate determination of the moon phase angle you will need to calculate UTC(date and time) using your zone longitude or better still your local longitude.