PHP code example of theriftlab / radiance

1. Go to this page and download the library: Download theriftlab/radiance 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/ */

    

theriftlab / radiance example snippets


use RiftLab\Radiance\Angle;

$angle = Angle::make(-51.477928);

echo $angle;
// Output: -51°28'41"

$angle2 = Angle::make('10°');

echo $angle->distanceTo($angle2);
// Output: 61°28'41"
echo $angle->distanceFrom($angle2);
// Output: -61°28'41"
echo $angle2->distanceTo($angle);
// Output: -61°28'41"
echo $angle->distanceTo(10);
// Output: 61°28'41"

echo $angle->add($angle2);
// Output: -41°28'41"
echo $angle->add(10);
// Output: -41°28'41"
echo $angle->sub($angle2);
// Output: -61°28'41"
echo $angle->sub(10);
// Output: -61°28'41"
echo $angle->add($angle2)->distanceTo($angle);
// Output: -10°00'00"

echo Angle::make(350)->midpointWith(20);
// Output: 05°00'00

// These will all produce identical objects:
$angle1 = Angle::make(-51.477928);
$angle2 = Angle::make('-51°28\'40.5408"');
$angle3 = Angle::make('51°28\'40.5408"W');
$angle4 = Angle::make('51w28\'40.5408');
$angle5 = Angle::make('51s28.67568');

var_dump($angle1 == $angle2);
// Output: bool(true)
var_dump($angle2 == $angle3);
// Output: bool(true)
// ..etc.

$lat = Latitude::make(-51.477928);
echo $lat;
// Output: 51s28.68

echo $lat->add(60);
// Output: 8n31.32

echo $lat->midpointWith(10);
// Output: 20s44.34

echo $lat->sub(40);
// Below -90°: LatitudeBoundaryError thrown

$dist = Angle::make(40);
echo $lat->sub($dist);
// LatitudeBoundaryError still thrown

echo Angle::make(-560);
// Output: -200°0'0"

$angle = Angle::make(-200);     // 160° on a circle

echo $angle;
// Output: -200°0'0"
echo $angle->distanceTo(140);   // 160° to 140°
// Output: -20°0'0"
echo $angle->distanceTo(180);   // 160° to 180°
// Output: 20°0'0"

$angle = Angle::make(-560);     // still 160°

echo $angle;
// Output: -200°0'0"
echo $angle->distanceTo(-220);  // 140° on a circle, so still 160° to 140°
// Output: -20°0'0"
echo $angle->distanceTo(-180);  // 180° on a circle, so still 160° to 180°
// Output: 20°0'0"

echo Angle::make(10)->distanceTo(30);
// Output: 20°00'00"

echo Latitude::make(10)->distanceTo(30);
// Output: 20n0.00

echo Longitude::make(10)->distanceTo(30);
// Output: 20e0.00