ironfelix717
Registered User.
- Local time
- Yesterday, 19:49
- Joined
- Sep 20, 2019
- Messages
- 193
I am not an astronomer. Nor is this discussion point a matter of Access VBA, as much as it is an astronomy/science discussion.
I set out today to implement a simple way of calculating the moon phase (percent of illumination, 100% = full moon).
Originally, I found a PHP script here:
calculating-moon-phase
Re-wrote it in VBA. Cool. Until i checked the accuracy compared to the original authors calculator (matches) and then to various web calculators out there. That script was off. By quite a bit. Trashed that. And decided to just learn the math behind calculating the moon phases.
I wasn't looking for "NASA Level Accuracy", simply, the ability to get the date when a full moon is present within accuracy of +/- 12 hours.
I then found this resource to learn how to calculate the new moon age. Turns out its actually quite easy.
https://www.subsystems.us moonphase.pdf
So, I followed their example. Built a script. And wah-lah. Doesn't match. Granted, I used a different "Base Line" date (i'm not going back to B.C.). The date I used for a new moon baseline is 1-6-2000 (see script below). The result for moon age (period age) should be the same. Not way off from their example. Perhaps I have an error somewhere. Doesn't look like it. Could be a date conversion or something.
Regardless, the PDF example's result does not match any of the calculators im basing my results on. I trust the web calculators more than this PDF by far.
https://www.almanac.com/astronomy/moon/calendar/MN/Minneapolis/2000-01
http://www.astronomyknowhow.com/month-percentage.php
In short, I find that you cannot actually calculate this with a simple math formula like the PDF and other's who have attempted this claim. There are either other astronomical or time factors that influence this. Its not feasible to get the accuracy that I request. If you believe i'm wrong, I welcome you to prove that
Best regards
I set out today to implement a simple way of calculating the moon phase (percent of illumination, 100% = full moon).
Originally, I found a PHP script here:
calculating-moon-phase
Re-wrote it in VBA. Cool. Until i checked the accuracy compared to the original authors calculator (matches) and then to various web calculators out there. That script was off. By quite a bit. Trashed that. And decided to just learn the math behind calculating the moon phases.
I wasn't looking for "NASA Level Accuracy", simply, the ability to get the date when a full moon is present within accuracy of +/- 12 hours.
I then found this resource to learn how to calculate the new moon age. Turns out its actually quite easy.
https://www.subsystems.us moonphase.pdf
So, I followed their example. Built a script. And wah-lah. Doesn't match. Granted, I used a different "Base Line" date (i'm not going back to B.C.). The date I used for a new moon baseline is 1-6-2000 (see script below). The result for moon age (period age) should be the same. Not way off from their example. Perhaps I have an error somewhere. Doesn't look like it. Could be a date conversion or something.
Regardless, the PDF example's result does not match any of the calculators im basing my results on. I trust the web calculators more than this PDF by far.
https://www.almanac.com/astronomy/moon/calendar/MN/Minneapolis/2000-01
http://www.astronomyknowhow.com/month-percentage.php
In short, I find that you cannot actually calculate this with a simple math formula like the PDF and other's who have attempted this claim. There are either other astronomical or time factors that influence this. Its not feasible to get the accuracy that I request. If you believe i'm wrong, I welcome you to prove that
Best regards
Code:
Function MoonPhase(Target As Date) As String
Dim BaseLine As Date
Dim SinceBase As Long
Dim PeriodDays As Long
Dim MoonAge As Double
Dim MoonCycles As Double
Dim remainder As Double
BaseLine = "1-6-2000" 'first new moon of year 200, arbitrary baseline date of a new moon.
SinceBase = Abs(DateDiff("d", BaseLine, Target)) + 2 'days since baseline date
'days in a period of full moon
PeriodDays = 29.53058
'# of mooncycles that occurred between the target and baseline
MoonCycles = SinceBase / PeriodDays
'Calculate the remainder of the fraction
'mod function is trash and doesn't actually give a remainder today?
'MoonCycles = SinceBase Mod PeriodSeconds
remainder = "." & Split(CStr(MoonCycles), ".")(1)
'calculate age (days) of the remainder:
MoonAge = remainder * 29.53058
Debug.Print MoonAge
End Function