예제 #1
0
function estetico_distance($lat1, $lon1, $lat2, $lon2, $unit = null)
{
    $theta = $lon1 - $lon2;
    $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
    $dist = acos($dist);
    $dist = rad2deg($dist);
    $miles = $dist * 60 * 1.1515;
    // Use Theme option of measuring units if no specefic unit is requested
    if ($unit == null) {
        $default_unit = estetico_get_setting('measuring_units');
        if ($default_unit == 'metric') {
            $unit = 'K';
        } else {
            if ($default_unit == 'us') {
                $unit = 'M';
            }
        }
    }
    $unit = strtoupper($unit);
    if ($unit == "K") {
        return $miles * 1.609344;
    } else {
        if ($unit == "N") {
            return $miles * 0.8683999999999999;
        } else {
            return $miles;
        }
    }
}
 /**
  * GET DISTANCE BETWEEN LOCATION AND CAFES
  * @param $lat1
  * @param $lon1
  * @param $lat2
  * @param $lon2
  * @param $unit
  * @param $limit
  * @param $id
  * @return array|bool
  */
 public function distance($lat1, $lon1, $lat2, $lon2, $unit, $limit, $id)
 {
     $theta = $lon1 - $lon2;
     $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     $miles = $dist * 60 * 1.1515;
     $unit = strtoupper($unit);
     //$miles = round($miles);
     $location = $this->cafe->find($id);
     $phone = $location->phone ? '<br/>' . $location->phone : null;
     if (strlen($location->image) < 1) {
         $image = URL::asset('library/img/loc-noimg.jpg');
     } else {
         $image = URL::asset('uploads/store_images/' . $location->image);
     }
     $array = array();
     if ($miles <= $limit) {
         array_push($array, ['image' => $image, 'miles' => intval($miles), 'id' => $location->id, 'name' => $location->name, 'address' => $location->address . '<br/>' . $location->city . ', ' . $location->state . ' ' . $location->zip_code . $phone, 'lat' => $location->lat, 'lng' => $location->lng, 'state' => $location->state, 'country' => $location->country, 'bakery' => $location->bakery, 'icecream' => $location->icecream, 'coffee' => $location->coffee, 'frozenyogurt' => $location->frozenyogurt, 'smoothies' => $location->smoothies, 'wifi' => $location->wifi, 'curbside' => $location->curbside, 'cookie' => $location->cookie, 'savory' => $location->savory, 'map' => $location->maps_url, 'facebook' => $location->facebook_url, 'online_order' => $location->online_order, 'coming_soon' => $location->coming_soon]);
         return $array;
     }
     return false;
     //return $miles;
     //        if ($unit == "K") {
     //            return ($miles * 1.609344);
     //        } else if ($unit == "N") {
     //            return ($miles * 0.8684);
     //        } else {
     //            return round($miles). ' Miles';
     //        }
 }
예제 #3
0
 /**
  * Calculate distance between two coord sets
  * @author zbrown
  *
  * @param ApiRequestObject $apiRequest
  * @return array
  */
 public function calculateDistance(ApiRequestObject $apiRequest)
 {
     $primaryLatitude = $apiRequest->getLatitude();
     $primaryLongitude = $apiRequest->getLongitude();
     $secondaryLatitude = $apiRequest->getSecondaryLatitude();
     $secondaryLongitude = $apiRequest->getSecondaryLongitude();
     $metricUnit = $apiRequest->getMetricUnit();
     $roundMath = $apiRequest->getRoundMath();
     $payload = array();
     $theta = $primaryLongitude - $secondaryLongitude;
     $dist = sin(deg2rad($primaryLatitude)) * sin(deg2rad($secondaryLatitude)) + cos(deg2rad($primaryLatitude)) * cos(deg2rad($secondaryLatitude)) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     $miles = $dist * 60 * 1.1515;
     $unit = strtolower($metricUnit);
     if ($unit == 'k') {
         $distance = $miles * 1.609344;
         $payload['unitName'] = 'kilometers';
     } else {
         if ($unit == 'n') {
             $distance = $miles * 0.8683999999999999;
             $payload['unitName'] = 'nautical miles';
         } else {
             $distance = $miles;
             $payload['unitName'] = 'miles';
         }
     }
     if (!empty($roundMath)) {
         $final = round($distance, $roundMath);
     } else {
         $final = $distance;
     }
     $payload = ['distance' => $final, 'metric' => strtoupper($apiRequest->getMetricUnit())];
     return $payload;
 }
