Example #1
0
 public function forward($p)
 {
     //alert("ll2m coords : ".coords);
     $lon = $p->x;
     $lat = $p->y;
     // convert to radians
     if ($lat * Proj4php::$common->R2D > 90.0 && $lat * Proj4php::$common->R2D < -90.0 && $lon * Proj4php::$common->R2D > 180.0 && $lon * Proj4php::$common->R2D < -180.0) {
         Proj4php::reportError("merc:forward: llInputOutOfRange: " . $lon . " : " . $lat);
         return null;
     }
     if (abs(abs($lat) - Proj4php::$common->HALF_PI) <= Proj4php::$common->EPSLN) {
         Proj4php::reportError("merc:forward: ll2mAtPoles");
         return null;
     } else {
         if ($this->sphere) {
             $x = $this->x0 + $this->a * $this->k0 * Proj4php::$common->adjust_lon($lon - $this->long0);
             $y = $this->y0 + $this->a * $this->k0 * log(tan(Proj4php::$common->FORTPI + 0.5 * $lat));
         } else {
             $sinphi = sin(lat);
             $ts = Proj4php::$common->tsfnz($this->e, $lat, $sinphi);
             $x = $this->x0 + $this->a * $this->k0 * Proj4php::$common->adjust_lon($lon - $this->long0);
             $y = $this->y0 - $this->a * $this->k0 * log($ts);
         }
         $p->x = $x;
         $p->y = $y;
         return $p;
     }
 }
Example #2
0
 public function inverse($p)
 {
     $Y = $p->x - $this->x0;
     $X = $p->y - $this->y0;
     $rotI = $Y / $this->R;
     $rotB = 2 * (atan(exp(X / $this->R)) - Sourcemap_Proj::PI / 4.0);
     $b = asin(cos($this->b0) * sin($rotB) + sin($this->b0) * cos($rotB) * cos($rotI));
     $I = atan(sin($rotI) / (cos($this->b0) * cos($rotI) - sin($this->b0) * tan($rotB)));
     $lambda = $this->lambda0 + $I / $this->alpha;
     $S = 0.0;
     $phy = $b;
     $prevPhy = -1000.0;
     $iteration = 0;
     while (abs($phy - $prevPhy) > 1.0E-7) {
         if (++$iteration > 20) {
             throw new Exception("Infinity...");
         }
         //S = log(tan(Sourcemap_Proj::PI / 4.0 + $phy / 2.0));
         $S = 1.0 / $this->alpha * (log(tan(Sourcemap_Proj::PI / 4.0 + $b / 2.0)) - $this->K) + $this->e * log(tan(Sourcemap_Proj::PI / 4.0 + asin($this->e * sin($phy)) / 2.0));
         $prevPhy = $phy;
         $phy = 2.0 * atan(exp($S)) - Sourcemap_Proj::PI / 2.0;
     }
     $p->x = $lambda;
     $p->y = $phy;
     return $p;
 }
Example #3
0
function geoToPixel($lat, $lon, $zoomLevel)
{
    $mapSize = TILE_SIZE << $zoomLevel;
    $latitude = min(1, max(0, 0.5 - log(tan(M_PI / 4 + M_PI / 2 * $lat / 180)) / M_PI / 2));
    $longitude = $lon / 360 + 0.5;
    return array("x" => intval($longitude * $mapSize), "y" => intval($latitude * $mapSize));
}
Example #4
0
 public static function ex3()
 {
     header('Content-type: application/json');
     if (is_numeric($_POST['x'])) {
         $x = $_POST['x'];
         $p = $_POST['p'];
         if (is_numeric($p)) {
             $e = pow(10, -$p);
             if ($x > -M_PI && $x < M_PI) {
                 $aprox = self::LentzAlgorithm($x, $e);
                 $tan = tan($x);
                 echo json_encode(array('aprox' => $aprox, 'tan' => $tan, 'pi' => M_PI, 'e' => $e, 'x' => $x));
                 exit;
             } elseif ($x < -M_PI || $x > M_PI) {
                 if ($x < 0) {
                     (double) ($real_x = fmod($x, -M_PI / 2));
                 } else {
                     (double) ($real_x = fmod($x, M_PI / 2));
                 }
                 $aprox = -self::LentzAlgorithm($real_x, $e);
                 $tan = tan($x);
                 echo json_encode(array('aprox' => $aprox, 'tan' => $tan, 'pi' => M_PI, 'e' => $e, 'x' => $x));
                 exit;
             } else {
                 //$aprox=self::LentzAlgorithm($x,$e);
                 //$tan=tan($x);
                 echo json_encode(array('aprox' => 0, 'tan' => 0, 'pi' => 0, 'e' => 0, 'x' => 0));
                 exit;
             }
         }
         //if
     }
     //if
 }
