suncalc icon indicating copy to clipboard operation
suncalc copied to clipboard

Const Distance between earth and sun

Open jindal12ketan opened this issue 1 year ago • 4 comments

`SunCalc.getMoonIllumination = function (date) {

var d = toDays(date || new Date()),
    s = sunCoords(d),
    m = moonCoords(d),

    sdist = 149598000, // distance from Earth to Sun in km

    phi = acos(sin(s.dec) * sin(m.dec) + cos(s.dec) * cos(m.dec) * cos(s.ra - m.ra)),
    inc = atan(sdist * sin(phi), m.dist - sdist * cos(phi)),
    angle = atan(cos(s.dec) * sin(s.ra - m.ra), sin(s.dec) * cos(m.dec) -
            cos(s.dec) * sin(m.dec) * cos(s.ra - m.ra));

return {
    fraction: (1 + cos(inc)) / 2,
    phase: 0.5 + 0.5 * inc * (angle < 0 ? -1 : 1) / Math.PI,
    angle: angle
};

};`

Why is the sdist constant, doesn't it change with date and time?

jindal12ketan avatar Apr 16 '24 18:04 jindal12ketan

This number is the distance of 1 AU (astronomical unit) in kilometers.

lulunac27a avatar Sep 12 '24 00:09 lulunac27a