## PHP: some method of determining the sun’s longitude – part 2 In the previous part, we know 3 method to determine the sun’s longitude base on the time.

Now, we offer more an method to do this.

We search on the book Explanatory Supplement to the Astronomical Almanac, it had equations for roughly calculating the position of the sun relative to the earth for any day within two hundred years of the latest epoch, the year 2000.

To do so, we start with the Julian Date of the day in question, JD.
From that, we’d like to calculate where in it’s ecliptic, the Sun is. This measurement is called λ.

λ = L + 1.915 sin G + 0.020 sin 2 G

Where L is the mean longitude corrected for aberration, and G is the mean anomaly.

L = 280.460 + 36000.770 T
G = 357.528 + 35999.050 T

T is the number of centuries since the epoch. Along with T, there’s only one other number we need to calculate, ε, the obliquity of the ecliptic.

T = JD – 2451545.0 / 36525

Now, we start the code:

function SunLongitude4($year,$month, $day,$hour, $min,$sec, $timeZone) {$jdn = gregoriantojd($month,$day, $year) + ($hour + $min / 60 +$sec / 3600) / 24;
$T = ($jdn - 2451545.5 - $timeZone / 24) / 36525; // Time in Julian centuries from 2000-01-01 12:00:00 GMT$dr = M_PI / 180; // degree to radian
$L = 280.460 + 36000.770 *$T; //  degree
$G = 357.528 + 35999.050 *$T; //  degree
$ec = 1.915 * sin($dr *$G) + 0.020 * sin($dr *2*$G);$lambda = $L +$ec ;// true longitude, degree

return $L =$lambda - 360 * (floor(\$lambda / (360))); // Normalize to (0, 360)
}

Example:
We can see in the website: http://www.usno.navy.mil/USNO/astronomical-applications/data-services/earth-seasons, at 03-20-2015 22:45 GMT, longitude of the sun is zero:

echo SunLongitude4(2015, 3, 20, 22, 45, 00, 0); //0.00324064046345 ~ 12''

So, the precision of the fourth method is the best.