PHP code example of andrmoel / astronomy-bundle

1. Go to this page and download the library: Download andrmoel/astronomy-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

andrmoel / astronomy-bundle example snippets


$angleDec = 132.6029282;

$angle = AngleUtil::dec2angle($angleDec);
$time = AngleUtil::dec2time($angleDec);

$time = '8h50m24.703s';

$angle = AngleUtil::time2dec($time);

$toi = TimeOfInterest::createFromString('2017-07-02 13:37:00');

$JD = $toi->getJulianDay();
$JD0 = $toi->getJulianDay0();
$T = $toi->getJulianCenturiesFromJ2000();
$t = $toi->getJulianMillenniaFromJ2000();

$toi = TimeOfInterest::createFromString('1992-12-20 00:00:00');

$GMST = $toi->getGreenwichMeanSiderealTime();
$GAST = $toi->getGreenwichApparentSiderealTime();
$E = $toi->getEquationOfTime();

// Initialize Location object for Berlin
$location = Location::create(52.524, 13.411);

// Initialize Location with elevation (Mt. Everest)
$location = Location::create(27.98787, 86.92483, 8848);

$T = -0.12727429842574; // Julian Centuries since J2000 (1987-04-10 19:21:00)
$rightAscension = 116.328942;
$declination = 28.026183;

$geoEquSphCoord = new GeocentricEquatorialSphericalCoordinates($rightAscension, $declination);
$geoEclSphCoord = $geoEquSphCoord->getGeocentricEclipticalSphericalCoordinates($T);

$lon = $geoEclSphCoord->getLongitude();
$lat = $geoEclSphCoord->getLatitude();

$location = Location::create(38.921389, -77.065556); // Washington DC
$T = -0.12727429842574; // Julian Centuries since J2000 (1987-04-10 19:21:00)
$rightAscension = 347.3193375;
$declination = -6.719891667;

$geoEquSphCoord = new GeocentricEquatorialSphericalCoordinates($rightAscension, $declination);
$locHorCoord = $geoEquSphCoord->getLocalHorizontalCoordinates($location, $T);

$altitude = $locHorCoord->getAltitude();
$azimuth = $locHorCoord->getAzimuth();

$toi = TimeOfInterest::createFromString('2017-07-02 12:00:00');

$moon = Moon::create($toi);

$toi = TimeOfInterest::createFromString('2019-05-17 17:50');

$sun = Sun::create($toi);

$geoEclSphCoordinates = $sun->getGeocentricEclipticalSphericalCoordinates();
$lon = $geoEclSphCoordinates->getLongitude();
$lat = $geoEclSphCoordinates->getLatitude();

$toi = TimeOfInterest::createFromString('2019-05-17 17:50');

$location = Location::create(52.524, 13.411); // Berlin

$sun = Sun::create($toi);

$locHorCoord = $sun->getLocalHorizontalCoordinates($location);
$azimuth = $locHorCoord->getAzimuth();
$altitude = $locHorCoord->getAltitude();

$sun = Sun::create();

$distance = $sun->getDistanceToEarth();

$toi = TimeOfInterest::createFromString('2017-06-05 20:50');

$sun = Sun::create($toi);

$distance = $sun->getDistanceToEarth();

$toi = TimeOfInterest::createFromString('2019-05-17');

$location = Location::create(52.524, 13.411); // Berlin

$sun = Sun::create($toi);

// Results are TimeOfInterest objects
$sunrise = $sun->getSunrise($location);
$sunset = $sun->getSunset($location);
$upperCulmination = $sun->getUpperCulmination($location);

$toi = TimeOfInterest::createFromString('1992-04-12 00:00:00');

$moon = Moon::create($toi);

$geoEquSphCoord = $moon->getGeocentricEquatorialSphericalCoordinates();
$rightAscension = $geoEquSphCoord->getRightAscension();
$declination = $geoEquSphCoord->getDeclination();

$toi = TimeOfInterest::createFromString('2019-05-20 23:00:00');

$location = Location::create(52.524, 13.411); // Berlin

$moon = Moon::create($toi);

$locHorCoord = $moon->getLocalHorizontalCoordinates($location);
$azimuth = $locHorCoord->getAzimuth();
$altitude = $locHorCoord->getAltitude();

$moon = Moon::create();

$distance = $moon->getDistanceToEarth();

$toi = TimeOfInterest::createFromString('2017-06-05 20:50');

$moon = Moon::create($toi);

$distance = $moon->getDistanceToEarth();

$toi = TimeOfInterest::createFromString('2019-05-13 21:30:00');

$moon = Moon::create($toi);

$isWaxing = $moon->isWaxingMoon();
$illumination = $moon->getIlluminatedFraction();
$positionAngle = $moon->getPositionAngleOfMoonsBrightLimb();

$toi = TimeOfInterest::createFromString('2018-06-03 19:00:00');

$mercury = Mercury::create();  // Time = now
$venus = Venus::create($toi); // Time = 2018-06-03 19:00:00
$earth = Earth::create($toi);
$mars = Mars::create($toi);
$jupiter = Jupiter::create($toi);
$saturn = Saturn::create($toi);
$uranus = Uranus::create($toi);
$neptune = Neptune::create($toi);

$toi = TimeOfInterest::createFromString('1992-12-20 00:00:00');

$venus = Venus::create($toi);

$helEclSphCoord = $venus->getHeliocentricEclipticalSphericalCoordinates();
$lon = $helEclSphCoord->getLongitude();
$lat = $helEclSphCoord->getLatitude();
$r = $helEclSphCoord->getRadiusVector();

