fixed details of lunar phase calculation

master
Claire 1 year ago
parent
commit
70558d902c
  1. 11
      Home.md

11
Home.md

@ -317,11 +317,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` (`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`.
2. Convert date of first full moon in 2000 (January 6 at 18:14 UTC) to unix timestamp as `baseDate`.
3. Calculate the time (in seconds) between the user date and `baseDate` as `totalSecs`.
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`.
This is all just basic arithmetic, so let's get into the Swift implementation.

Loading…
Cancel
Save