コード例 #1
0
/**
 * Converts decimal degrees into a given format
 *
 * @param   float       $degrees The decimal degrees
 * @param   string      $format  The format: DMS, HMS, MOD360, NONE, RADIANS, default = NONE
 * @param   bool        $mod360  True to convert degrees to a value between 0 and 360 degrees before formating,
 *                               false otherwise, default = false
 * @return  float|array          The degrees expressed in the given format
 * @returns int         0        The degrees or the hours
 * @returns int         1        The minutes
 * @returns float       2        The seconds
 * @returns bool        3        True if positive, false if negative
 */
function aa_degrees_to_format($degrees, $format = null, $mod360 = false)
{
    if ($mod360) {
        $degrees = aa_degrees_to_mod360($degrees);
    }
    switch ($format) {
        case 'DMS':
        case 'dms':
            $degrees = aa_degrees_to_dms($degrees);
            break;
        case 'HMS':
        case 'hms':
            $degrees = aa_degrees_to_hms($degrees);
            break;
        case 'MOD360':
        case 'mod360':
            $degrees = aa_degrees_to_mod360($degrees);
            break;
        case 'NONE':
        case null:
            // passthru, no formatting
            break;
        case 'RADIANS':
        case 'radians':
            $degrees = deg2rad($degrees);
            break;
        default:
            aa_set_error('Invalid format.');
            return false;
    }
    return $degrees;
}
/**
 * Calculates the Julian day of a date in the Julian calendar
 *
 * This algorithm is invalid for negative Julian days.
 *
 * @param  int      $year  The year, for example: 2000, -1000, 0
 * @param  int      $month The month, from 1 to 12
 * @param  float    $day   The day, from 1 to 31, or with decimals
 * @return int|bool        The Julian day, or false on error
 */
function aa_julian_date_to_julian_day($year, $month, $day)
{
    if ($month <= 2) {
        $year--;
        $month += 12;
    }
    $julian_day = aa_int(365.25 * ($year + 4716)) + aa_int(30.6001 * ($month + 1)) + $day - 1524.5;
    if ($julian_day < 0) {
        aa_set_error('This algorithm is invalid for negative Julian days.');
        return false;
    }
    return $julian_day;
}
コード例 #3
0
/**
 * Adds a number of days to a date
 *
 * The calendar in which the date falls is automatically detected.
 * This algorithm is invalid for negative Julian days.
 *
 * @param   int        $year        The year, for example: 2000, -1000, 0
 * @param   int        $month       The month, from 1 to 12
 * @param   float      $day         The day, from 1 to 31, or with decimals
 * @param   float      $days_to_add The number of days to add,  example: 1, 2, -1, -2, -1.25, 1.5
 * @return  array|bool              The new year or false on error
 * @returns int        0            The year
 * @returns int        1            The month
 * @returns float      2            The day
 */
function aa_add_days_to_date($year, $month, $day, $days_to_add)
{
    $julian_day = aa_date_to_julian_day($year, $month, $day);
    if ($julian_day === false) {
        return false;
    }
    $julian_day += $days_to_add;
    if ($julian_day < 0) {
        aa_set_error('This algorithm is invalid for negative Julian days.');
        return false;
    }
    $new_date = aa_julian_day_to_date($julian_day);
    return $new_date;
}
コード例 #4
0
/**
 * Sets the Earth ellipsoid
 *
 * @param string       $earth_ellipsoid The new Earth ellipsoid, default = WGS-1984
 * @return string|bool                  False if the ellipsoid is invalid, the previous Earth ellipsoid otherwise
 */
function aa_set_earth_ellipsoid($earth_ellipsoid = null)
{
    global $_aa_earth_ellipsoid;
    global $_aa_earth_ellipsoids;
    $previous_earth_ellipsoid = $_aa_earth_ellipsoid;
    if (is_null($earth_ellipsoid)) {
        $earth_ellipsoid = EARTH_ELLIPSOID;
    } else {
        if (!isset($_aa_earth_ellipsoids[$earth_ellipsoid])) {
            aa_set_error('Invalid ellipsoid.');
            return false;
        }
    }
    $_aa_earth_ellipsoid = $earth_ellipsoid;
    return $previous_earth_ellipsoid;
}
コード例 #5
0
/**
 * Returns the list of algorithms
 *
 * @param  string  $type The type of list: "algorithms", "categories", "both"
 * @return array         The list of the algorithms
 */
function aa_get_algorithms($type = null)
{
    global $_aa_algorithms;
    global $_aa_algorithm_categories;
    global $_aa_algorithms_by_category;
    is_null($type) and $type = 'algorithms';
    switch ($type) {
        case 'algorithms':
            return $_aa_algorithms;
        case 'categories':
            return $_aa_algorithm_categories;
        case 'both':
            return $_aa_algorithms_by_category;
        default:
            aa_set_error('Type of list invalid.');
            return false;
    }
}
コード例 #6
0
/**
 * Calculates the date from a Julian day
 *
 * The calendar in which the date falls is automatically detected.
 * This algorithm is invalid for negative Julian days.
 *
 * @param   int        $julian_day The Julian day
 * @return  array|bool             The date or false on error
 * @returns int        0           The year
 * @returns int        1           The month
 * @returns float      2           The day
 */
function aa_julian_day_to_date($julian_day)
{
    if ($julian_day < 0) {
        aa_set_error('This algorithm is invalid for negative Julian days.');
        return false;
    }
    $julian_day += 0.5;
    $Z = aa_int($julian_day);
    $F = $julian_day - $Z;
    // fixes Meeus original algorithm (p. 63) to calculate the Julian day of the change of calendar
    // the value of 2299161 is the Julian day for 1582-10-15 in the Gregorian calendar + 0.5
    // 1582-10-15 is the default first day of the Gregorian calendar
    list($change_year, $change_month, $change_day) = aa_get_calendar_change_date();
    $change_julian_day = aa_gregorian_date_to_julian_day($change_year, $change_month, $change_day);
    $change_julian_day += 0.5;
    if ($Z < $change_julian_day) {
        $A = $Z;
    } else {
        $alpha = aa_int(($Z - 1867216.25) / 36524.25);
        $A = $Z + 1 + $alpha - aa_int($alpha / 4);
    }
    $B = $A + 1524;
    $C = aa_int(($B - 122.1) / 365.25);
    $D = aa_int(365.25 * $C);
    $E = aa_int(($B - $D) / 30.6001);
    $day = $B - $D - aa_int(30.6001 * $E) + $F;
    if ($E < 14) {
        $month = $E - 1;
    } else {
        if ($E == 14 or $E == 15) {
            $month = $E - 13;
        } else {
            aa_set_error('The calculated value of the month is out of range.');
            return false;
        }
    }
    if ($month > 2) {
        $year = $C - 4716;
    } else {
        $year = $C - 4715;
    }
    return array($year, $month, $day);
}
コード例 #7
0
/**
 * Converts seconds of arc into a given format
 *
 * @param   float       $seconds The seconds of arc
 * @param   string      $format  The format: DEGREES, RADIANS, default = null or SECONDS (passthru)
 * @return  float|array          The degrees expressed in the given format
 */
function aa_seconds_to_format($seconds, $format = null)
{
    switch ($format) {
        case 'DEGREES':
        case 'degrees':
            $degrees = $seconds / 3600;
            break;
        case 'RADIANS':
        case 'radians':
            $degrees = deg2rad($seconds / 3600);
            break;
        case 'SECONDS':
        case 'seconds':
        case null:
            // passthru
            $degrees = $seconds;
            break;
        default:
            aa_set_error('Invalid format.');
            return false;
    }
    return $degrees;
}