예제 #4
0
 /**
  * @get distance from latitude and longitute
  *
  * @param float $lat_from
  * @param float $long_from
  * @param float $lat_to
  * @param float *long_to
  * @param $unit options k, m, n, Default k
  *
  * @return float
  */
 public static function distance($lat_from, $long_from, $lat_to, $long_to, $unit = 'k')
 {
     /*** distance unit ***/
     switch ($unit) {
         /*** miles ***/
         case 'm':
             $unit = 3963;
             break;
             /*** nautical miles ***/
         /*** nautical miles ***/
         case 'n':
             $unit = 3444;
             break;
         default:
             /*** kilometers ***/
             $unit = 6371;
     }
     /*** 1 degree = 0.017453292519943 radius ***/
     $degreeRadius = deg2rad(1);
     /*** convert longitude and latitude to radians ***/
     $lat_from *= $degreeRadius;
     $long_from *= $degreeRadius;
     $lat_to *= $degreeRadius;
     $long_to *= $degreeRadius;
     /*** apply the Great Circle Distance Formula ***/
     $dist = sin($lat_from) * sin($lat_to) + cos($lat_from) * cos($lat_to) * cos($long_from - $long_to);
     /*** radius of earth * arc cosine ***/
     return $unit * acos($dist);
 }
예제 #5
0
파일: utils.php 프로젝트: abbra/midcom
 /**
  * Get bearing from position to another
  *
  * Code from http://www.corecoding.com/getfile.php?file=25
  */
 static function get_bearing(org_routamc_positioning_spot $from, org_routamc_positioning_spot $to)
 {
     if (round($from->longitude, 1) == round($to->longitude, 1)) {
         if ($from->latitude < $to->latitude) {
             $bearing = 0;
         } else {
             $bearing = 180;
         }
     } else {
         $dist = org_routamc_positioning_utils::get_distance($from, $to, 'N');
         $arad = acos((sin(deg2rad($to->latitude)) - sin(deg2rad($from->latitude)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($from->latitude))));
         $bearing = $arad * 180 / pi();
         if (sin(deg2rad($to->longitude - $from->longitude)) < 0) {
             $bearing = 360 - $bearing;
         }
     }
     $dirs = array('N', 'E', 'S', 'W');
     $rounded = round($bearing / 22.5) % 16;
     if ($rounded % 4 == 0) {
         $dir = $dirs[$rounded / 4];
     } else {
         $dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
         $dir .= $dirs[1 + 2 * floor($rounded / 8)];
     }
     return $dir;
 }
 public static function get_nearest_timezone($cur_lat, $cur_long, $country_code = '')
 {
     $timezone_ids = $country_code ? DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code) : DateTimeZone::listIdentifiers();
     if ($timezone_ids && is_array($timezone_ids) && isset($timezone_ids[0])) {
         $time_zone = '';
         $tz_distance = 0;
         //only one identifier?
         if (count($timezone_ids) == 1) {
             $time_zone = $timezone_ids[0];
         } else {
             foreach ($timezone_ids as $timezone_id) {
                 $timezone = new DateTimeZone($timezone_id);
                 $location = $timezone->getLocation();
                 $tz_lat = $location['latitude'];
                 $tz_long = $location['longitude'];
                 $theta = $cur_long - $tz_long;
                 $distance = sin(deg2rad($cur_lat)) * sin(deg2rad($tz_lat)) + cos(deg2rad($cur_lat)) * cos(deg2rad($tz_lat)) * cos(deg2rad($theta));
                 $distance = acos($distance);
                 $distance = abs(rad2deg($distance));
                 // echo '<br />'.$timezone_id.' '.$distance;
                 if (!$time_zone || $tz_distance > $distance) {
                     $time_zone = $timezone_id;
                     $tz_distance = $distance;
                 }
             }
         }
         return $time_zone;
     }
     return 'unknown';
 }