Example #5
0
function perspective($fovy, $aspect, $zNear, $zFar)
{
    $fovy = deg2rad($fovy);
    $f = 1 / tan($fovy / 2);
    $result = new mat4([[$f / $aspect, 0, 0, 0], [0, $f, 0, 0], [0, 0, ($zFar + $zNear) / ($zNear - $zFar), -1], [0, 0, -2 * $zFar * $zNear / ($zFar - $zNear), 0]]);
    return $result;
}
Example #6
0
 /**
  * Convert this UTM reference to a latitude and longitude
  *
  * @return the converted latitude and longitude
  */
 function toLatLng()
 {
     $wgs84 = new ReferenceEllipsoid(ReferenceEllipsoid::WGS84_MAJ, ReferenceEllipsoid::WGS84_MIN);
     $UTM_F0 = 0.9996;
     $a = $wgs84->maj;
     $eSquared = $wgs84->ecc;
     $ePrimeSquared = $eSquared / (1.0 - $eSquared);
     $e1 = (1 - sqrt(1 - $eSquared)) / (1 + sqrt(1 - $eSquared));
     $x = $this->easting - 500000.0;
     $y = $this->northing;
     $zoneNumber = $this->lngZone;
     $zoneLetter = $this->latZone;
     $longitudeOrigin = ($zoneNumber - 1.0) * 6.0 - 180.0 + 3.0;
     // Correct y for southern hemisphere
     if (ord($zoneLetter) - ord("N") < 0) {
         $y -= 10000000.0;
     }
     $m = $y / $UTM_F0;
     $mu = $m / ($a * (1.0 - $eSquared / 4.0 - 3.0 * $eSquared * $eSquared / 64.0 - 5.0 * pow($eSquared, 3.0) / 256.0));
     $phi1Rad = $mu + (3.0 * $e1 / 2.0 - 27.0 * pow($e1, 3.0) / 32.0) * sin(2.0 * $mu) + (21.0 * $e1 * $e1 / 16.0 - 55.0 * pow($e1, 4.0) / 32.0) * sin(4.0 * $mu) + 151.0 * pow($e1, 3.0) / 96.0 * sin(6.0 * $mu);
     $n = $a / sqrt(1.0 - $eSquared * sin($phi1Rad) * sin($phi1Rad));
     $t = tan($phi1Rad) * tan($phi1Rad);
     $c = $ePrimeSquared * cos($phi1Rad) * cos($phi1Rad);
     $r = $a * (1.0 - $eSquared) / pow(1.0 - $eSquared * sin($phi1Rad) * sin($phi1Rad), 1.5);
     $d = $x / ($n * $UTM_F0);
     $latitude = ($phi1Rad - $n * tan($phi1Rad) / $r * ($d * $d / 2.0 - (5.0 + 3.0 * $t + 10.0 * $c - 4.0 * $c * $c - 9.0 * $ePrimeSquared) * pow($d, 4.0) / 24.0 + (61.0 + 90.0 * $t + 298.0 * $c + 45.0 * $t * $t - 252.0 * $ePrimeSquared - 3.0 * $c * $c) * pow($d, 6.0) / 720.0)) * (180.0 / pi());
     $longitude = $longitudeOrigin + ($d - (1.0 + 2.0 * $t + $c) * pow($d, 3.0) / 6.0 + (5.0 - 2.0 * $c + 28.0 * $t - 3.0 * $c * $c + 8.0 * $ePrimeSquared + 24.0 * $t * $t) * pow($d, 5.0) / 120.0) / cos($phi1Rad) * (180.0 / pi());
     return new LatLng($latitude, $longitude);
 }
 public function LatLonToMeters($lat, $lon)
 {
     $mx = $lon * $this->originShift / 180.0;
     $my = log(tan((90 + $lat) * pi() / 360.0)) / (pi() / 180.0);
     $my = $my * $this->originShift / 180.0;
     return array($mx, $my);
 }
