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

Moon Positions are Off #102

Open
aemkei opened this issue Jul 12, 2017 · 5 comments
Open

Moon Positions are Off #102

aemkei opened this issue Jul 12, 2017 · 5 comments

Comments

@aemkei
Copy link

aemkei commented Jul 12, 2017

I really love this library!

Unfortunately the #getMoonPosition method is returning wrong values.

Note: I'd love to use it for some eclipse visualizations, but so fare I couldn't get the right values.

Take Hopkinsville as an example (the point with the maximum eclipse): https://www.timeanddate.com/eclipse/in/usa/hopkinsville?iso=20170821

  • Time: 13:25
  • Position: 36.8656, -87.4886

The moon and sun position should both be 64° (altitude) and 198° (azimuth).

These are also the values calculated at suncalc.org and mooncalc.org.

But If you pass these values to suncalc.js, we got this:

const lat = 36.8656;
const lng = -87.4886;
const dateTime = new Date("2017-08-21T13:25:00-05:00");
const sun = SunCalc.getPosition(dateTime, lat, lng);
const moon = SunCalc.getMoonPosition(dateTime, lat, lng);

function toDegree(radians) {
  return radians * 180 / Math.PI;
}

var values = {
  sun: {
    azimuth: 180 + toDegree(sun.azimuth),
    altitude: toDegree(sun.altitude)
  },
  moon: {
    azimuth: 180 + toDegree(moon.azimuth),
    altitude: toDegree(moon.altitude)
  }
};

console.log(values);

Logs:

{
  "sun": {
    "azimuth": 197.79,
    "altitude": 64.12
  },
  "moon": {
    "azimuth": 195.05,
    "altitude": 64.01
  }
}
@aemkei
Copy link
Author

aemkei commented Jul 12, 2017

Playing a bit with the values… Looks like position of moon and sun will match ~2 hours earlier:

...
const dateTime = new Date("2017-08-21T13:25:00-05:00");
...

But the values are still way off to the original.

@mourner mourner added the bug label Jul 12, 2017
@aemkei
Copy link
Author

aemkei commented Jul 13, 2017

Note: had to update the code above to use North as 0° azimuth.

PS: Values from @Fabiz Meeus are more precise.

sun azi:198.1004, alt:63.9873
moon azi:198.1186, alt:63.989

@aoizoijoizj
Copy link

aoizoijoizj commented Jul 13, 2017

Also test this in your example
console.log(moon.distance)
It should be 372107 km
In suncalc it is 375556 km
It's a big difference!

@mourner
Copy link
Owner

mourner commented Jul 14, 2017

@aemkei hey, I don't have enough bandwidth to look into the mismatches now, but I'd suggest using Meeus for precision. Meeus formulas are known to be more precise than what I've used — in fact I even started poking around rewriting this library with these formulas (see meeus branch). Will get to it some day.

@aemkei
Copy link
Author

aemkei commented Jul 17, 2017

Okay, thanks for the comment! Switching to Meeus was not that hard because the interface is quite similar. I still prefer the structure and source of Suncalc and will definitely come back once that formulas were updated.

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

No branches or pull requests

3 participants