Author Topic: Phases of the moon - query  (Read 5507 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Phases of the moon - query
« on: September 11, 2021, 05:34:37 am »
Hi,
has anyone on the forum addressed this issue? Why do I ask. Because of the calendar. According to the definition of the Easter holidays, it is always published on the first Sunday after the first spring full moon. So it's after the full moon, which will take place after March 21st. For this reason - if no one has dealt with it yet, I have two options. Either insert pre-computed data obtained elsewhere into the program, or try (this is an exact expression - try) to write this algorithm. But if anyone already had it, I would be very grateful for.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Phases of the moon - query
« Reply #1 on: September 11, 2021, 06:27:14 am »
My little calendar program tracks moon phases, as well as Easter holiday and a whole bunch of others derived from it.  (Like Good Friday, Ash Wednesday, and all)

To find Easter for the years 2000 to 2099 (which is all I figured my calendar needed), it’s as simple as:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3. FOR y = 2000 TO 2099
  4.     FindEaster y, m, d
  5.     PRINT m; "-"; d; "-"; y,
  6.  
  7. SUB FindEaster (y, m, d) 'for the 21st century
  8.     m = 3
  9.     temp = (204.5 - 11 * (y MOD 19)) MOD 30 + 21
  10.     IF (temp = 49 AND y MOD 19 > 10) OR (temp = 50) THEN temp = temp - 1
  11.     d = temp + ((20 - (temp - 19) MOD 7 - INT((y MOD 100) * 1.25) MOD 7) MOD 7) + 1
  12.     IF d > 31 THEN d = d - 31: m = m + 1
  13.  
« Last Edit: September 11, 2021, 06:32:58 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Phases of the moon - query
« Reply #2 on: September 11, 2021, 06:40:29 am »
Moon Phases, if I remember correctly, I simply started with a single predetermined date, calculated the difference between that date and the desired date, and then modded by 27 days, 7 hours, and 43 minutes.

(Difference betweenTimestamps of both dates in minutes) MOD (27 * 24 * 60 + 7 * 60 +43), or very similar, if my brain is remembering correctly.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Phases of the moon - query
« Reply #3 on: September 11, 2021, 06:48:50 am »
Sorry…. That’s for a sidereal month.

The synodic month (Greek: συνοδικός, romanized: synodikós, meaning "pertaining to a synod, i.e., a meeting"; in this case, of the Sun and the Moon), also lunation, is the average period of the Moon's orbit with respect to the line joining the Sun and Earth: 29 d 12 h 44 min and 2.9 s. This is the period of the lunar phases, because the Moon's appearance depends on the position of the Moon with respect to the Sun as seen from the Earth.

While the Moon is orbiting the Earth, the Earth is progressing in its orbit around the Sun. After completing a sidereal month, the Moon must move a little further to reach the new position having the same angular distance from the Sun, appearing to move with respect to the stars since the previous month. Therefore, the synodic month takes 2.2 days longer than the sidereal month. Thus, about 13.37 sidereal months, but about 12.37 synodic months, occur in a Gregorian year.

Since Earth's orbit around the Sun is elliptical and not circular, the speed of Earth's progression around the Sun varies during the year. Thus, the angular rate is faster nearer periapsis and slower near apoapsis. The same is so for the Moon's orbit around the Earth. Because of these variations in angular rate, the actual time between lunations may vary from about 29.18 to about 29.93 days. The average duration in modern times is 29.53059 days with up to seven hours variation about the mean in any given year.[5][a] A more precise figure may be derived for a specific synodic month using the lunar theory of Chapront-Touzé and Chapront (1988):
29.5305888531 + 0.00000021621T − 3.64×10−10T2 where T = (JD − 2451545.0)/36525 and JD is the Julian day number.[7] The duration of synodic months in ancient and medieval history is itself a topic of scholarly study.[8]
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Phases of the moon - query
« Reply #4 on: September 11, 2021, 07:05:03 am »
@SMcNeill

Thank you very much, Steve. I was looking at some source program in PHP from the astronomical forum, well, actually, it was too much for me (there was more to it than I needed and what I was able to orientate myself in). Your program is exactly what I was looking for. You saved me a lot of headaches.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Phases of the moon - query
« Reply #5 on: September 11, 2021, 08:24:07 am »
Yeah, a lot of those guys want precision to the twentieth decimal point for a time frame of billions of years….  When the rest of us just need to know what DAY something falls on in our lifetimes.  Perfect precision isn’t needed everywhere, and as a farmer all my life, I’m quite adapt at dealing with “Meh!  Close enough — it works for me!”

*********

Which is what drives STxATxIC crazy about my work.  He’s into physics where 0.0000000001 precision matters to him.  I’m in farming, where my cow weighs “bout 1200 pounds, give or take a leg…” and the market price is $1.23 a pound…. “bout one and a quarter, so close to $1000….” Give me $950 and a beer, and she’s yours!

STx wants and expects precise answers.  I just need simple working solutions.  There’s a world of difference in the requirements for our perspective fields!  ;D
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline jack

  • Seasoned Forum Regular
  • Posts: 408
    • View Profile
Re: Phases of the moon - query
« Reply #6 on: September 11, 2021, 08:54:08 am »
Hi Petr, I found this Qbasic code http://www.stargazing.net/kepler/moon2.html

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Phases of the moon - query
« Reply #7 on: September 11, 2021, 09:19:18 am »
@SMcNeill
I totally agree with you. Have the calculation so accurate - why? So, of course, if we were to count something billions of kilometers away, then every slight inaccuracy plays a role. I do it as you describe it. It is simply rounded and when there is an agreement between the seller and the buyer, everyone is satisfied.

@jack
Thanks for the link, I'll take a look.

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: Phases of the moon - query
« Reply #8 on: September 11, 2021, 10:28:07 am »
As far as the Easter Sunday calculation, I have converted an  old Commodore 64 program I had. It uses the WEBB algorithm, and is capable of calculating Easter for any year after the adoption of the Gregorian Calendar.

It was written in 1984 by Eric Burgess.

Here is my Easter Sunday program, converted to QB64 about a year ago:

Code: QB64: [Select]
  1. _TITLE "Calculate Easter Sunday For Any Year"
  2. ' PROGRAM: EASTER SUNDAY
  3. ' ***************************************************************************************
  4. '    THIS PROGRAM CALCULATES THE DATE EASTER FALLS ON FROM
  5. '    1583 TO AN INFINITE FUTURE DATE.
  6. '    ORIGINAL CODE FROM COMMODORE 64 TO QB64
  7. '
  8. ' ORIGINAL PROGRAM FOR 8-BIT COMPUTERS BY BY ERIC BURGESS F.R.A.S. (NOV, 1984)
  9. '    CODE IS FROM THE BOOK "CELESTIAL BASIC" BY ERIC BURGESS (REVISED IN 1985)
  10. '
  11. ' MODIFIED TO RUN IN QB64 BY GEORGE MCGINN (SEPT, 2020)
  12. '    REWORKED THE CODE TO BE MORE STRUCTURED THAN IT WAS WITH ITS ORIGINAL LINE NUMBERS
  13. '    ALSO REMOVED THE FORMULA THAT CALCULATED MOD AS QB64 HAS A MOD STATEMENT
  14. '    ADDED A SECTION TO DIPLAY INFO BOXES (showAbout).
  15. ' ***************************************************************************************
  16.  
  17. DECLARE FUNCTION PRINTLINES (LINES)
  18. DECLARE FUNCTION showAbout (X)
  19.  
  20. MAIN_LOGIC:
  21.  
  22.     GOTO INTRODUCTION
  23.  
  24.  
  25. EXPLANATION:
  26. '***************************************************************************************************
  27. ' *** Show the about box. Comment out the next line to prevent the About alert
  28. ' *** from showing up when the program starts.
  29.     CLS
  30.     result = showAbout(1)
  31.     PAUSE
  32.     CLS
  33.     GOTO RETRIEVE_YEAR
  34.  
  35.    
  36. INTRODUCTION:
  37.     result = showAbout(2)
  38.     PRINT: PRINT
  39.     PRINT "AN ASTRONOMY PROGRAM"
  40.     PRINT
  41.     PRINT "*********************"
  42.     PRINT "*    EASTER SUNDAY  *"
  43.     PRINT "*********************"
  44.     PRINT: PRINT
  45.     PRINT "BY ERIC BURGESS F.R.A.S."
  46.     PRINT
  47.     PRINT "ALL RIGHTS RESERVED BY"
  48.     PRINT "S+T SOFTWARE SERVICES"
  49.     PRINT "A DIVISION OF"
  50.     PRINT "AMERICAN ONLY. INC."
  51.     PRINT TAB(5); "ORIGINAL CODE: NOVEMBER 1984"
  52.     PRINT TAB(5); "FROM THE BOOK 'CELESTIAL BASIC' BY ERIC BURGESS (REVISED IN 1985)"
  53.     PRINT
  54.     PRINT "MODIFIED BY GEORGE MCGINN FOR QB64"
  55.     PRINT TAB(5); "MODIFIED CODE: SEPTEMBER 2020 + MARCH 2021"
  56.     PRINT: PRINT
  57.    
  58.  
  59. GET_EXPLANATION:
  60.     INPUT "DO YOU WANT AN EXPLANATION? Y/N "; A$
  61.     A$ = UCASE$(A$)
  62.  
  63.     SELECT CASE A$
  64.           CASE "Y", "YES"
  65.                 PRINT
  66.                 GOTO EXPLANATION
  67.           CASE "N", "NO"
  68.                 GOTO RETRIEVE_YEAR
  69.           CASE ELSE
  70.                 PRINT "INVALID ANSWER"
  71.                 PRINT " "
  72.                 GOTO GET_EXPLANATION
  73.     END SELECT
  74.  
  75.      
  76. RETRIEVE_YEAR:
  77.     PRINT: PRINT
  78.     INPUT "YEAR (REQURED-YYYY) "; Y
  79.     Y$ = STR$(Y)
  80.     IF LEN(Y$) < 4 THEN
  81.       PRINT "INVALID YEAR"
  82.       PRINT
  83.       GOTO RETRIEVE_YEAR
  84.     END IF
  85.    
  86.     Y = VAL(Y$)
  87.     IF Y < 1583 THEN
  88.       PRINT "YEAR MUST BE AFTER 1582"
  89.       PRINT
  90.       GOTO RETRIEVE_YEAR
  91.     END IF
  92.  
  93.    
  94. WEBB_ALGORITHM:
  95. '*** START OF WEBB ALGORITHM
  96.     QC = .05: QX = Y / .8: B1 = 19: B2 = 30: B3 = 7: Y2 = Y / 100
  97.     L = INT((Y / B1 - INT(Y / B1)) * B1 + QC) * SGN(Y / B1)
  98.     A = (11 * (L + 4) + INT(.32 * (1 + INT(Y2)) + .2) - INT(.75 * (1 - INT(Y2))))
  99.     E = INT((A / B2 - INT(A / B2)) * B2 + QC) * SGN(A / B2)
  100.     IF E <= (L / 10) THEN E = E + 1
  101.     F = INT(QX) - E + 3 - INT(.75 * (1 - INT(YZ)))
  102.     F2 = INT((F / B3 - INT(F / B3)) * B3 - QC) * SGN(F / B3)
  103.     D = 26 - E - F2
  104.     IF D <= 0 THEN
  105.       D = D + 31
  106.       M = 3
  107.       M$ = "MARCH"
  108.     ELSE
  109.       M = 4
  110.       M$ = "APRIL"
  111.     END IF
  112. '*** END OF WEBB ALGORITHM
  113.  
  114.  
  115. DISPLAY_EASTER_DATE:
  116. '*** DISPLAYS THE DATE EASTER FALLS ON THE YEAR SELECTED
  117.     PRINT: PRINT
  118.     PRINT "EASTER SUNDAY IN "; Y; " IS ON ... "; M$; " "; D
  119.     PRINT: PRINT
  120.  
  121.  
  122. ENDPROCESS:
  123. '*** END OF PROGRAM ROUTINE OR PROCESS ANOTHER YEAR
  124.     INPUT "DO YOU WANT ANOTHER YEAR "; A$
  125.     A$ = UCASE$(A$)
  126.    
  127.     SELECT CASE A$
  128.           CASE "Y", "YES"
  129.                 PRINT
  130.                 GOTO RETRIEVE_YEAR
  131.           CASE "N", "NO"
  132.                 GOTO endPROG
  133.           CASE ELSE
  134.                 PRINT "INVALID ANSWER"
  135.                 PRINT
  136.                 GOTO ENDPROCESS
  137.     END SELECT
  138.  
  139. endPROG:
  140.     PRINT: PRINT
  141.     PRINT "Thanks for using the EASTER SUNDAY date program."
  142.     END
  143.  
  144. '*************************************************************************************
  145. '*** SUBROUTINES AND FUNCTIONS
  146. '
  147.  
  148.  
  149. SUB PAUSE STATIC
  150. ' =============================== PAUSE ================================
  151. '   The Pause subprogram simply creates a pause in the action until the
  152. '       user presses a key at the keyboard
  153. ' ======================================================================
  154.  
  155.     DO
  156.         InChar$ = INKEY$
  157.     LOOP UNTIL InChar$ <> ""
  158.  
  159.  
  160.    
  161. FUNCTION showAbout (Version)
  162. '*************************************************************************************
  163. ' Shows different About alerts when the program calls it with a parameter.
  164.  
  165.     SELECT CASE Version
  166.           CASE 1
  167.                 about$ = "" + CHR$(10) + "THIS PROGRAM CALCULATES THE DATE"
  168.                 about$ = about$ + CHR$(10) + "OF EASTER SUNDAY FOR ANY YEAR"
  169.                 about$ = about$ + CHR$(10) + "AFTER 1582."
  170.                 about$ = about$ + CHR$(10) + CHR$(10) + "THE PROCESS TO CALULATE EASTER WAS"
  171.                 about$ = about$ + CHR$(10) + "BASED ON AN ADAPTATION OF:"
  172.                 about$ = about$ + CHR$(10) + "    THE WEBB ALGORITHM"
  173.                 about$ = about$ + CHR$(10) + CHR$(10) + "PRESS [OK] TO CONTINUE "
  174.                 PRINT about$
  175.           CASE 2
  176.                 about$ = "" + CHR$(10) + "AN ASTRONOMY PROGRAM"
  177.                 about$ = about$ + CHR$(10) + CHR$(10) + "EASTER SUNDAY"
  178.                 about$ = about$ + CHR$(10) + " _______________"
  179.                 about$ = about$ + CHR$(10) + CHR$(10) + "BY ERIC BURGESS F.R.A.S."
  180.                 about$ = about$ + CHR$(10) + "ORIGINAL CODE: NOVEMBER 1984"
  181.                 about$ = about$ + CHR$(10) + "FROM THE BOOK 'CELESTIAL BASIC' BY ERIC BURGESS (REVISED IN 1985)"
  182.                 about$ = about$ + CHR$(10) + "ALL RIGHTS RESERVED BY"
  183.                 about$ = about$ + CHR$(10) + "S+T SOFTWARE SERVICES"
  184.                 about$ = about$ + CHR$(10) + "A DIVISION OF"
  185.                 about$ = about$ + CHR$(10) + "AMERICAN ONLY. INC."
  186.                 about$ = about$ + CHR$(10) + CHR$(10) + "MODIFIED BY GEORGE MCGINN FOR TECHBASIC/QB64"
  187.                 about$ = about$ + CHR$(10) + "MODIFIED CODE: SEPTEMBER 2020 + MARCH 2021"
  188.                 about$ = about$ + CHR$(10) + CHR$(10) + "PRESS [OK] TO CONTINUE "
  189.                 PRINT about$
  190.     END SELECT
  191.    
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Phases of the moon - query
« Reply #9 on: September 11, 2021, 11:10:27 am »
Fun fact. I was actually born on an Easter Sunday...

J
Logic is the beginning of wisdom.

Offline Cobalt

  • QB64 Developer
  • Forum Resident
  • Posts: 878
  • At 60 I become highly radioactive!
    • View Profile
Re: Phases of the moon - query
« Reply #10 on: September 11, 2021, 11:59:54 am »
To find Easter for the years 2000 to 2099 (which is all I figured my calendar needed), it’s as simple as:

ahh, but I wanted to know just what day the first Easter fell upon! XD
Granted after becoming radioactive I only have a half-life!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Phases of the moon - query
« Reply #11 on: September 11, 2021, 12:44:44 pm »
Quote
ahh, but I wanted to know just what day the first Easter fell upon! XD

More fun facts from professor Google:
Quote
The naming of the celebration as "Easter" seems to go back to the name of a pre-Christian goddess in England, Eostre, who was celebrated at beginning of spring. The only reference to this goddess comes from the writings of the Venerable Bede, a British monk who lived in the late seventh and early eighth century.

Quote
What is the root meaning of the word Easter?
Old English Easterdæg, from Eastre (Northumbrian Eostre), from Proto-Germanic *austron-, "dawn," also the name of a goddess of fertility and spring, perhaps originally of sunrise, whose feast was celebrated at the spring equinox, from *aust- "east, toward the sunrise" (compare east), from PIE root *aus- (1) "to shine,"


Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Phases of the moon - query
« Reply #12 on: September 11, 2021, 04:50:46 pm »
Questions like these remind me of the weather rock.

1) find a big rock and paint a W on it.  Doesn't matter what color.
2) if the rock is wet "It's raining."
3) if the rock is cold "It's cold outside."
4) if the rock is hot to the touch.  "It's hot outside."
5) if you can't find the rock.  "It's windy outside."

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Phases of the moon - query
« Reply #13 on: September 12, 2021, 04:40:46 pm »
ahh, but I wanted to know just what day the first Easter fell upon! XD

