Please enable JavaScript to view this site.

 

int = PlanetAtExtremalDistance(nDate, nSunSourceIndex, nPlanetID)

 

This macro function calculates the time, on nDate, when the planet of planetary index nPlanetID is closest to, or furthest away from, the Earth.

 

The allowed values for nPlanetID range from n_MERCURY to n_PLUTO, and also include n_SUN and n_MOON.

The sign of the result is positive if the planet is closest, and negative if the planet is furthest away on nDate. If the date nDate does not correspond to either case, then the function returns 0.

The absolute value of the result is the time of the day expressed in one millionth of a day (less than 1/10th of a second).

 

The macro code below checks if any of the planets, including Pluto, as well as the Moon and the Sun, are closest to the Earth, or furthest from the Earth, on the date of the incoming macro token, and displays the result using the terms specific to the Sun and Moon.

for nPlanetID = n_SUN to n_PLUTO step 1
    sBuffer = ''
    nCurResIdx = PlanetAtExtremalDistance(n_TokenDate, 1, nPlanetID)
    if nCurResIdx > 0
        switch nPlanetID
            case n_MOON
                sBuffer = PlanetName(nPlanetID) + ' at apogee'
            case n_SUN
                sBuffer = 'Earth at aphelion'
            else
                sBuffer = PlanetName(nPlanetID) + ' farthest from Earth'
        endswitch
    endif
    if nCurResIdx < 0
        switch nPlanetID
            case n_MOON
                sBuffer = 'Moon at perigee'
            case n_SUN
                sBuffer = 'Earth at perihelion'
            else
                sBuffer = PlanetName(nPlanetID) + ' closest to Earth'
        endswitch
    endif
    // add the time it occurs in parentheses
    if Abs(nCurResIdx) > 1
       sBuffer = sBuffer + FormatTime('" ("hh:nn")"', Abs(nCurResIdx), true)
    endif
endfor

See also: PlanetAtExtremalDistanceFromSun and planetary macro functions.

 


Topic 177595, last updated on 18-Apr-2020