예제 #7
0
 public function calculateDistance($lat_from, $long_from, $lat_to, $long_to, $unit = 'k')
 {
     switch ($unit) {
         // miles
         case 'm':
             $unit = 3963;
             break;
             // nautical miles
         // nautical miles
         case 'n':
             $unit = 3444;
             break;
             // kilometers
         // kilometers
         default:
             $unit = 6371;
     }
     $degreeRadius = deg2rad(1);
     $lat_from *= $degreeRadius;
     $long_from *= $degreeRadius;
     $lat_to *= $degreeRadius;
     $long_to *= $degreeRadius;
     // apply the Great Circle Distance Formula
     $dist = sin($lat_from) * sin($lat_to) + cos($lat_from) * cos($lat_to) * cos($long_from - $long_to);
     // radius of earth * arc cosine
     return $unit * acos($dist);
 }
예제 #8
0
 public function getShape()
 {
     $c = $this->_points[2];
     // base
     $b = $this->_points[1];
     // sides
     $a = $this->_points[0];
     // calculate angle, cosine rule
     $alpha = acos((pow($b, 2) + pow($c, 2) - pow($a, 2)) / (2 * $b * $c));
     // pythag to calc height and y distance
     $height = abs(sin($alpha)) * $b;
     $width = abs(cos($alpha)) * $b;
     $x = 0;
     // start point
     $y = 100;
     $points = array($x, $y, $x + $c, $y, $x + $width, $y - $height);
     // draw
     $image = imagecreatetruecolor(100, 100);
     // sets background to red
     $white = ImageColorAllocate($image, 255, 255, 255);
     ImageFillToBorder($image, 0, 0, $white, $white);
     $blue = imagecolorallocate($image, 0, 0, 255);
     imagefilledpolygon($image, $points, 3, $blue);
     return $image;
 }
예제 #9
0
파일: Tools.php 프로젝트: weejames/geotools
 public static function distanceBetween(Geopoint $pointA, Geopoint $pointB, $algorithm, $units)
 {
     switch ($algorithm) {
         case 'haversine':
             $theta = $pointA->getLongitude() - $pointB->getLongitude();
             $dist = sin(deg2rad($pointA->getLatitude())) * sin(deg2rad($pointB->getLatitude())) + cos(deg2rad($pointA->getLatitude())) * cos(deg2rad($pointB->getLatitude())) * cos(deg2rad($theta));
             $dist = acos($dist);
             $distance = rad2deg($dist);
             break;
         case 'flat':
         default:
             $distanceEW = ($pointB->getLongitude() - $pointA->getLongitude()) * cos($pointA->getLatitude());
             $distanceNS = $pointB->getLatitude() - $pointA->getLatitude();
             $distance = sqrt($distanceEW * $distanceEW + $distanceNS * $distanceNS);
             break;
     }
     switch ($units) {
         case self::GEO_UNIT_KM:
             $radius = self::EARTH_RADIUS_KM;
             break;
         case self::GEO_UNIT_MILES:
             $radius = self::EARTH_RADIUS_MILES;
             break;
     }
     $distance *= 2 * pi() * $radius / 360.0;
     return $distance;
 }
예제 #10
0
파일: utils.php 프로젝트: nemein/openpsa
 /**
  * Get bearing from position to another
  *
  * Code from http://www.corecoding.com/getfile.php?file=25
  */
 function get_bearing($from, $to)
 {
     if (round($from['longitude'], 1) == round($to['longitude'], 1)) {
         if ($from['latitude'] < $to['latitude']) {
             $bearing = 0;
         } else {
             $bearing = 180;
         }
     } else {
         $dist = org_routamc_positioning_utils::get_distance($from, $to, 'N');
         $arad = acos((sin(deg2rad($to['latitude'])) - sin(deg2rad($from['latitude'])) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($from['latitude']))));
         $bearing = $arad * 180 / pi();
         if (sin(deg2rad($to['longitude'] - $from['longitude'])) < 0) {
             $bearing = 360 - $bearing;
         }
     }
     $dirs = array("N", "E", "S", "W");
     $rounded = round($bearing / 22.5) % 16;
     if ($rounded % 4 == 0) {
         $dir = $dirs[$rounded / 4];
     } else {
         $dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
         $dir .= $dirs[1 + 2 * floor($rounded / 8)];
     }
     return $dir;
 }