Cobalt.

That could be tricky for a couple of reasons. The world, as a whole, had adapted the Gregorian Calendar as of 1582. Before then we had a length of year of about 375 days. "Oh. But what about using Julian days?", you may ask. If memory serves correctly, Julian days are measured from the start of an epoch (usually data recorded at a specific point in time. Usually at the beginning of a Century).

Determining events based on Pre-Gregorian (Julian) could be inaccurate... after all, from the second to the 16th century, most scholars were using a geocentric system (everything rotated around the Earth).

But that being said, calculating the day of the 'first' Easter may not be possible. Easter was a pagan festival that pre-dated the Christian religion. There are many symbols adopted by many cultures. Easter has roots in a Spring festival to the godess Eostre and the Jewish holiday of Passover. Records show that Christians adopted and observed, the current form of Easter, as early as the second century AD. But parts of it may have had its roots as far back as the first century AD.

My apologies for 'babbling'... I really must concentrate on brevity...

Logic is the beginning of wisdom.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Phases of the moon - query
« Reply #14 on: September 12, 2021, 05:10:26 pm »
Cobalt.

That could be tricky for a couple of reasons. The world, as a whole, had adapted the Gregorian Calendar as of 1582. Before then we had a length of year of about 375 days. "Oh. But what about using Julian days?", you may ask. If memory serves correctly, Julian days are measured from the start of an epoch (usually data recorded at a specific point in time. Usually at the beginning of a Century).

Determining events based on Pre-Gregorian (Julian) could be inaccurate... after all, from the second to the 16th century, most scholars were using a geocentric system (everything rotated around the Earth).

But that being said, calculating the day of the 'first' Easter may not be possible. Easter was a pagan festival that pre-dated the Christian religion. There are many symbols adopted by many cultures. Easter has roots in a Spring festival to the godess Eostre and the Jewish holiday of Passover. Records show that Christians adopted and observed, the current form of Easter, as early as the second century AD. But parts of it may have had its roots as far back as the first century AD.

My apologies for 'babbling'... I really must concentrate on brevity...

J

“Official Easter” was established in 325AD when Emperor Constantine met with other church leaders and together they decreed that Easter would fall on the first Sunday after the first full moon after the spring equinox.

I guess if you want “first Easter”, you’d see when that occured for the first time after that decree.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!