function returnGeo($lat, $lng, $radius, $tableName, $limit = 10) { $r = $radius / 3956; $latRadians = $lat * pi() / 180; $maxLat = 180 * ($latRadians + $r) / pi(); $minLat = 180 * ($latRadians - $r) / pi(); $lonRadians = $lng * pi() / 180; $deltaLon = asin(sin($r) / cos($latRadians)); //return $deltaLon; $maxLon = 180 * (($lonRadians + $deltaLon) / pi()); $minLon = 180 * (($lonRadians - $deltaLon) / pi()); // return array($lat,$lng,$radius,$tableName,$limit); if ($tableName == 'cities') { $query = "SELECT *, 3956 * 2 * ASIN(SQRT(POWER(SIN(abs(" . $lat . " - latitude) * pi()/180 /2),2)+ " . "(COS(" . $lat . "* pi()/180) * COS(abs(latitude) * pi()/180) * " . "POWER(SIN(abs(" . $lng . " - longitude) * pi()/180 / 2),2)) )) " . " as Distance FROM " . $tableName . " WHERE latitude < " . $maxLat . " AND latitude > " . $minLat . " AND longitude < " . $maxLon . " AND longitude > " . $minLon . " having Distance < " . $radius . " ORDER BY population DESC, Distance ASC LIMIT " . $limit . ";"; } else { $query = "SELECT *, 3956 * 2 * ASIN(SQRT(POWER(SIN(abs(" . $lat . " - latitude) * pi()/180 /2),2)+ " . "(COS(" . $lat . "* pi()/180) * COS(abs(latitude) * pi()/180) * " . "POWER(SIN(abs(" . $lng . " - longitude) * pi()/180 / 2),2)) )) " . " as Distance FROM " . $tableName . " WHERE latitude < " . $maxLat . " AND latitude > " . $minLat . " AND longitude < " . $maxLon . " AND longitude > " . $minLon . "having Distance < " . $radius . " ORDER BY Distance ASC LIMIT " . $limit . ";"; } //return $query; $results = $this->query($query); //if (!$results) return array('problem'=>$query); foreach ($results as $key => $value) { $results[$key] = $value[$tableName]; $results[$key]['distance'] = $value[0]['Distance']; } return $results; }
public static function getRange($params) { if (empty($params['range'])) { $params['range'] = 1000; } if (!isset($params['latitude']) || !isset($params['longitude']) || !isset($params['range'])) { return false; } $latitude = $params['range'] / 111319.55; $result['min_latitude'] = number_format($params['latitude'] - $latitude, 6); $result['max_latitude'] = number_format($params['latitude'] + $latitude, 6); // $longitude = $params['range']/(111319.55*cos($params['latitude']))*0.817;//0.86修正数 $longitude = rad2deg(asin(sin($params['range'] / self::R) / cos(deg2rad($params['latitude'])))); $result['min_longitude'] = number_format($params['longitude'] - $longitude, 6); $result['max_longitude'] = number_format($params['longitude'] + $longitude, 6); if ($result['min_latitude'] < -90) { $result['min_latitude'] = -90.0; } if ($result['max_latitude'] > 90) { $result['max_latitude'] = 90.0; } if ($result['min_longitude'] < -180) { $result['min_longitude'] = -180.0; } if ($result['max_longitude'] > 180) { $result['max_longitude'] = 180.0; } return $result; }
public function __construct(Coords $p0, Coords $dir, $len, $r0, $r1) { $vl = $dir->distance(0, 0, 0); if ($vl == 1) { $this->ap = atan2($dir->y, $dir->x); $this->av = asin($dir->z); $this->dir = clone $dir; } else { $this->ap = atan2($dir->y, $dir->x); $this->av = asin($dir->z / $vl); $this->dir = Coords::fromPolar(1, $this->ap, $this->av); } $this->p0 = clone $p0; $this->p1 = $p0->translate($len * $this->dir->x, $len * $this->dir->y, $len * $this->dir->z); $this->len = $len; $this->r0 = $r0; $this->r1 = $r1; $cap = cos($this->ap - M_PI / 2); $sap = sin($this->ap - M_PI / 2); $sav = sin($this->av - M_PI / 2); $points[] = new Coords($this->p0->x + $this->r0 * $cap, $this->p0->y + $this->r0 * $sap, $this->p0->z + $this->r0 * $sav); $points[] = new Coords($this->p0->x - $this->r0 * $cap, $this->p0->y - $this->r0 * $sap, $this->p0->z - $this->r0 * $sav); $points[] = new Coords($this->p1->x + $this->r1 * $cap, $this->p1->y + $this->r1 * $sap, $this->p1->z + $this->r1 * $sav); $points[] = new Coords($this->p1->x - $this->r1 * $cap, $this->p1->y - $this->r1 * $sap, $this->p1->z - $this->r1 * $sav); $this->red = new Coords(floor(min($points[0]['x'], $points[1]['x'], $points[2]['x'], $points[3]['x'])), floor(min($points[0]['y'], $points[1]['y'], $points[2]['y'], $points[3]['y'])), floor(min($points[0]['z'], $points[1]['z'], $points[2]['z'], $points[3]['z']))); $this->blue = new Coords(ceil(max($points[0]['x'], $points[1]['x'], $points[2]['x'], $points[3]['x'])), ceil(max($points[0]['y'], $points[1]['y'], $points[2]['y'], $points[3]['y'])), ceil(max($points[0]['z'], $points[1]['z'], $points[2]['z'], $points[3]['z']))); }
function normalizedBoundingBox($center, $tolerance, $fromProj = null, $toProj = null) { if ($fromProj !== null || $toProj !== null) { $projector = new MapProjector(); } // create the bounding box in lat/lon first if ($fromProj !== null) { $projector->setSrcProj($fromProj); $center = $projector->projectPoint($center); } // approximate upper/lower bounds for lat/lon before calculating GCD $dLatRadians = $tolerance / EARTH_RADIUS_IN_METERS; // by haversine formula $dLonRadians = 2 * asin(sin($dLatRadians / 2) / cos($center['lat'] * M_PI / 180)); $dLatDegrees = $dLatRadians * 180 / M_PI; $dLonDegrees = $dLonRadians * 180 / M_PI; $min = array('lat' => $center['lat'] - $dLatDegrees, 'lon' => $center['lon'] - $dLonDegrees); $max = array('lat' => $center['lat'] + $dLatDegrees, 'lon' => $center['lon'] + $dLonDegrees); if ($toProj !== null) { $projector->setSrcProj(GEOGRAPHIC_PROJECTION); $projector->setDstProj($toProj); $min = $projector->projectPoint($min); $max = $projector->projectPoint($max); } return array('min' => $min, 'max' => $max, 'center' => $center); }
function getDistance($lat1, $lng1, $lat2, $lng2) { $earthRadius = 6367000; //approximate radius of earth in meters /* Convert these degrees to radians to work with the formula */ $lat1 = $lat1 * pi() / 180; $lng1 = $lng1 * pi() / 180; $lat2 = $lat2 * pi() / 180; $lng2 = $lng2 * pi() / 180; /* Using the Haversine formula http://en.wikipedia.org/wiki/Haversine_formula calculate the distance */ $calcLongitude = $lng2 - $lng1; $calcLatitude = $lat2 - $lat1; $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2); $stepTwo = 2 * asin(min(1, sqrt($stepOne))); $calculatedDistance = $earthRadius * $stepTwo; return round($calculatedDistance); }
/** * 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 */ }
/** * Calculates the distance (in miles) between two points using the Haversine formula. * * @param array $point1 Array with indices [lat,lng] * @param array $point2 Array with indices [lat,lng] * @return float Distance in miles */ public static function _getLatLngDistance($point1, $point2) { $lat1 = $point1["lat"]; $lng1 = $point1["lng"]; $lat2 = $point2["lat"]; $lng2 = $point2["lng"]; //$earth = 6371; //km change accordingly $earth = 3960; //miles //Point 1 cords $lat1 = deg2rad($lat1); $long1 = deg2rad($lng1); //Point 2 cords $lat2 = deg2rad($lat2); $long2 = deg2rad($lng2); //Haversine Formula $dlong = $long2 - $long1; $dlat = $lat2 - $lat1; $sinlat = sin($dlat / 2); $sinlong = sin($dlong / 2); $a = $sinlat * $sinlat + cos($lat1) * cos($lat2) * ($sinlong * $sinlong); $c = 2 * asin(min(1, sqrt($a))); $d = $earth * $c; return $d; }
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; }
public function inverse($p) { $lon; $lat; $p->x = ($p->x - $this->x0) / $this->a; /* descale and de-offset */ $p->y = ($p->y - $this->y0) / $this->a; $p->x /= $this->k0; $p->y /= $this->k0; if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) { $c = 2.0 * atan2($rho, $this->R2); $sinc = sin($c); $cosc = cos($c); $lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho); $lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc); } else { $lat = $this->phic0; $lon = 0.0; } $p->x = $lon; $p->y = $lat; Proj4php::$proj['gauss']->inverse->apply($this, array($p)); $p->x = Proj4php::$common->adjust_lon($p->x + $this->long0); /* adjust longitude to CM */ return $p; }
/** * @param type $p * @return type */ public function inverse($p) { // descale and de-offset $p->x = ($p->x - $this->x0) / $this->a; $p->y = ($p->y - $this->y0) / $this->a; $p->x /= $this->k0; $p->y /= $this->k0; if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) { $c = 2.0 * atan2($rho, $this->R2); $sinc = sin($c); $cosc = cos($c); $lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho); $lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc); } else { $lat = $this->phic0; $lon = 0.0; } $p->x = $lon; $p->y = $lat; //$p = Proj4php::$proj['gauss']->inverse($p); $p = parent::inverse($p); // adjust longitude to CM $p->x = Common::adjust_lon($p->x + $this->long0); return $p; }
function CircleDraw($lat_one, $long_one, $radius, $datasrc, $time) { //convert from degrees to radians $lat1 = deg2rad($lat_one); $long1 = deg2rad($long_one); $d = $radius; $d_rad = $d / 6378137; $hex = 0xc249255; $color = $datasrc * $hex; $out = "<name>Data Visualization</name>\n"; $out .= "<visibility>1</visibility>\n"; $out .= "<Placemark>\n"; $out .= "<name>Dilution for node " . $datasrc . " at " . $time . "</name>\n"; $out .= "<visibility>1</visibility>\n"; $out .= "<Style>\n"; $out .= "<geomColor>" . dechex($color) . "</geomColor>\n"; $out .= "<geomScale>1</geomScale></Style>\n"; $out .= "<LineString>\n"; $out .= "<coordinates>\n"; // loop through the array and write path linestrings for ($i = 0; $i <= 360; $i++) { $radial = deg2rad($i); $lat_rad = asin(sin($lat1) * cos($d_rad) + cos($lat1) * sin($d_rad) * cos($radial)); $dlon_rad = atan2(sin($radial) * sin($d_rad) * cos($lat1), cos($d_rad) - sin($lat1) * sin($lat_rad)); $lon_rad = fmod($long1 + $dlon_rad + M_PI, 2 * M_PI) - M_PI; $out .= rad2deg($lon_rad) . "," . rad2deg($lat_rad) . ",0 "; } $out .= "</coordinates>\n"; $out .= "</LineString>\n"; $out .= "</Placemark>\n"; return $out; }
public static function getDistance($lat1, $long1, $lat2, $long2, $scale = 'km') { switch (strtolower($scale)) { case 'miles': $earth = 3960; break; case 'km': default: $earth = 6371; break; } //Point 1 cords $lat1 = deg2rad($lat1); $long1 = deg2rad($long1); //Point 2 cords $lat2 = deg2rad($lat2); $long2 = deg2rad($long2); //Haversine Formula $dlong = $long2 - $long1; $dlat = $lat2 - $lat1; $sinlat = sin($dlat / 2); $sinlong = sin($dlong / 2); $a = $sinlat * $sinlat + cos($lat1) * cos($lat2) * ($sinlong * $sinlong); $b = 2 * asin(min(1, sqrt($a))); return $earth * $b; }
function bearing($lat1, $long1, $lat2, $long2) { $args = func_get_args(); list($lat1, $long1, $lat2, $long2) = array_map('deg2rad', $args); $bearing = rad2deg(atan2(asin($long2 - $long1) * cos($lat2), cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($long2 - $long1))); return $bearing < 0 ? 360 + $bearing : $bearing; }
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; }
function Generate($level) { $CI =& get_instance(); $CI->load->library('10/Szogfuggvenyek/Haromszog_tangens', NULL, 'tangens'); $node = 'BC'; $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(asin($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>szinusza</b> a szöggel szembeni befogó ($BC$) és az átfogó ($AB$) hányadosa:' . '$$\\sin\\alpha=\\frac{\\textcolor{blue}{BC}}{\\textcolor{green}{AB}}=' . '\\frac{\\textcolor{blue}{' . $length . '}}{\\textcolor{green}{' . $AB . '}}' . '$$'; $page[] = 'Az $\\alpha$ szöget úgy kapjuk meg, ha a hányados <b>arkusz szinuszát</b> vesszük (ami a szinusz függvény inverze), és az eredményt két tizedesjegyre kerekítjük:$$\\alpha=\\arcsin\\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 szinusz függvény inverzét a <b>sin<sup>-1</sup></b> gomb segítségével lehet kiszámolni:<br />' . '<kbd>' . $length . '</kbd> <kbd>÷</kbd> <kbd>' . $AB . '</kbd> <kbd>=</kbd> <kbd>Shift</kbd> <kbd>sin<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'); }
/** * @return InclinedStringDrawer **/ public function draw($string) { $textWidth = $this->getTextWidth($string); $textHeight = $this->getMaxCharacterHeight(); if ($textWidth < $this->getTuringImage()->getHeight()) { $maxAngle = 45; } else { $maxAngle = rad2deg(asin(($this->getTuringImage()->getHeight() - $textHeight) / $textWidth)); } $angle = mt_rand(-$maxAngle / 2, $maxAngle / 2); if ($angle > self::MAX_ANGLE) { $angle = self::MAX_ANGLE; } if ($angle < -self::MAX_ANGLE) { $angle = -self::MAX_ANGLE; } if ($this->getTuringImage()->getWidth() > $textWidth) { $x = round(($this->getTuringImage()->getWidth() - $textWidth) * cos(deg2rad($angle)) / 2); $y = round(($this->getTuringImage()->getHeight() + $textWidth) * sin(deg2rad($angle)) / 2 + $textHeight / 2); for ($i = 0, $length = strlen($string); $i < $length; ++$i) { $character = $string[$i]; $this->drawCraracter($angle, $x, $y, $character); $charWidth = $this->getStringWidth($character) + $this->getSpace(); $y -= $charWidth * sin(deg2rad($angle)); $x += $charWidth * cos(deg2rad($angle)); } } else { return $this->showError(); } return $this; }
public static function distance(float $latitude1, float $longitude1, float $latitude2, float $longitude2) : float { $dLatitude = ($latitude2 - $latitude1) / 2; $dLongitude = ($longitude2 - $longitude1) / 2; $tmp = sin(deg2rad($dLatitude)) * sin(deg2rad($dLatitude)) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin(deg2rad($dLongitude)) * sin(deg2rad($dLongitude)); $aux = asin(min(1, sqrt($tmp))); return round(12745.9728 * $aux, 4); }
/** *计算某个经纬度的周围某段距离的正方形的四个点 * *@param lng float 经度 *@param lat float 纬度 *@param distance float 该点所在圆的半径,该圆与此正方形内切,默认值为0.5千米 *@return array 正方形的四个点的经纬度坐标 */ public static function returnSquarePoint($lng, $lat, $distance = 0.5) { $dlng = 2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat))); $dlng = rad2deg($dlng); $dlat = $distance / EARTH_RADIUS; $dlat = rad2deg($dlat); return array('left-top' => array('lat' => $lat + $dlat, 'lng' => $lng - $dlng), 'right-top' => array('lat' => $lat + $dlat, 'lng' => $lng + $dlng), 'left-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng - $dlng), 'right-bottom' => array('lat' => $lat - $dlat, 'lng' => $lng + $dlng)); }
/** * Function to eliminate roundoff errors in asin * * @param type $x * @return type */ protected function asinz($x) { return asin(abs($x) > 1.0 ? $x > 1.0 ? 1.0 : -1.0 : $x); //if( abs( $x ) > 1.0 ) { // $x = ($x > 1.0) ? 1.0 : -1.0; //} //return asin( $x ); }
/** *计算某个经纬度的周围某段距离的正方形的四个点 * *@param lon float 经度 *@param lat float 纬度 *@param distance float 该点所在圆的半径,该圆与此正方形内切,默认值为0.5千米 *@return array 正方形的四个点的经纬度坐标 */ function returnSquarePoint($lon, $lat, $distance = 10) { $dlon = 2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat))); $dlon = rad2deg($dlon); $dlat = $distance / EARTH_RADIUS; $dlat = rad2deg($dlat); return array('left-top' => array('lat' => $lat + $dlat, 'lon' => $lon - $dlon), 'right-top' => array('lat' => $lat + $dlat, 'lon' => $lon + $dlon), 'left-bottom' => array('lat' => $lat - $dlat, 'lon' => $lon - $dlon), 'right-bottom' => array('lat' => $lat - $dlat, 'lon' => $lon + $dlon)); }
protected function getLongitudeKeyLength($latitude) { $operand = 2 * sin($this->getRadiansKeySize() / 2) / cos($this->getRadiansByDegree($latitude)); if ($operand > M_PI / 2) { return 1; } else { return asin($operand); } }
/** * Get the distance (in KM) of a users position vs a venue * @param type $userLat * @param type $userLong * @param type $venueLat * @param type $venueLong * @return int Returns a user's distance from a venue in KM */ function getDistance($userLat, $userLong, $venueLat, $venueLong) { $dLat = deg2rad($venueLat - $userLat); $dLon = deg2rad($venueLong - $userLong); $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($userLat)) * cos(deg2rad($venueLat)) * sin($dLon / 2) * sin($dLon / 2); $c = 2 * asin(sqrt($a)); $d = EARTH_RADIUS_KM * $c; return $d; }
private static function calculate($from, $to, $earth_radius) { $dLat = deg2rad($to['lat'] - $from['lat']); $dLon = deg2rad($to['lon'] - $from['lon']); $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2rad($from['lat'])) * cos(deg2rad($to['lat'])) * sin($dLon / 2) * sin($dLon / 2); $c = 2 * asin(sqrt($a)); $d = $earth_radius * $c; return ceil($d); }
public static function destination($lat1, $lon1, $brng, $dt, $unit = KM) { $r = self::validateRadius($unit); $lat1 = deg2rad($lat1); $lon1 = deg2rad($lon1); $lat3 = asin(sin($lat1) * cos($dt / $r) + cos($lat1) * sin($dt / $r) * cos(deg2rad($brng))); $lon3 = $lon1 + atan2(sin(deg2rad($brng)) * sin($dt / $r) * cos($lat1), cos($dt / $r) - sin($lat1) * sin($lat3)); return array("LAT" => rad2deg($lat3), "LON" => rad2deg($lon3)); }
/** * Finds a destination given a starting location, bearing and distance. * * @since 2.0 * * @param LatLongValue $startingCoordinates * @param float $bearing The initial bearing in degrees. * @param float $distance The distance to travel in km. * * @return array The destination coordinates, as non-directional floats in an array with lat and lon keys. */ public static function findDestination(LatLongValue $startingCoordinates, $bearing, $distance) { $startingCoordinates = array('lat' => deg2rad($startingCoordinates->getLatitude()), 'lon' => deg2rad($startingCoordinates->getLongitude())); $radBearing = deg2rad((double) $bearing); $angularDistance = $distance / Maps_EARTH_RADIUS; $lat = asin(sin($startingCoordinates['lat']) * cos($angularDistance) + cos($startingCoordinates['lat']) * sin($angularDistance) * cos($radBearing)); $lon = $startingCoordinates['lon'] + atan2(sin($radBearing) * sin($angularDistance) * cos($startingCoordinates['lat']), cos($angularDistance) - sin($startingCoordinates['lat']) * sin($lat)); return array('lat' => rad2deg($lat), 'lon' => rad2deg($lon)); }
function haversine($lat1, $long1, $lat2, $long2) { $lat1 = deg2rad($lat1); $sinlat1 = sin($lat1); $lat2 = deg2rad($lat2); $long1 = deg2rad($long1); $long2 = deg2rad($long2); return (7926 - 26 * $sinlat1) * asin(min(1, 0.707106781186548 * sqrt(1 - sin($lat2) * $sinlat1 - cos($lat1) * cos($lat2) * cos($long2 - $long1)))); }
/** * Calculate the square point. * At a point as the center point, calculate the square of the four points. * * Result: * ~~~ * [ * 'left-top' => '<float>', * 'right-top' => '<float>', * 'right-bottom' => '<float>', * 'left-bottom' => '<float>', * ] * ~~~ * * @param float $lng * @param float $lat * @param float $distance KM * @return array */ public static function squarePoint($lng, $lat, $distance = 1) { $earthRadius = 6371; $dlng = 2 * asin(sin($distance / (2 * $earthRadius)) / cos(deg2rad($lat))); $dlng = rad2deg($dlng); $dlat = $distance / $earthRadius; $dlat = rad2deg($dlat); return [[$lng - $dlng, $lat + $dlat], [$lng + $dlng, $lat + $dlat], [$lng + $dlng, $lat - $dlat], [$lng - $dlng, $lat - $dlat]]; }
/** * Convert a CEA point back to a geodetic point. * Just returns the array data for initialising a Geodetic point. */ public function inverse(Projected $point) { $x = $point->x - $this->x0; $y = $point->y - $this->y0; $lon = $this->adjustLon($this->long0 + $x / $this->a / cos($this->lat_ts)); $lat = asin($y / $this->a * cos($this->lat_ts)); // The result is given in radians. return ['latrad' => $lat, 'lonrad' => $lon]; }
/** * Given two sets of lat/lon pairs, calculate the distance between them * * Distance defaults to being calculated in kilometers. * * @param mixed $aLon * @param mixed $aLat * @param mixed $bLon * @param mixed $bLat * @param mixed $unit * * @return float */ function calculateDistance($aLon, $aLat, $bLon, $bLat, $unit = KILOMETERS) { $sinHalfDeltaLat = sin(deg2rad($bLat - $aLat) / 2.0); $sinHalfDeltaLon = sin(deg2rad($bLon - $aLon) / 2.0); $lonSqrd = $sinHalfDeltaLon * $sinHalfDeltaLon; $latSqrd = $sinHalfDeltaLat * $sinHalfDeltaLat; $angle = 2 * asin(sqrt($latSqrd + cos(deg2rad($aLat)) * cos(deg2rad($bLat)) * $lonSqrd)); return $unit * $angle; }
/** * {@inheritDoc} */ public function getDistance(Coordinate $from, Coordinate $to) { $diffLatitude = $from->getLatitude() - $to->getLatitude(); $diffLongitude = $from->getLongitude() - $to->getLongitude(); $a = sin($diffLatitude / 2) * sin($diffLatitude / 2) + cos($from->getLatitude()) * cos($to->getLatitude()) * sin($diffLongitude / 2) * sin($diffLongitude / 2); $c = 2 * asin(sqrt($a)); $distance = self::EARTH_RADIUS * $c; return $this->createDistance($distance * 1000); }