Treffynnon\Navigator\Distance\Calculator\CosineLaw::calculate PHP Method

calculate() public method

Supply instances of the coordinate class. http://en.wikipedia.org/wiki/Cosine_law
public calculate ( Treffynnon\Navigator\LatLong $point1, Treffynnon\Navigator\LatLong $point2 ) : float
$point1 Treffynnon\Navigator\LatLong
$point2 Treffynnon\Navigator\LatLong
return float
    public function calculate(N\LatLong $point1, N\LatLong $point2)
    {
        $celestialBody = $this->getCelestialBody();
        $d = acos(sin($point1->getLatitude()->get()) * sin($point2->getLatitude()->get()) + cos($point1->getLatitude()->get()) * cos($point2->getLatitude()->get()) * cos($point2->getLongitude()->get() - $point1->getLongitude()->get())) * $celestialBody->volumetricMeanRadius;
        return $d * 1000;
    }

Usage Example

 /**
  * @dataProvider cosineLawDataProvider 
  */
 public function testCosineLawCalculate($lat1, $long1, $lat2, $long2, $expected_result)
 {
     $CosineLaw = new C\CosineLaw($this->getObject());
     $point1 = new N\LatLong(new N\Coordinate($lat1), new N\Coordinate($long1));
     $point2 = new N\LatLong(new N\Coordinate($lat2), new N\Coordinate($long2));
     $metres = $CosineLaw->calculate($point1, $point2);
     $this->assertEquals($expected_result, $metres, '', 0.2);
 }
All Usage Examples Of Treffynnon\Navigator\Distance\Calculator\CosineLaw::calculate
CosineLaw