예제 #11
0
    function Generate($level)
    {
        $CI =& get_instance();
        $CI->load->library('10/Szogfuggvenyek/Haromszog_tangens', NULL, 'tangens');
        $node = 'AC';
        $length = rand(ceil($level / 2), $level);
        $AB = $length + rand(ceil($level / 2), $level);
        $question = 'Az $ABC$ derékszögű háromszög $' . $node . '$ befogója $' . $length . '$ cm, $AB$ átfogója $' . $AB . '$ cm hosszú. Számítsa ki az $ABC$ háromszög hegyesszögeinek nagyságát legalább két tizedesjegy pontossággal!';
        $alpha = toDeg(acos($length / $AB));
        $beta = 90 - $alpha;
        $alphatext = str_replace('.', ',', round($alpha * 100) / 100);
        $betatext = str_replace('.', ',', round($beta * 100) / 100);
        $correct = array(round1($alpha), round1($beta));
        $labels = array('$\\alpha$', '$\\beta$');
        $solution = '$\\alpha=' . $alphatext . '°$ és $\\beta=' . $betatext . '°$.';
        $hints[][] = 'Rajzoljunk egy derékszögű háromszöget:' . $CI->tangens->Triangle();
        $hints[][] = 'Tudjuk, hogy az $\\textcolor{blue}{' . $node . '}$ befogó $' . $length . '$ cm hosszú:' . $CI->tangens->Triangle([$node], [$length], ['blue']);
        $hints[][] = 'Tudjuk, hogy az $\\textcolor{green}{AB}$ átfogó $' . $AB . '$ cm hosszú:' . $CI->tangens->Triangle([$node, 'AB'], [$length, $AB], ['blue', 'green']);
        $page[] = 'Az $\\alpha$ szög <b>koszinusza</b> a szög melletti befogó ($AC$) és az átfogó ($AB$) hányadosa:' . '$$\\cos\\alpha=\\frac{\\textcolor{blue}{AC}}{\\textcolor{green}{AB}}=' . '\\frac{\\textcolor{blue}{' . $length . '}}{\\textcolor{green}{' . $AB . '}}' . '$$';
        $page[] = 'Az $\\alpha$ szöget úgy kapjuk meg, ha a hányados <b>arkusz koszinuszát</b> vesszük (ami a koszinusz függvény inverze), és az eredményt két tizedesjegyre kerekítjük:$$\\alpha=\\arccos\\frac{\\textcolor{blue}{' . $length . '}}{\\textcolor{green}{' . $AB . '}}=' . $alphatext . '°$$';
        $page[] = '<b>Megjegyzés</b>: az eredményt a következőképpen lehet kiszámolni számológéppel:
			<ol>
				<li>Állítsuk be a gépet <b>DEG</b> módba (ha még nem tettük):<br /><kbd>MODE</kbd> <kbd>DEG</kbd></li>
				<li>Az koszinusz függvény inverzét a <b>cos<sup>-1</sup></b> gomb segítségével lehet kiszámolni:<br />' . '<kbd>' . $length . '</kbd> <kbd>&divide;</kbd> <kbd>' . $AB . '</kbd> <kbd>=</kbd> <kbd>Shift</kbd> <kbd>cos<sup>-1</sup></kbd> <kbd>=</kbd></li>
			</ol>';
        $page[] = 'Tehát az $\\alpha$ szög <span class="label label-success">$' . $alphatext . '°$</span>.';
        $hints[] = $page;
        $page = [];
        $page[] = 'Mivel a háromszög belső szögeinek összege $180°$, ezért a $\\beta$ szöget már könnyen ki lehet számolni:$$\\beta=180°-90°-' . $alphatext . '°$$';
        $page[] = 'Tehát a $\\beta$ szög <span class="label label-success">$' . $betatext . '°$</span>.';
        $hints[] = $page;
        return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints, 'labels' => $labels, 'type' => 'array');
    }
