Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Wanted] Moon Phase computation #1

Open
MathieuNls opened this issue Jul 19, 2016 · 1 comment
Open

[Help Wanted] Moon Phase computation #1

MathieuNls opened this issue Jul 19, 2016 · 1 comment

Comments

@MathieuNls
Copy link

MathieuNls commented Jul 19, 2016

Hi,

First of all, thanks for your library. I am not exploring yet, but it's definitively quite something !

Using your library, I am trying to reproduce the following moon phase indicator : http://www.patek.com/en/collection/movements-complications/moonphase-indicator

For now, I've something like this:

    this.illum = this.getMoonIllumination(new Date());
    this.pos = this.getMoonPosition(new Date(), 0, 0);
    this.angleMoon = this.illum.angle - this.pos.parallacticAngle;

Which gives me the actual moon position at Date() rather than the moon phase.

I've tried to adapt the calculation so they match this code by Xavier Jubier, without success:

/**
 * The following code is
 * Adapted from http://xjubier.free.fr/en/site_pages/LunarEclipseCalculator.html
 * Copyright Xavier Jubier
 */
var myPhaseName = "";
var forecastImage = new Array();

function moonPhasePercent(theDate)
{
  var synodic = 29.53058867;
  var msPerDay = 86400000;
  var baseDate = new Date();
  baseDate.setUTCFullYear(2005);
  baseDate.setUTCMonth(4);
  baseDate.setUTCDate(8);
  baseDate.setUTCHours(8);
  baseDate.setUTCMinutes(48);

  var diff = theDate - baseDate;
  var phase = diff / (synodic * msPerDay);
  phase *= 100;
  phase %= 100;
  if ( phase < 0 )
    phase += 100;

  return(phase);
}

function getMoonPhase()
{

  var theDate = new Date();

  var phasePercent = moonPhasePercent(theDate);

  var phaseNames = [
    "New Moon", "New Moon",
    "Waxing Crescent", "Waxing Crescent", "Waxing Crescent", "Waxing Crescent",
    "First Quarter", "First Quarter", "First Quarter",
    "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous",
    "Full Moon", "Full Moon",
    "Waning Gibbous", "Waning Gibbous", "Waning Gibbous", "Waning Gibbous",
    "Last Quarter", "Last Quarter", "Last Quarter",
    "Waning Crescent", "Waning Crescent", "Waning Crescent", "Waning Crescent",
    "New Moon"
  ];

  thePhase = Math.round(phasePercent * 0.279);
  myPhaseName = phaseNames[thePhase];

  return thePhase;
}

Thanks,
M.

@slowe
Copy link
Owner

slowe commented Aug 21, 2016

@MathieuNls It is four years or so since I made this but I don't remember this library including a calculation of the phase of the Moon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants