Skip to content

Commit

Permalink
Interpolate shadow position based on time of quarters
Browse files Browse the repository at this point in the history
Previously assumed each quarter was 1/4 of the cycle. Which its not.
THis is not ideal either.
  • Loading branch information
wwjjbb committed Jul 14, 2017
1 parent 2f3bf40 commit 0f1e2a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
47 changes: 24 additions & 23 deletions package/contents/code/lunacalc.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,37 @@ function reloadPhases()
return getPhasesByLunation(lunation);
}

function getCurrentPhase() // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon)
function getCurrentPhase(interpolate) // this function assumes that today is between phases[0] (last new moon) and phases[4] (next new moon)
{

var oneDay = 1000 * 60 * 60 * 24;
var today = new Date().getTime();
var phases = getTodayPhases();

/* -------------------------------------------------------------------------
// Estimate where the terminator is - base this on knowing where it
// is at each quarter, and interpolating. Cowboy maths.
// Determines how far into the current quarter we are, and uses
// the result to work out where the terminator is. This allows for
// the quarters being different sizes, rather than assuming they are
// each one quarter of the cycle time.
var qnum = 0;
while (today > phases[qnum+1] && qnum < 3) {
qnum++;
var terminator;
if (interpolate) {
// Estimate where the terminator is - base this on knowing where it
// is at each quarter, and interpolating. Cowboy maths.
// Determines how far into the current quarter we are, and uses
// the result to work out where the terminator is. This allows for
// the quarters being different sizes, rather than assuming they are
// each one quarter of the cycle time.

var qnum = 0;
while (today > phases[qnum+1] && qnum < 3) {
qnum++;
}
var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime();
var sinceQuarter = today - phases[qnum].getTime();
terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90);
}
else {
// Work out where the terminator is, 0..359 degrees.
// This assumes a constant rate for the month, which is unlikely
var cycleTime = phases[4].getTime() - phases[0].getTime();
var sinceNew = today - phases[0].getTime();
terminator = Math.floor((sinceNew / cycleTime) * 360);
}
var quarterTime = phases[qnum+1].getTime() - phases[qnum].getTime();
var sinceQuarter = today - phases[qnum].getTime();
var terminator = Math.floor(((sinceQuarter / quarterTime) + qnum) * 90);
--------------------------------------------------------------------- */

// /*
// Work out where the terminator is, 0..359 degrees
var cycleTime = phases[4].getTime() - phases[0].getTime();
var sinceNew = today - phases[0].getTime();
var terminator = Math.floor((sinceNew / cycleTime) * 360);
// */

// Keep this in the range [0,360):
if (terminator >= 360) {
Expand Down
2 changes: 1 addition & 1 deletion package/contents/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Item {

function updateDetails() {
// set the correct image for the moon
currentPhase = LunaCalc.getCurrentPhase();
currentPhase = LunaCalc.getCurrentPhase(true);
lunaIcon.phaseNumber = 13; //currentPhase.number;
lunaIcon.theta = currentPhase.terminator;
lunaIcon.hemisphere = hemisphere;
Expand Down

0 comments on commit 0f1e2a3

Please sign in to comment.