Example #8
0
 public function forward($pt)
 {
     $lon = $pt->x;
     $lat = $pt->y;
     // convert to radians
     if ($lat * Sourcemap_Proj::R2D > 90.0 && $lat * Sourcemap_Proj::R2D < -90.0 && $lon * Sourcemap_Proj::R2D > 180.0 && $lon * Sourcemap_Proj::R2D < -180.0) {
         throw new Exception('Lat/Lon input out of range.');
     }
     if (abs(abs($lat) - Sourcemap_Proj::HALF_PI) <= Sourcemap_Proj::EPSLN) {
         throw new Exception('Lat/Long at poles.');
     } else {
         if ($this->_proj->sphere) {
             $x = $this->_proj->x0 + $this->_proj->a * $this->_proj->k0 * Sourcemap_Proj::adjust_lon($lon - $this->_proj->long0);
             $y = $this->_proj->y0 + $this->_proj->a * $this->_proj->k0 * log(tan(Sourcemap_Proj::FORTPI + 0.5 * $lat));
         } else {
             $sinphi = sin($lat);
             $ts = Sourcemap_Proj::tsfnz($this->_proj->e, $lat, $sinphi);
             $x = $this->_proj->x0 + $this->_proj->a * $this->_proj->k0 * Sourcemap_Proj::adjust_lon($lon - $this->_proj->long0);
             $y = $this->_proj->y0 - $this->_proj->a * $this->_proj->k0 * log($ts);
         }
         $pt->x = $x;
         $pt->y = $y;
         return $pt;
     }
 }
 static function latLonToMeters($lat, $lng)
 {
     $mx = $lng * self::originShift() / 180;
     $my = log(tan((90 + $lat) * pi() / 360.0)) / (pi() / 180);
     $my = $my * self::originShift() / 180;
     return new GoogleMapPoint($mx, $my);
 }
Example #10
0
 public function phi4z($eccent, $e0, $e1, $e2, $e3, $a, $b, $c, $phi)
 {
     $phi = $a;
     for ($i = 1; $i <= 15; $i++) {
         $sinphi = sin($phi);
         $tanphi = tan($phi);
         $c = $tanphi * sqrt(1.0 - $eccent * $sinphi * $sinphi);
         $sin2ph = sin(2.0 * $phi);
         /*
           ml = e0 * *phi - e1 * sin2ph + e2 * sin (4.0 *  *phi);
           mlp = e0 - 2.0 * e1 * cos (2.0 *  *phi) + 4.0 * e2 *  cos (4.0 *  *phi);
         */
         $ml = $e0 * $phi - $e1 * $sin2ph + $e2 * sin(4.0 * $phi) - $e3 * sin(6.0 * $phi);
         $mlp = $e0 - 2.0 * $e1 * cos(2.0 * $phi) + 4.0 * $e2 * cos(4.0 * $phi) - 6.0 * $e3 * cos(6.0 * $phi);
         $con1 = 2.0 * $ml + $c * ($ml * $ml + $b) - 2.0 * $a * ($c * $ml + 1.0);
         $con2 = $eccent * $sin2ph * ($ml * $ml + $b - 2.0 * $a * $ml) / (2.0 * $c);
         $con3 = 2.0 * ($a - $ml) * ($c * $mlp - 2.0 / $sin2ph) - 2.0 * $mlp;
         $dphi = $con1 / ($con2 + $con3);
         $phi += $dphi;
         if (abs($dphi) <= 1.0E-10) {
             return $phi;
         }
     }
     throw new Exception("phi4z: No convergence");
 }
 /**
  * @return RandomLinesBackgroundDrawer
  **/
 public function draw()
 {
     $imageId = $this->getTuringImage()->getImageId();
     $height = $this->getTuringImage()->getHeight();
     $width = $this->getTuringImage()->getWidth();
     for ($i = 0; $i < $this->count; ++$i) {
         $color = $this->makeColor();
         $colorId = $this->getTuringImage()->getColorIdentifier($color);
         $y = mt_rand(1, $height - 1);
         $x = mt_rand(1, $width - 1);
         $angle = mt_rand(0, 180);
         while ($angle == 90) {
             $angle = mt_rand(0, 180);
         }
         $angleRad = deg2rad($angle);
         $dy = ($width - $x) * tan($angleRad);
         if ($dy < $y) {
             $xEnd = $width;
             $yEnd = $y - $dy;
         } else {
             $yEnd = 0;
             $xEnd = $x + tan($angleRad) / $y;
         }
         $dy = $x * tan($angleRad);
         if ($dy <= $height - $y) {
             $xStart = 0;
             $yStart = $y + $dy;
         } else {
             $yStart = $height;
             $xStart = $x - tan($angleRad) / ($height - $y);
         }
         imageline($imageId, $xStart, $yStart, $xEnd, $yEnd, $colorId);
     }
     return $this;
 }
 public function createFromWidthAndAlpha(array $coords)
 {
     $width = $coords[0];
     $alpha = $coords[1];
     $height = tan(deg2rad($alpha)) * $width;
     return $this->createFromCoordinates(array(0, 0, $width, $height));
 }
Example #13
0
 /**
  * Computes whether the vertical segment (lat3, lng3) to South Pole intersects the segment
  * (lat1, lng1) to (lat2, lng2).
  * Longitudes are offset by -lng1; the implicit lng1 becomes 0.
  */
 private static function intersects($lat1, $lat2, $lng2, $lat3, $lng3, $geodesic)
 {
     // Both ends on the same side of lng3.
     if ($lng3 >= 0 && $lng3 >= $lng2 || $lng3 < 0 && $lng3 < $lng2) {
         return false;
     }
     // Point is South Pole.
     if ($lat3 <= -M_PI / 2) {
         return false;
     }
     // Any segment end is a pole.
     if ($lat1 <= -M_PI / 2 || $lat2 <= -M_PI / 2 || $lat1 >= M_PI / 2 || $lat2 >= M_PI / 2) {
         return false;
     }
     if ($lng2 <= -M_PI) {
         return false;
     }
     $linearLat = ($lat1 * ($lng2 - $lng3) + $lat2 * $lng3) / $lng2;
     // Northern hemisphere and point under lat-lng line.
     if ($lat1 >= 0 && $lat2 >= 0 && $lat3 < $linearLat) {
         return false;
     }
     // Southern hemisphere and point above lat-lng line.
     if ($lat1 <= 0 && $lat2 <= 0 && $lat3 >= $linearLat) {
         return true;
     }
     // North Pole.
     if ($lat3 >= M_PI / 2) {
         return true;
     }
     // Compare lat3 with latitude on the GC/Rhumb segment corresponding to lng3.
     // Compare through a strictly-increasing function (tan() or mercator()) as convenient.
     return $geodesic ? tan($lat3) >= self::tanLatGC($lat1, $lat2, $lng2, $lng3) : MathUtil::mercator($lat3) >= self::mercatorLatRhumb($lat1, $lat2, $lng2, $lng3);
 }