예제 #12
0
 /**
  * Compare two position and return is in area
  * @param double $areaLat
  * @param double $areaLng
  * @param double $radius
  * @param double $targetLat
  * @param double $targetLng
  * @return boolean
  */
 public function isInArea($lat1, $lon1, $radius, $lat2, $lon2)
 {
     $theta = $lon1 - $lon2;
     $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     $miles = $dist * 60 * 1.1515;
     $meter = $miles * 1609.344;
     if ($meter <= $radius) {
         return true;
     } else {
         return false;
     }
     // 		if ($unit == "K") {
     // 			return ($miles * 1.609344);
     // 		} else if ($unit == "N") {
     // 			return ($miles * 0.8684);
     // 		} else {
     // 			return $miles;
     // 		}
     // 		}
     // 		echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>";
     // 		echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>";
     // 		echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";
 }
예제 #13
0
파일: Qra.php 프로젝트: orio33/Cloudlog
function bearing($lat1, $lon1, $lat2, $lon2)
{
    if (round($lon1, 1) == round($lon2, 1)) {
        if ($lat1 < $lat2) {
            $bearing = 0;
        } else {
            $bearing = 180;
        }
    } else {
        $dist = distance($lat1, $lon1, $lat2, $lon2, 'N');
        $arad = acos((sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($lat1))));
        $bearing = $arad * 180 / pi();
        if (sin(deg2rad($lon2 - $lon1)) < 0) {
            $bearing = 360 - $bearing;
        }
    }
    $dirs = array("N", "E", "S", "W");
    $rounded = round($bearing / 22.5) % 16;
    if ($rounded % 4 == 0) {
        $dir = $dirs[$rounded / 4];
    } else {
        $dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
        $dir .= $dirs[1 + 2 * floor($rounded / 8)];
        #if ($rounded % 2 == 1)
        #  $dir = $dirs[round_to_int($rounded/4) % 4] . "-" . $dir;
    }
    $var_dist = "";
    #return $dir;
    if (isset($dist)) {
        $var_dist = $dist . " miles";
    }
    return round($bearing, 0) . "&#186; " . $dir . " " . $var_dist;
}
예제 #14
0
 /**
  * Get distance from another position
  *
  * @param PositionAbstract $position Position to get distance from.
  *
  * @param string $units Units to return. Default (m) is miles.
  * n = nautical miles, k = kilometers,
  * f = feet, i = inches.
  *
  * @param float $adjustment Adjust the distance to take turns into account.
  * 1.125 seems to be the most accurate.
  *
  * @return float Distance in the specified units
  */
 public function getDistanceFrom(PositionAbstract $position, $units = 'm', $adjustment = 1.125)
 {
     $miles = $adjustment * 3959 * acos(cos(deg2rad($this->getLat())) * cos(deg2rad($position->getLat())) * cos(deg2rad($this->getLng()) - deg2rad($position->getLng())) + sin(deg2rad($this->getLat())) * sin(deg2rad($position->getLat())));
     switch (strtolower($units)) {
         case 'k':
             // kilometers
             return $miles * 1.609344;
             break;
         case 'n':
             // nautical mile
             return $miles * 0.868976242;
             break;
         case 'f':
             // feet
             return $miles * 5280;
             break;
         case 'i':
             // inches
             return $miles * 63360;
             break;
         case 'm':
         default:
             return $miles;
             break;
     }
 }
예제 #15
0
 private function distance($lat1, $lon1, $lat2, $lon2, $unit)
 {
     global $source;
     $theta = $lon1 - $lon2;
     $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     $miles = $dist * 60 * 1.1515;
     $unit = strtoupper($unit);
     $distDesc = "";
     if ($unit == "K") {
         $meters = intval($miles * 1.609344 * 1000);
         if ($meters > 1000) {
             $distDesc1 = intval($meters / 1000) . '公里';
             $distDesc2 = intval($meters % 1000) . '公尺';
             $distDesc = $distDesc1 . $distDesc2;
         } else {
             $distDesc = $meters . '公尺';
         }
     } else {
         if ($unit == "N") {
             $distDesc = $miles * 0.8683999999999999 + '';
         } else {
             $distDesc = $miles + '';
         }
     }
     return array("dist" => $meters, "distDesc" => $distDesc);
 }