$helEclRecCoord = $venus->getHeliocentricEclipticalRectangularCoordinates();
$x = $helEclRecCoord->getX();
$y = $helEclRecCoord->getY();
$z = $helEclRecCoord->getZ();

$toi = TimeOfInterest::createFromString('2018-10-25 07:15:00');

$venus = Venus::create($toi);

$geoEclSphCoords = $venus->getGeocentricEclipticalSphericalCoordinates();
$lon = $geoEclSphCoords->getLongitude();
$lat = $geoEclSphCoords->getLatitude();

$geoEclSphCoords = $venus->getGeocentricEquatorialSphericalCoordinates();
$rightAscension = $geoEclSphCoords->getRightAscension();
$declination = $geoEclSphCoords->getDeclination();

$location = Location::create(52.524, 13.411); // Berlin

$toi = TimeOfInterest::createFromString('2018-10-25 07:15:00');

$venus = Venus::create($toi);

$locHorCoords = $venus->getLocalHorizontalCoordinates($location);
$azimuth = $locHorCoords->getAzimuth();
$altitude = $locHorCoords->getAltitude();

$location = Location::create(52.524, 13.411); // Berlin

$toi = TimeOfInterest::createFromString('2018-10-25 07:15:00');

$venus = Venus::create($toi);

// Results are TimeOfInterest objects
$rise = $venus->getRise($location);
$set = $venus->getSet($location);
$upperCulmination = $venus->getUpperCulmination($location);

$location = Location::create(44.61040, -121.23848); // Madras, OR

$toi = TimeOfInterest::createFromString('2017-08-21'); // Date of the eclipse (UTC)

$solarEclipse = SolarEclipse::create($toi, $location);

$location = Location::create(44.61040, -121.23848); // Madras, OR

$toi = TimeOfInterest::createFromString('2017-08-21'); // Date of the eclipse (UTC)

$solarEclipse = SolarEclipse::create($toi, $location);

$type = $solarEclipse->getEclipseType();
$duration = $solarEclipse->getEclipseDuration(); // in seconds
$durationTotality = $solarEclipse->getEclipseUmbraDuration(); // in seconds
$obscuration = $solarEclipse->getObscuration();
$magnitude = $solarEclipse->getMagnitude();
$moonSunRatio = $solarEclipse->getMoonSunRatio();

$location = Location::create(52.52, 13.405); // Berlin

$toi = TimeOfInterest::createFromString('2015-03-20'); // Date of the eclipse (UTC)

$solarEclipse = SolarEclipse::create($toi, $location);

$type = $solarEclipse->getEclipseType();
$duration = $solarEclipse->getEclipseDuration(); // in seconds
$durationTotality = $solarEclipse->getEclipseUmbraDuration(); // in seconds
$obscuration = $solarEclipse->getObscuration();
$magnitude = $solarEclipse->getMagnitude();
$moonSunRatio = $solarEclipse->getMoonSunRatio();

$location = Location::create(44.61040, -121.23848); // Madras, OR

$toi = TimeOfInterest::createFromString('2017-08-21'); // Date of the eclipse (UTC)

$solarEclipse = SolarEclipse::create($toi, $location);

$c1 = $solarEclipse->getCircumstancesC1();
$c2 = $solarEclipse->getCircumstancesC2();
$max = $solarEclipse->getCircumstancesMax();
$c3 = $solarEclipse->getCircumstancesC3();
$c4 = $solarEclipse->getCircumstancesC4();

$location = Location::create(44.61040, -121.23848); // Madras, OR

$toi = TimeOfInterest::createFromString('2017-08-21'); // Date of the eclipse (UTC)

$solarEclipse = SolarEclipse::create($toi, $location);

$c2 = $solarEclipse->getCircumstancesC2();

// Get time for C2
$toiC2 = $solarEclipse->getTimeOfInterest($c2);

// Get local horizontal coordinates (azimuth, altitude) of C2
$locHorCoord = $c2->getLocalHorizontalCoordinates();
$azimuth = $locHorCoord->getAzimuth();
$altitude = $locHorCoord->getAltitude();

$location1 = Location::create(52.524, 13.411); // Berlin
$location2 = Location::create(40.697,-74.539); // New York

$distance = EarthCalc::getDistanceBetweenLocations($location1, $location2);

$T = -0.127296372458;

$nutationLon = EarthCalc::getNutationInLongitude($T);
$nutationLon = AngleUtil::dec2angle($nutationLon);

$nutationObl = EarthCalc::getNutationInObliquity($T);
$nutationObl = AngleUtil::dec2angle($nutationObl);

php examples/sun.php

// Create from time
$toi = TimeOfInterest::create(2017, 7, 2, 15, 30, 0);
$toi = TimeOfInterest::createFromTime(2017, 7, 2, 15, 30, 0);

// Create from string
$toi = TimeOfInterest::createFromString('2017-07-02 15:30:00');

// Create from PHPs DateTime object
$dateTime = new \DateTime('2017-07-02 15:30:00');
$toi = TimeOfInterest::createFromDateTime($dateTime);

// Create from Julian Day
$JD = 2457937.1458333;
$toi = TimeOfInterest::createFromJulianDay($JD);

// Create from Julian Centuries since J2000
$T = 0.17500741501255;
$toi = TimeOfInterest::createFromJulianCenturiesJ2000($T);

echo $toi;

$toi = TimeOfInterest::createFromCurrentTime();

echo $toi;

$toi = TimeOfInterest::createFromCurrentTime();

$toi->setString('2017-07-02 15:30:00');

echo $toi;