Example #14
0
function solphy($dj, &$lo, &$bo, &$p)
{
    global $T2000, $DGRAD, $DPI;
    $t = ($dj - $T2000) / 3652500;
    $t2 = $t * $t;
    $t3 = pow($t, 3);
    $t4 = pow($t, 4);
    $t5 = pow($t, 5);
    $gi = 7.25 * $DGRAD;
    $go = 73 + 40.0 / 60.0 + 50.25 / 3600 * ($dj - 2396758.5) / 365.25;
    $gm = 112.766 + (2430000.5 - $dj) * 14.18439716 + 180;
    $go = fmod($go * $DGRAD, $DPI);
    $gm = fmod($gm * $DGRAD, $DPI);
    $a1 = 2.18 - 3375.7 * $t + 0.36 * $t2;
    $a2 = 3.51 + 125666.39 * $t + 0.1 * $t2;
    $dpsi = 1.0E-7 * (-834 * sin($a1) - 64 * sin($a2));
    $epsv = 0.4090928 + 1.0E-7 * (-226938 * $t - 75 * $t2 + 96926 * $t3 - 2491 * $t4 - 12104 * $t5 + 446 * cos($a1) + 28 * cos($a2));
    $gla = lonsol($dj);
    $gl = $gla - $dpsi;
    $c = cos($gl - $go);
    $s = sin($gl - $go);
    //print "a1: $a1 a2: $a2 dpsi: $dpsi gla: $gla gl: $gl c: $c s: $s<BR>";
    $lo = atan2(-$s * cos($gi), -$c) + $gm;
    $lo = fmod($lo, $DPI);
    if ($lo < 0) {
        $lo += $DPI;
    }
    $bo = asin($s * sin($gi));
    $x = atan(-cos($gla) * tan($epsv));
    $y = atan(-$c * tan($gi));
    $p = $x + $y;
}
Example #15
0
function getmercator($sx, $sy, $ex, $ey)
{
    $sx = $sx * 6371000.0 * M_PI / 180;
    $sy = log(tan(M_PI_4 + $sy * M_PI / 360)) * 6371000.0;
    $ex = $ex * 6371000.0 * M_PI / 180;
    $ey = log(tan(M_PI_4 + $ey * M_PI / 360)) * 6371000.0;
    return array('l' => array('x' => $sx, 'y' => $sy), 'h' => array('x' => $ex, 'y' => $ey));
}
Example #16
0
 /**
  * Resets the angle in radians.
  *
  * @param  float  $radians
  */
 public function set($radians)
 {
     $this->radians = $radians;
     $this->sin = sin($radians);
     $this->cos = cos($radians);
     $this->tan = tan($radians);
     return $this;
 }
Example #17
0
function geoToPixel($lat, $lon, $zoomLevel)
{
    global $tileSize;
    $mapSize = $tileSize << $zoomLevel;
    $latitude = min(1, max(0, 0.5 - log(tan(M_PI / 4 + M_PI / 2 * $lat / 180)) / M_PI / 2));
    $longitude = $lon / 360 + 0.5;
    return array('x' => intval($longitude * $mapSize), 'y' => intval($latitude * $mapSize));
}
 /**
  * get pixel coordinates for given longitude and latitude
  *
  * @param int $lon
  * @param int $lat
  * @return array
  */
 public function getPixelXY($lon, $lat)
 {
     $worldMapWidth = $this->getWidth();
     $worldMapHeight = $this->getHeight();
     $x = round(($lon + 180) / 360 * $worldMapWidth);
     $y = round(abs((log(tan(pi() / 4 + deg2rad($lat) / 2)) - pi()) / (2 * pi())) * $this->getHeight());
     return array('x' => $x, 'y' => $y);
 }
Example #19
0
 private function _projection($angle, $ratio, $near, $far)
 {
     $this->_matrix['x']['x'] = 1 / ($ratio * tan($angle * M_PI / 180 / 2));
     $this->_matrix['y']['y'] = 1 / tan($angle * M_PI / 180 / 2);
     $this->_matrix['z']['z'] = ($near + $far) / ($near - $far);
     $this->_matrix['z']['w'] = 2 * $far * $near / ($near - $far);
     $this->_matrix['w']['z'] = -1;
     $this->_type = "PROJECTION";
 }
