From 352b4ec651cca7ed9335a4901865e92680e80643 Mon Sep 17 00:00:00 2001 From: claire Date: Fri, 24 Mar 2023 11:01:58 -0700 Subject: [PATCH] clarified details on calculating moon phase --- Home.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Home.md b/Home.md index cace273..ef391f6 100644 --- a/Home.md +++ b/Home.md @@ -316,13 +316,12 @@ I can't take credit for figuring out the math on this. I was lucky to find [this Here's the overview: -1. Use the lunar cycle constant `29.53058770576` and calculate its duration in seconds as `lunarDays`. -2. Convert date of first full moon in 2000 (January 6 at 18:14 UTC) to unix timestamp as `lunarSecs`. -3. Calculate `totalSecs` which is the time (in seconds) between the user date and `lunarDays`. -4. If the result is positive, it's valid, so calculate the modulus (remainder) of `totalSecs` divided by `lunarSecs`, which will return the total seconds that have passed in the current cycle as `currSecs`. -5. Divide `currSecs` by `lunarSecs` to find the current position in the lunar cycle as `currentFrac`. -6. Multiply `currFrac` by `lunarDays` to get this value in days as `currDays`. -7. Find the correct moon phase based on the value of `currDays`. +1. Use the lunar cycle constant `29.53058770576` (`LunarDays`), and calculate its duration in seconds as `lunarSecs`. +2. Calculate the time (in seconds) between the user date and `lunarSecs` as `totalSecs`. +3. If the result is positive, it's valid, so calculate the modulus (remainder) of `totalSecs` divided by `lunarSecs`, which will return the total seconds that have passed in the current cycle as `currSecs`. +4. Divide `currSecs` by `lunarSecs` to find the current position in the lunar cycle as `currentFrac`. +5. Multiply `currFrac` by `lunarDays` to get this value in days as `currDays`. +6. Find the correct moon phase based on the value of `currDays`. This is all just basic arithmetic, so let's get into the Swift implementation.