Java tutorial
//package com.java2s; public class Main { /** * Calculate the apparent longitude of the sun. * * @param t number of Julian centuries since J2000. * @return Sun's apparent longitude in degrees. */ private static double sunApparentLongitude(final double t) { final double omega = Math.toRadians(125.04 - 1934.136 * t); return sunTrueLongitude(t) - 0.00569 - 0.00478 * Math.sin(omega); } /** * Calculate the true longitude of the sun. This the geometric mean * longitude plus a correction factor ("equation of center" for the * sun). * * @param t number of Julian centuries since J2000. * @return Sun's true longitude in degrees. */ private static double sunTrueLongitude(final double t) { return sunGeometricMeanLongitude(t) + sunEquationOfCenter(t); } /** * Calculate the Geometric Mean Longitude of the Sun. * This value is close to 0 degree at the spring equinox, * 90 degree at the summer solstice, 180 degree at the automne equinox * and 270 degree at the winter solstice. * * @param t number of Julian centuries since J2000. * @return Geometric Mean Longitude of the Sun in degrees, * in the range 0 degree (inclusive) to 360 degree (exclusive). */ private static double sunGeometricMeanLongitude(final double t) { double L0 = 280.46646 + t * (36000.76983 + 0.0003032 * t); L0 = L0 - 360 * Math.floor(L0 / 360); return L0; } /** * Calculate the equation of center for the sun. This value is a correction * to add to the geometric mean longitude in order to get the "true" longitude * of the sun. * * @param t number of Julian centuries since J2000. * @return Equation of center in degrees. */ private static double sunEquationOfCenter(final double t) { final double m = Math.toRadians(sunGeometricMeanAnomaly(t)); return Math.sin(1 * m) * (1.914602 - t * (0.004817 + 0.000014 * t)) + Math.sin(2 * m) * (0.019993 - t * (0.000101)) + Math.sin(3 * m) * (0.000289); } /** * Calculate the Geometric Mean Anomaly of the Sun. * * @param t number of Julian centuries since J2000. * @return Geometric Mean Anomaly of the Sun in degrees. */ private static double sunGeometricMeanAnomaly(final double t) { return 357.52911 + t * (35999.05029 - 0.0001537 * t); } }