Example #20
0
 /**
  * Calculate the pixel point for the given latitude and longitude
  *
  * @param LatLng $latLon
  * @param $zoom
  * @return Point
  */
 public static function calculatePoint(LatLng $latLon, $zoom)
 {
     $tile_count = pow(2, $zoom);
     $pixel_count = $tile_count * self::TILE_SIZE;
     $x = $pixel_count * (180 + $latLon->getLng()) / 360 % $pixel_count;
     $lat = $latLon->getLat() * M_PI / 180;
     $y = log(tan($lat / 2 + M_PI_4));
     $y = $pixel_count / 2 - $pixel_count * $y / (2 * M_PI);
     return new Point($x, $y);
 }
Example #21
0
 public function testTrigonometry()
 {
     $t = new IntMethods();
     $this->assertEquals(sin(1), $t->getSin(1));
     $this->assertEquals(cos(1), $t->getCos(1));
     $this->assertEquals(tan(1), $t->getTan(1));
     $this->assertEquals(asin(1), $t->getAsin(1));
     $this->assertEquals(acos(1), $t->getAcos(1));
     $this->assertEquals(atan(1), $t->getAtan(1));
 }
Example #22
0
 public static function get_tile_offset($lat, $lon, $zoom = 0)
 {
     $xtile = ($lon + 180) / 360 * pow(2, $zoom);
     $xtile -= floor($xtile);
     $dlat = deg2rad($lat);
     $ytile = (1 - log(tan($dlat) + 1 / cos($dlat)) / pi()) / 2 * pow(2, $zoom);
     $ytile -= floor($ytile);
     $tw = $th = sqrt(self::TILE_SZ);
     return array($xtile * 256, $ytile * 256);
 }
Example #23
0
 public function getDistance($lat1, $lng1, $lat2, $lng2)
 {
     /**
      * Ported from javascript
      *
      * Original JavaScript version
      * http://www.movable-type.co.uk/scripts/latlong-vincenty.html
      */
     $lat1 = deg2rad($lat1);
     $lat2 = deg2rad($lat2);
     $lon1 = deg2rad($lon1);
     $lon2 = deg2rad($lon2);
     $a = 6378137;
     $b = 6356752.3142;
     $f = 1 / 298.257223563;
     $L = $lon2 - $lon1;
     $U1 = atan((1 - $f) * tan($lat1));
     $U2 = atan((1 - $f) * tan($lat2));
     $sinU1 = sin($U1);
     $cosU1 = cos($U1);
     $sinU2 = sin($U2);
     $cosU2 = cos($U2);
     $lambda = $L;
     $lambdaP = 2 * M_PI;
     $iterLimit = 20;
     while (abs($lambda - $lambdaP) > 1.0E-12 && --$iterLimit > 0) {
         $sinLambda = sin($lambda);
         $cosLambda = cos($lambda);
         $sinSigma = sqrt($cosU2 * $sinLambda * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda));
         if ($sinSigma == 0) {
             return 0;
         }
         // co-incident points
         $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda;
         $sigma = atan2($sinSigma, $cosSigma);
         // was atan2
         $alpha = asin($cosU1 * $cosU2 * $sinLambda / $sinSigma);
         $cosSqAlpha = cos($alpha) * cos($alpha);
         $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha;
         $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha));
         $lambdaP = $lambda;
         $lambda = $L + (1 - $C) * $f * sin($alpha) * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM)));
     }
     if ($iterLimit == 0) {
         return false;
     }
     // formula failed to converge
     $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b);
     $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq)));
     $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq)));
     $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM)));
     $s = $b * $A * ($sigma - $deltaSigma);
     return round($s / 1609.344, 3);
     //miles
 }