예제 #16
0
function LatLonDistance($lat1, $lon1, $lat2, $lon2)
{
    global $sDistanceUnit;
    // Formula for calculating radians between
    // latitude and longitude pairs.
    // Uses the Spherical Law of Cosines to find great circle distance.
    // Length of arc on surface of sphere
    // convert to radians to work with trig functions
    $lat1 = deg2rad($lat1);
    $lon1 = deg2rad($lon1);
    $lat2 = deg2rad($lat2);
    $lon2 = deg2rad($lon2);
    // determine angle between between points in radians
    $radians = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($lon1 - $lon2));
    // mean radius of Earth in kilometers
    $radius = 6371.0;
    // distance in kilometers is $radians times $radius
    $distance = $radians * $radius;
    // convert to miles
    if (strtoupper($sDistanceUnit) == 'MILES') {
        $distance = 0.6213712 * $distance;
    }
    // Return distance to three figures
    if ($distance < 10.0) {
        $distance_f = sprintf("%0.2f", $distance);
    } elseif ($distance < 100.0) {
        $distance_f = sprintf("%0.1f", $distance);
    } else {
        $distance_f = sprintf("%0.0f", $distance);
    }
    return $distance_f;
}
예제 #17
0
 private function greatCircleDistance($firstLongitude, $firstLatitude, $secondLongitude, $secondLatitude)
 {
     $o = acos(sin($firstLatitude) * sin($secondLatitude) + cos($firstLatitude) * cos($secondLatitude) * cos($firstLongitude - $secondLongitude));
     $r = 6371;
     $d = $o * $r;
     return $d;
 }
예제 #18
0
파일: Astro.php 프로젝트: mykitty/jyotish
 /**
  * Get sunrise time.
  * 
  * @param array $userData
  * @param array $sunData
  * @return float
  */
 public static function getSunRise($userData, $sunData)
 {
     $hourAngle = acos((cos(Math::dmsToDecimal(['d' => 90, 'm' => 51])) - sin($userData['latitude']) * sin($sunData['declination'])) / cos($userData['latitude']) * cos($sunData['declination']));
     $eot = self::getEot($userData['date']);
     $time = 12 - $hourAngle + $eot;
     return $time;
 }
	public function distanceBetween(Geopoint $pointA, Geopoint $pointB, $algorithm = 'flat', $unit = null) {

		if (!$unit) $unit = $this->defaultUnit;

		switch ($algorithm) {
			case 'haversine':
				$theta = ($pointA->longitude - $pointB->longitude); 
				$dist = sin(deg2rad($pointA->latitude)) * sin(deg2rad($pointB->latitude)) +  cos(deg2rad($pointA->latitude)) * cos(deg2rad($pointB->latitude)) * cos(deg2rad($theta)); 
				$dist = acos($dist); 
				
				$distance = rad2deg($dist);
			break;
			case 'flat':
			default:	
				$distanceEW = ($pointB->longitude - $pointA->longitude) * cos($pointA->latitude);
				$distanceNS = $pointB->latitude - $pointA->latitude;
				
				$distance = sqrt( ($distanceEW * $distanceEW) + ($distanceNS * $distanceNS));
			break;
		}
		
		$distance *= 2 * pi() * $this->earthRadius[$unit] / 360.0;
		
		return $distance;
		
	}
예제 #20
0
function ogdbDistance($origin, $destination)
{
    ini_set('precision', 49);
    // http://de2.php.net/manual/de/function.pi.php
    $fileData = explode("\n", ogdbGetData());
    foreach ($fileData as $fileRow) {
        $fileRow = explode("\t", $fileRow);
        $dataStructure = ogdbDataStructure($fileRow);
        if ($dataStructure) {
            if (isset($fileRow[$dataStructure['zip_pos']]) && isset($fileRow[$dataStructure['lon_pos']]) && isset($fileRow[$dataStructure['lat_pos']])) {
                if (substr_count($fileRow[$dataStructure['zip_pos']], $origin) == 1) {
                    $origin_lon = deg2rad($fileRow[$dataStructure['lon_pos']]);
                    $origin_lat = deg2rad($fileRow[$dataStructure['lat_pos']]);
                }
                if (substr_count($fileRow[$dataStructure['zip_pos']], $destination) == 1) {
                    $destination_lon = deg2rad($fileRow[$dataStructure['lon_pos']]);
                    $destination_lat = deg2rad($fileRow[$dataStructure['lat_pos']]);
                }
            }
        }
        unset($dataStructure, $fileRow);
    }
    $distance = FALSE;
    if (isset($origin_lon) && isset($origin_lat) && isset($destination_lon) && isset($destination_lat)) {
        $distance = acos(sin($destination_lat) * sin($origin_lat) + cos($destination_lat) * cos($origin_lat) * cos($destination_lon - $origin_lon)) * OGDB_EARTH_RADIUS;
    }
    return $distance;
}
예제 #21
0
function getDistance($latA, $lonA, $latB = 45.732044, $lonB = 126.611824)
{
    $R = 6371.001;
    $t = sin($latA) * sin($latB) + cos($latA) * cos($latB) * cos($lonA - $lonB);
    $distance = $R * acos($t) * M_PI / 180;
    return $distance * 1000;
}
예제 #22
0
 /**
  * get distance between to geocoords using great circle distance formula
  * @param Point $point1
  * @param Point $point2
  * @param string $unit   M=miles, K=kilometers, N=nautical miles, I=inches, F=feet
  */
 function distanceBetweenPoints($point1, $point2, $unit = 'K')
 {
     $lat1 = $point1->lat;
     $lng1 = $point1->lng;
     $lat2 = $point2->lat;
     $lng2 = $point2->lng;
     // calculate miles
     $M = 69.09 * rad2deg(acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lng1 - $lng2))));
     switch (strtoupper($unit)) {
         case 'K':
             // kilometers
             return $M * 1.609344;
             break;
         case 'N':
             // nautical miles
             return $M * 0.868976242;
             break;
         case 'F':
             // feet
             return $M * 5280;
             break;
         case 'I':
             // inches
             return $M * 63360;
             break;
         case 'M':
             // miles
             return $M;
             break;
         default:
             // miles
             return $M;
             break;
     }
 }
예제 #23
0
 /**
  * @param Coordinate $point
  * @param Line $line
  *
  * @return float
  */
 public function getPerpendicularDistance(Coordinate $point, Line $line)
 {
     $ellipsoid = $point->getEllipsoid();
     $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius();
     $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat());
     $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng());
     $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat);
     $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat);
     $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat);
     $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat());
     $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng());
     $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat);
     $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat);
     $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat);
     $pointLat = $this->deg2radLatitude($point->getLat());
     $pointLng = $this->deg2radLongitude($point->getLng());
     $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat);
     $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat);
     $pointZ = $ellipsoidRadius * cos($pointLat);
     $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY;
     $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ;
     $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX;
     $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ);
     $normalizedX /= $length;
     $normalizedY /= $length;
     $normalizedZ /= $length;
     $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ;
     $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ);
     $thetaPoint /= $length;
     $distance = abs(M_PI / 2 - acos($thetaPoint));
     return $distance * $ellipsoidRadius;
 }
예제 #24
0
 /**
  * Calculate the distance between two
  * points using the Great Circle formula.
  *
  * Supply instances of the coordinate class.
  * 
  * http://www.ga.gov.au/earth-monitoring/geodesy/geodetic-techniques/distance-calculation-algorithms.html#circle
  *
  * @param Treffynnon\Navigator\Coordinate $point1
  * @param Treffynnon\Navigator\Coordinate $point2
  * @return float
  */
 public function calculate(N\LatLong $point1, N\LatLong $point2)
 {
     $celestialBody = $this->getCelestialBody();
     $degrees = acos(sin($point1->getLatitude()->get()) * sin($point2->getLatitude()->get()) + cos($point1->getLatitude()->get()) * cos($point2->getLatitude()->get()) * cos($point2->getLongitude()->get() - $point1->getLongitude()->get()));
     $d = $degrees * $celestialBody->volumetricMeanRadius;
     return $d * 1000;
 }
예제 #25
0
 /**
  *  Calculate Great Circle distance
  */
 function __construct($latitude, $longitude, $latitude_origin, $longitude_origin)
 {
     $lat1 = $this->deg2rad($latitude_origin);
     $lat2 = $this->deg2rad($latitude);
     $lon1 = $this->deg2rad($longitude_origin);
     $lon2 = $this->deg2rad($longitude);
     $d = 2 * asin(sqrt(pow(sin(($lat1 - $lat2) / 2), 2) + cos($lat1) * cos($lat2) * pow(sin(($lon1 - $lon2) / 2), 2)));
     if ($d <= 1.0E-7) {
         $tc1 = 0;
         // less than 10 cm: going to self
     } elseif ($lat1 > M_PI / 2.0001) {
         $tc1 = M_PI;
         // starting from N pole
     } elseif ($lat1 < -M_PI / 2.0001) {
         $tc1 = 0;
         // starting from S pole
     } else {
         $tc1 = acos((sin($lat2) - sin($lat1) * cos($d)) / (sin($d) * cos($lat1)));
         if (sin($lon2 - $lon1) < 0) {
             $tc1 = 2 * M_PI - $tc1;
         }
     }
     $this->heading = rad2deg($tc1);
     $this->distance = rad2deg($d) * 60 * 1852;
     /* Assumes Earth radius of 6366.71 km */
 }
예제 #26
0
 public function testFunctions()
 {
     $functions = array('abs(5)' => 5, 'abs(-5)' => 5, 'abs(0)' => 0, 'acos(0.5)' => acos(0.5), 'acos(0.1)' => acos(0.1));
     foreach ($functions as $function => $expected) {
         $this->assertEquals($expected, $this->em->sProcessStringContainingExpressions('{' . $function . '}'));
     }
 }
예제 #27
0
파일: Calculator.php 프로젝트: XTAIN/geo
 /**
  * @param Point $place1
  * @param Point $place2
  *
  * @return Distance
  * @author Maximilian Ruta <*****@*****.**>
  */
 public static function distance(Point $place1, Point $place2)
 {
     $theta = $place1->getLongitude() - $place2->getLongitude();
     $dist = sin(deg2rad($place1->getLatitude())) * sin(deg2rad($place2->getLatitude())) + cos(deg2rad($place1->getLatitude())) * cos(deg2rad($place2->getLatitude())) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     return new Distance($dist);
 }
예제 #28
0
 static function getPointDistance($lat1, $lon1, $lat2, $lon2)
 {
     $theta = $lon1 - $lon2;
     $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
     $dist = acos($dist);
     $dist = rad2deg($dist);
     return $dist * 60 * 1.1515;
 }
예제 #29
0
 public function distance(Location $p1, Location $p2)
 {
     $R = 6371;
     $d = acos( sin($this->toRad($p1->getLatitude()))*sin($this->toRad($p2->getLatitude())) +
     cos($this->toRad($p1->getLatitude()))*cos($this->toRad($p2->getLatitude())) *
     cos($this->toRad($p2->getLongitude())-$this->toRad($p1->getLongitude()))) * $R;
     return $d;
 }
예제 #30
0
 /**
  * Calculates the Great Circle Distance from the geographic point to another Long/Lat coordinate
  *
  * Formula is from http://williams.best.vwh.net/avform.htm#GCF
  *
  * @param float $lon1 Longitude
  * @param float $lat1 Latitude
  *
  * @return float distance in meters
  */
 public function distanceFrom($lon1, $lat1)
 {
     $lon2 = deg2rad($this->getLong());
     $lat2 = deg2rad($this->getLat());
     $theta = $lon2 - $lon1;
     $dist = acos(sin($lat1) * sin($lat2) + cos($lat1) * cos($lat2) * cos($theta));
     return $dist * 6366710;
 }