function pleac_Calculating_More_Trigonometric_Functions()
{
    function my_tan($theta)
    {
        return sin($theta) / cos($theta);
    }
    // ------------
    $theta = 3.7;
    printf("%f\n", my_tan($theta));
    printf("%f\n", tan($theta));
}
Example #25
0
 function geo_dist($lon1, $lat1, $lon2, $lat2)
 {
     // check if polygon is in geo mode
     if (!$this->use_geo_mode()) {
         die('error: function geo_dist should not be used if vertices are not defined by latitudes and longitudes (geomode)');
     }
     $a = 6378137;
     $b = 6356752.3142;
     $f = 1 / 298.257223563;
     // WGS-84 ellipsiod
     $L = deg2rad($lon2 - $lon1);
     $U1 = atan((1 - $f) * tan(deg2rad($lat1)));
     $U2 = atan((1 - $f) * tan(deg2rad($lat2)));
     $sinU1 = sin($U1);
     $cosU1 = cos($U1);
     $sinU2 = sin($U2);
     $cosU2 = cos($U2);
     $lambda = $L;
     $lambdaP = 2 * M_PI;
     $iterLimit = 20;
     while (abs($lambda - $lambdaP) > 1.0E-12 && --$iterLimit > 0) {
         $sinLambda = sin($lambda);
         $cosLambda = cos($lambda);
         $sinSigma = sqrt($cosU2 * $sinLambda * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda));
         if ($sinSigma == 0) {
             return 0;
         }
         // co-incident points
         $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda;
         $sigma = atan2($sinSigma, $cosSigma);
         $sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma;
         $cosSqAlpha = 1 - $sinAlpha * $sinAlpha;
         $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha;
         if (is_numeric($cos2SigmaM)) {
             $cos2SigmaM = 0;
         }
         // equatorial line: cosSqAlpha=0 (ยง6)
         $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha));
         $lambdaP = $lambda;
         $lambda = $L + (1 - $C) * $f * $sinAlpha * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM)));
     }
     if ($iterLimit == 0) {
         return NULL;
     }
     // formula failed to converge
     $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b);
     $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq)));
     $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq)));
     $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM)));
     $s = $b * $A * ($sigma - $deltaSigma);
     $s = round($s, 3);
     // round to 1mm precision
     return $s;
 }
Example #26
0
 private function _create_projection($fov, $ratio, $near, $far)
 {
     $rad = deg2rad($fov);
     $yscale = 1.0 / tan($rad / 2);
     $xscale = $yscale / $ratio;
     $nearmfar = $near - $far;
     $vtcX = new Vector(['dest' => new Vertex(array('x' => $xscale, 'y' => 0.0, 'z' => 0.0, 'w' => 0.0))]);
     $vtcY = new Vector(['dest' => new Vertex(array('x' => 0.0, 'y' => $yscale, 'z' => 0.0, 'w' => 0.0))]);
     $vtcZ = new Vector(['dest' => new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => ($far + $near) / $nearmfar, 'w' => -1.0))]);
     $vtx0 = new Vertex(array('x' => 0.0, 'y' => 0.0, 'z' => 2 * $far * $near / $nearmfar, 'w' => 0.0));
     $this->_M = array('vtcX' => $vtcX, 'vtcY' => $vtcY, 'vtcZ' => $vtcZ, 'vtx0' => $vtx0);
 }
Example #27
0
 /**
  * Calculates the geodetic distance between two points using the
  * Vincenty inverse formula for ellipsoids.
  *
  * @see http://en.wikipedia.org/wiki/Vincenty%27s_formulae
  * @see http://www.movable-type.co.uk/scripts/latlong-vincenty.html
  * @param  mixed             $from
  * @param  mixed             $to
  * @return Distance
  * @throws \RuntimeException
  */
 public function distanceVincenty($from, $to)
 {
     $from = LatLng::normalize($from);
     $to = LatLng::normalize($to);
     $lat1 = $from->getLatitude();
     $lng1 = $from->getLongitude();
     $lat2 = $to->getLatitude();
     $lng2 = $to->getLongitude();
     $a = $this->ellipsoid->getSemiMajorAxis();
     $b = $this->ellipsoid->getSemiMinorAxis();
     $f = $this->ellipsoid->getFlattening();
     $L = deg2rad($lng2 - $lng1);
     $U1 = atan((1 - $f) * tan(deg2rad($lat1)));
     $U2 = atan((1 - $f) * tan(deg2rad($lat2)));
     $sinU1 = sin($U1);
     $cosU1 = cos($U1);
     $sinU2 = sin($U2);
     $cosU2 = cos($U2);
     $lambda = $L;
     $iterLimit = 100;
     do {
         $sinLambda = sin($lambda);
         $cosLambda = cos($lambda);
         $sinSigma = sqrt($cosU2 * $sinLambda * ($cosU2 * $sinLambda) + ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda) * ($cosU1 * $sinU2 - $sinU1 * $cosU2 * $cosLambda));
         if ($sinSigma == 0) {
             return new Distance(0);
             // co-incident points
         }
         $cosSigma = $sinU1 * $sinU2 + $cosU1 * $cosU2 * $cosLambda;
         $sigma = atan2($sinSigma, $cosSigma);
         $sinAlpha = $cosU1 * $cosU2 * $sinLambda / $sinSigma;
         $cosSqAlpha = 1 - $sinAlpha * $sinAlpha;
         if (0 != $cosSqAlpha) {
             $cos2SigmaM = $cosSigma - 2 * $sinU1 * $sinU2 / $cosSqAlpha;
         } else {
             $cos2SigmaM = 0.0;
             // Equatorial line
         }
         $C = $f / 16 * $cosSqAlpha * (4 + $f * (4 - 3 * $cosSqAlpha));
         $lambdaP = $lambda;
         $lambda = $L + (1 - $C) * $f * $sinAlpha * ($sigma + $C * $sinSigma * ($cos2SigmaM + $C * $cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM)));
     } while (abs($lambda - $lambdaP) > 1.0E-12 && --$iterLimit > 0);
     if ($iterLimit == 0) {
         throw new \RuntimeException('Vincenty formula failed to converge.');
     }
     $uSq = $cosSqAlpha * ($a * $a - $b * $b) / ($b * $b);
     $A = 1 + $uSq / 16384 * (4096 + $uSq * (-768 + $uSq * (320 - 175 * $uSq)));
     $B = $uSq / 1024 * (256 + $uSq * (-128 + $uSq * (74 - 47 * $uSq)));
     $deltaSigma = $B * $sinSigma * ($cos2SigmaM + $B / 4 * ($cosSigma * (-1 + 2 * $cos2SigmaM * $cos2SigmaM) - $B / 6 * $cos2SigmaM * (-3 + 4 * $sinSigma * $sinSigma) * (-3 + 4 * $cos2SigmaM * $cos2SigmaM)));
     $s = $b * $A * ($sigma - $deltaSigma);
     return new Distance($s);
 }
Example #28
0
 public function forward($p)
 {
     $lon = $p->x;
     $lat = $p->y;
     /* Forward equations
        -----------------*/
     $dlon = Proj4php::$common->adjust_lon($lon - $this->long0);
     $x = $this->x0 + $this->a * $dlon;
     $y = $this->y0 + $this->a * log(tan(Proj4php::$common->PI / 4.0 + $lat / 2.5)) * 1.25;
     $p->x = $x;
     $p->y = $y;
     return $p;
 }
Example #29
0
 public static function WGS84ToLambert($phi, $lambda)
 {
     tools::initvars();
     $phi = deg2rad($phi);
     $lambda = deg2rad($lambda);
     //calc
     $t = tan(pi() / 4 - $phi / 2) / pow((1 - tools::$e * sin($phi)) / (1 + tools::$e * sin($phi)), tools::$e / 2);
     $r = tools::$a * tools::$g * pow($t, tools::$n);
     $theta = tools::$n * ($lambda - tools::$l0);
     $x = tools::$x0 + $r * sin($theta);
     $y = tools::$y0 + tools::$r0 - $r * cos($theta);
     return array($x, $y);
 }
Example #30
0
 public function forward($p)
 {
     $lon = $p->x;
     $lat = $p->y;
     /* Forward equations
        -----------------*/
     $dlon = Sourcemap_Proj::adjust_lon($lon - $this->long0);
     $x = $this->x0 + $this->a * $dlon;
     $y = $this->y0 + $this->a * log(tan(Sourcemap_Proj::PI / 4.0 + $lat / 2.5)) * 1.25;
     $p->x = $x;
     $p->y = $y;
     return $p;
 }