示例#1
0
/**
 * boxshadow_filters
 * Builds filter properties for IE
 * @return array $filter_properties The new filter properties
 */
function boxshadow_filters($values)
{
    // Get the relevant box shadow value
    global $cssp;
    $value = $cssp->get_final_value($values);
    $filter_properties = array();
    // Build the filter value
    if (preg_match('/([-0-9]+)\\D+([-0-9]+)\\D+([-0-9]+)\\D+#([0-9A-F]{3,6})+/i', trim($value), $matches) == 1) {
        $xoffset = intval($matches[1]);
        $yoffset = intval($matches[2]);
        $blur = intval($matches[3]);
        $color = $matches[4];
        if (strlen($color) == 3) {
            $color = substr($color, 0, 1) . substr($color, 0, 1) . substr($color, 1, 1) . substr($color, 1, 1) . substr($color, 2, 1) . substr($color, 2, 1);
        }
        $median_offset = round((abs($xoffset) + abs($yoffset)) / 2);
        $opacity = $median_offset - $blur > 0 ? ($median_offset - $blur) / $median_offset : 0.05;
        $color_opacity = strtoupper(str_pad(dechex(round(hexdec(substr($color, 0, 2)) * $opacity)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(round(hexdec(substr($color, 2, 2)) * $opacity)), 2, '0', STR_PAD_LEFT) . str_pad(dechex(round(hexdec(substr($color, 4, 2)) * $opacity)), 2, '0', STR_PAD_LEFT));
        // Calculate direction
        $direction = rad2deg(atan2($yoffset, $xoffset * -1));
        // Hard Shadow
        if ($blur == 0) {
            $filter = 'progid:DXImageTransform.Microsoft.dropshadow(OffX=' . $xoffset . ',OffY=' . $yoffset . ',Color=\'#' . strtoupper(str_pad(dechex(round($opacity * 255)), 2, '0', STR_PAD_LEFT)) . $color . '\',Positive=\'true\')';
        } else {
            $filter = 'progid:DXImageTransform.Microsoft.Shadow(Color=\'#' . $color . '\',Direction=' . $direction . ',Strength=' . $median_offset . ')';
        }
        // IE8 compliance (note: value inside apostrophes!)
        $filter_properties['-ms-filter'] = array('"' . $filter . '"');
        // Legacy IE compliance
        $filter_properties['filter'] = array($filter);
        $filter_properties['zoom'] = array('1');
    }
    return $filter_properties;
}
示例#2
0
 /**
  * Get a center latitude,longitude from an array of like geopoints
  *
  * @param array data 2 dimensional array of latitudes and longitudes
  * For Example:
  * $data = array
  * (
  *   0 = > array(45.849382, 76.322333),
  *   1 = > array(45.843543, 75.324143),
  *   2 = > array(45.765744, 76.543223),
  *   3 = > array(45.784234, 74.542335)
  * );
  *
  * Thanks to Gio: http://stackoverflow.com/questions/6671183/calculate-the-center-point-of-multiple-latitude-longitude-coordinate-pairs
  */
 private function getCenterFromDegrees($data)
 {
     if (!is_array($data)) {
         return FALSE;
     }
     $num_coords = count($data);
     $X = 0.0;
     $Y = 0.0;
     $Z = 0.0;
     foreach ($data as $coord) {
         $lat = $coord[0] * pi() / 180;
         $lon = $coord[1] * pi() / 180;
         $a = cos($lat) * cos($lon);
         $b = cos($lat) * sin($lon);
         $c = sin($lat);
         $X += $a;
         $Y += $b;
         $Z += $c;
     }
     $X /= $num_coords;
     $Y /= $num_coords;
     $Z /= $num_coords;
     $lon = atan2($Y, $X);
     $hyp = sqrt($X * $X + $Y * $Y);
     $lat = atan2($Z, $hyp);
     return array($lat * 180 / pi(), $lon * 180 / pi());
 }
示例#3
0
 static function calcBearing($lat1, $lon1, $lat2, $lon2)
 {
     // Input sind Breite/Laenge in Altgrad
     // Der Fall lat/lon1 == lat/lon2 sollte vorher abgefangen werden,
     // zB. ueber die Abfrage der Distanz, dass Bearing nur bei Distanz > 5m
     // geholt wird, sonst = false gesetzt wird...
     if ($lat1 == $lat2 && $lon1 == $lon2) {
         return false;
     } else {
         $pi = 3.141592653589793;
         if ($lat1 == $lat2) {
             $lat1 += 1.66E-5;
         }
         if ($lon1 == $lon2) {
             $lon1 += 1.66E-5;
         }
         $rad_lat1 = $lat1 / 180.0 * $pi;
         $rad_lon1 = $lon1 / 180.0 * $pi;
         $rad_lat2 = $lat2 / 180.0 * $pi;
         $rad_lon2 = $lon2 / 180.0 * $pi;
         $delta_lon = $rad_lon2 - $rad_lon1;
         $bearing = atan2(sin($delta_lon) * cos($rad_lat2), cos($rad_lat1) * sin($rad_lat2) - sin($rad_lat1) * cos($rad_lat2) * cos($delta_lon));
         $bearing = 180.0 * $bearing / $pi;
         // Output Richtung von lat/lon1 nach lat/lon2 in Altgrad von -180 bis +180
         // wenn man Output von 0 bis 360 haben moechte, kann man dies machen:
         if ($bearing < 0.0) {
             $bearing = $bearing + 360.0;
         }
         return $bearing;
     }
 }
示例#4
0
文件: stops.php 项目: hubgit/radibus
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;
}
	/**
	 * ImageResizeFilter::text()
	 * Фильтр - накладывает полупрозрачный текст по диагонали.
	 * 
	 * @param mixed $arrParams
	 * @return void
	 */
	private static function text($arrParams) {

		$objImg = imagecreatefromjpeg(self::$strFile);	
		
	    //получаем ширину и высоту исходного изображения
	    $intWidth = imagesx($objImg);
	    $intHeight = imagesy($objImg);
	    
	    //угол поворота текста
	    $intAngle =  -rad2deg(atan2((-$intHeight),($intWidth))); 

	    //добавляем пробелы к строке
	    $strText = ' '.$arrParams['text'].' ';
	 
	    $intColor = imagecolorallocatealpha($objImg, $arrParams['red'], $arrParams['green'], $arrParams['blue'], $arrParams['alpha']);
	    
	    $intSize = (($intWidth + $intHeight) / 2) * 2 / strlen($strText);
	    $arrBox  = imagettfbbox($intSize, $intAngle, $arrParams['font'], $strText);
	    $intX = $intWidth / 2 - abs($arrBox[4] - $arrBox[0]) / 2;
	    $intY = $intHeight / 2 + abs($arrBox[5] - $arrBox[1]) / 2;
	 
	    //записываем строку на изображение
	    imagettftext($objImg, $intSize ,$intAngle, $intX, $intY, $intColor, $arrParams['font'], $strText);
	    
	    imagejpeg($objImg, self::$strFile, 100);
	    
	    imagedestroy($objImg);
		
	}//\\ text
function eposr_calculate_distance()
{
    if (!session_id()) {
        session_start();
    }
    $_SESSION['location'] = array('lat' => $_POST['us2_lat'], 'lon' => $_POST['us2_lon'], 'address' => $_POST['us2_address']);
    $_SESSION['order_type'] = "delivery";
    //
    $lat1 = $_SESSION['location']['lat'];
    $lng1 = $_SESSION['location']['lon'];
    //Latitude and longitude set by restaurant on the admin panel setting
    $lat2 = esc_attr(get_option('restaurant_lat'));
    $lng2 = esc_attr(get_option('restaurant_lon'));
    $pi80 = M_PI / 180;
    $lat1 *= $pi80;
    $lng1 *= $pi80;
    $lat2 *= $pi80;
    $lng2 *= $pi80;
    $r = 6372.797;
    // mean radius of Earth in km
    //for whitton
    $wlat = $lat2 - $lat1;
    $wlng = $lng2 - $lng1;
    $w = sin($wlat / 2) * sin($wlat / 2) + cos($lat1) * cos($lat2) * sin($wlng / 2) * sin($wlng / 2);
    $wc = 2 * atan2(sqrt($w), sqrt(1 - $w));
    $wkm = $r * $wc;
    if ((double) ($wkm * 1000) <= (double) esc_attr(get_option('delivery_radius'))) {
        echo 'accessible';
        die;
    } else {
        echo 'not accessible';
        die;
    }
}
示例#7
0
文件: mandel.php 项目: lleaff/Backito
function mandel($params)
{
    $image_x = 4 * $params['w'];
    $image_y = 4 * $params['h'];
    $image = imagecreatetruecolor($image_x, $image_y);
    imagefilledrectangle($image, 0, 0, $image_x, $image_y, 0xffffff);
    $f = imagecolorallocate($image, $params['r'], $params['g'], $params['b']);
    $color = color($params, $image);
    for ($x = 0; $x < $image_x; $x++) {
        for ($y = 0; $y < $image_y; $y++) {
            $c_r = $x / $params['w'] + -2;
            $c_i = $y / $params['h'] + -2;
            $z_r = 0;
            $z_i = 0;
            $i = 0;
            while ($z_r * $z_r + $z_i * $z_i < 4 and $i < $params['n']) {
                $mod = sqrt($z_r * $z_r + $z_i * $z_i);
                $arg = atan2($z_i, $z_r);
                $z_r = pow($mod, $params['k']) * cos($params['k'] * $arg) + $c_r;
                $z_i = pow($mod, $params['k']) * sin($params['k'] * $arg) + $c_i;
                $i++;
            }
            if ($i == $params['n']) {
                imagesetpixel($image, $x, $y, $f);
            } else {
                imagesetpixel($image, $x, $y, $color[$i]);
            }
        }
    }
    return send_image($image);
}
示例#8
0
 public function getAngleSize(AngleInterface $angle, AngleSizeUnitsEnum $angleSizeUnit = null)
 {
     $BA = $angle->getFirstVector();
     $BC = $angle->getLastVector();
     $A = $BA->getLastPoint();
     $B = $BA->getFirstPoint();
     $C = $BC->getLastPoint();
     $Ax = $A->getX();
     $Ay = $A->getY();
     $Bx = $B->getX();
     $By = $B->getY();
     $Cx = $C->getX();
     $Cy = $C->getY();
     $coordSumBAx = $Ax - $Bx;
     $coordSumBAy = $Ay - $By;
     $coordSumBCx = $Cx - $Bx;
     $coordSumBCy = $Cy - $By;
     $x1 = $coordSumBCx;
     $x2 = $coordSumBAx;
     $y1 = $coordSumBCy;
     $y2 = $coordSumBAy;
     $res = $rads = atan2($x1 * $y2 - $y1 * $x2, $x1 * $x2 + $y1 * $y2);
     if (empty($angleSizeUnit)) {
         $angleSizeUnit = $this->getAngleSizeUnit();
     }
     if ($angleSizeUnit->getTypeName() === AngleSizeUnitsEnum::DEG) {
         $res = rad2deg($rads);
         if ($res < 0) {
             $res = $res + 360;
         }
     }
     return new AngleSize($angleSizeUnit, $res);
 }
示例#9
0
文件: sterea.php 项目: Tjoosten/input
 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;
 }
示例#10
0
 function distance($zip1, $zip2)
 {
     $url = parse_url(getenv("CLEARDB_DATABASE_URL"));
     $server = $url["host"];
     $user = $url["user"];
     $pass = $url["pass"];
     $database = substr($url["path"], 1);
     $db = new PDO("mysql:host={$server};dbname={$database};charset=utf8", $user, $pass);
     $stmt = $db->prepare('SELECT * FROM zip WHERE zip = :zip1;');
     $stmt->bindParam(':zip1', $zip1);
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $lat1 = $result[0]["latitude"];
     $lon1 = $result[0]["longitude"];
     $stmt = $db->prepare('SELECT * FROM zip WHERE zip = :zip2;');
     $stmt->bindParam(':zip2', $zip2);
     $stmt->execute();
     $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
     $lat2 = $result[0]['latitude'];
     $lon2 = $result[0]['longitude'];
     /* Convert all the degrees to radians */
     $lat1 = $this->deg_to_rad($lat1);
     $lon1 = $this->deg_to_rad($lon1);
     $lat2 = $this->deg_to_rad($lat2);
     $lon2 = $this->deg_to_rad($lon2);
     /* Find the deltas */
     $delta_lat = $lat2 - $lat1;
     $delta_lon = $lon2 - $lon1;
     /* Find the Great Circle distance */
     $temp = pow(sin($delta_lat / 2.0), 2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon / 2.0), 2);
     $EARTH_RADIUS = 3956;
     $distance = $EARTH_RADIUS * 2 * atan2(sqrt($temp), sqrt(1 - $temp));
     return $distance;
 }
示例#11
0
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 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'])));
 }
示例#13
0
 public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC)
 {
     if ($this->attackTime > 0) {
         $lastCause = $this->getLastDamageCause();
         if ($lastCause instanceof EntityDamageEvent and $lastCause->getDamage() >= $damage) {
             return;
         }
     }
     $pk = new EntityEventPacket();
     $pk->eid = $this->getID();
     $pk->event = 2;
     //Ouch!
     Server::broadcastPacket($this->hasSpawned, $pk);
     $this->setLastDamageCause($source);
     $motion = new Vector3(0, 0, 0);
     if ($source instanceof EntityDamageByEntityEvent) {
         $e = $source->getDamager();
         $deltaX = $this->x - $e->x;
         $deltaZ = $this->z - $e->z;
         $yaw = atan2($deltaX, $deltaZ);
         $motion->x = sin($yaw) * 0.5;
         $motion->z = cos($yaw) * 0.5;
     }
     $this->setMotion($motion);
     $this->setHealth($this->getHealth() - $damage);
     $this->attackTime = 10;
     //0.5 seconds cooldown
 }
示例#14
0
 /**
  * @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;
 }
示例#15
0
 public function updateMove()
 {
     if (!$this->isMovement()) {
         return null;
     }
     $target = null;
     if ($this->stayTime > 0) {
         $this->move(0, 0);
         if (--$this->stayTime <= 0) {
             $this->stayVec = null;
         }
     } else {
         $target = $this->getTarget();
         $x = $target->x - $this->x;
         $y = $target->y - $this->y;
         $z = $target->z - $this->z;
         $speed = [Zombie::NETWORK_ID => 0.11, Creeper::NETWORK_ID => 0.09, Skeleton::NETWORK_ID => 0.1, Spider::NETWORK_ID => 0.113, PigZombie::NETWORK_ID => 0.115, Enderman::NETWORK_ID => 0.121];
         $add = $this instanceof PigZombie && $this->isAngry() ? 0.132 : $speed[static::NETWORK_ID];
         $this->move(cos($atn = atan2($z, $x)) * $add, sin($atn) * $add);
         $this->yaw = rad2deg($atn - M_PI_2);
         $this->pitch = $y == 0 ? 0 : rad2deg(-atan2($y, sqrt($x ** 2 + $z ** 2)));
     }
     $this->updateMovement();
     return $target;
 }
示例#16
0
文件: rasp.php 项目: nbald/RASP-User
function direction($u, $v, $good)
{
    $stringNum = array("N" => 0, "NNE" => 2, "NE" => 4, "ENE" => 6, "E" => 8, "ESE" => 10, "SE" => 12, "SSE" => 14, "S" => 16, "SSO" => 18, "SO" => 20, "OSO" => 22, "O" => 24, "ONO" => 26, "NO" => 28, "NNO" => 30);
    $dirString = array(0 => "N", 1 => "NNE", 2 => "NNE", 3 => "NE", 4 => "NE", 5 => "ENE", 6 => "ENE", 7 => "E", 8 => "E", 9 => "ESE", 10 => "ESE", 11 => "SE", 12 => "SE", 13 => "SSE", 14 => "SSE", 15 => "S", 16 => "S", 17 => "SSO", 18 => "SSO", 19 => "SO", 20 => "SO", 21 => "OSO", 22 => "OSO", 23 => "O", 24 => "O", 25 => "ONO", 26 => "ONO", 27 => "NO", 28 => "NO", 29 => "NNO", 30 => "NNO", 31 => "N", 32 => "N");
    $dir = (atan2($u, $v) / pi() + 1) * 180;
    $dirSecteur = round($dir / 11.25);
    $goods = str_getcsv($good);
    //var_dump($goods);
    $col = "white";
    foreach ($goods as $good) {
        //echo $good . '?';
        if ($good != '') {
            $num = $stringNum[$good];
            // echo 'ref='.$num.' et wind='.$dirSecteur . '! ';
            //je n'arrive pas Ó bien formuler l'intervalle sur mes numÚros de secteur
            if ($num + 3 >= $dirSecteur and $num - 3 <= $dirSecteur) {
                $col = "lightgreen";
            }
            if ($num == 0) {
                if ($dirSecteur == 31 or $dirSecteur == 30 or $dirSecteur == 29) {
                    $col = "lightgreen";
                }
            }
            if ($num == 1) {
                if ($dirSecteur == 31) {
                    $col = "lightgreen";
                }
            }
        }
    }
    print "<td bgcolor='" . $col . "'>" . $dirString[$dirSecteur] . "</td>";
}
示例#17
0
function bearing($lat1, $lon1, $lat2, $lon2)
{
    // Inspiration thanks to http://www.movable-type.co.uk/scripts/LatLong.html
    $dlong = ($lon2 - $lon1) * M_PI / 180.0;
    $lat1 = $lat1 * M_PI / 180.0;
    $lat2 = $lat2 * M_PI / 180.0;
    return 180 / M_PI * atan2(sin($dlong) * cos($lat2), cos($lat1) * sin($lat2) - sin($lat1) * cos($lat2) * cos($dlong));
}
示例#18
0
 /**
  * @link http://en.wikipedia.org/wiki/Vincenty%27s_formulae
  * @param AbstractCoordinate $coordinateA
  * @param AbstractCoordinate $coordinateB
  * @return float distance in meters
  */
 public function getDistance(AbstractCoordinate $coordinateA, AbstractCoordinate $coordinateB)
 {
     $lonDelta = $coordinateB->getRadianLongitude() - $coordinateA->getRadianLongitude();
     $a = pow(cos($coordinateB->getRadianLatitude()) * sin($lonDelta), 2) + pow(cos($coordinateA->getRadianLatitude()) * sin($coordinateB->getRadianLatitude()) - sin($coordinateA->getRadianLatitude()) * cos($coordinateB->getRadianLatitude()) * cos($lonDelta), 2);
     $b = sin($coordinateA->getRadianLatitude()) * sin($coordinateB->getRadianLatitude()) + cos($coordinateA->getRadianLatitude()) * cos($coordinateB->getRadianLatitude()) * cos($lonDelta);
     $angle = atan2(sqrt($a), $b);
     return $this->process($angle * $this->radius);
 }
示例#19
0
 private static function haversineDistance($lat1, $lon1, $lat2, $lon2)
 {
     $latd = deg2rad($lat2 - $lat1);
     $lond = deg2rad($lon2 - $lon1);
     $a = sin($latd / 2) * sin($latd / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($lond / 2) * sin($lond / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return 6371.0 * $c;
 }
示例#20
0
function calculateBearing($lat1, $long1, $lat2, $long2)
{
    $y = $lat2 - $lat1;
    $x = $long2 - $long1;
    if ($x == 0 and $y == 0) {
        return 0;
    }
    return $x < 0 ? rad2deg(atan2($x, $y)) + 360 : rad2deg(atan2($x, $y));
}
示例#21
0
 private function rotate(&$x, &$y, $angle)
 {
     if ($angle != 0) {
         $r = sqrt($x * $x + $y * $y);
         $angle = deg2rad($angle) - atan2($y, $x);
         $x = $r * cos($angle);
         $y = $r * sin($angle);
     }
 }
示例#22
0
 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));
 }
 function getDistance($lat1, $lat2, $long1, $long2)
 {
     $radiusEarth = 6371;
     $lat = deg2rad($lat2 - $lat1);
     $lng = deg2rad($long2 - $long1);
     $a = pow(sin($lat / 2), 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin($lng), 2);
     $c = 2 * atan2(sqrt($a), sqrt(abs($lng / 2)));
     return $radiusEarth * $c / 1.609344;
 }
示例#24
0
 /**
  * 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));
 }
示例#25
0
文件: W2Map.php 项目: alonexy/lea
 /**
  *
  * 根据经纬度计算距离
  * @param float $lng1 经度1
  * @param float $lat1 纬度2
  * @param float $lng2 经度1
  * @param float $lat2 纬度2
  * @return float      单位(公里 KM)
  */
 public static function getdistance($lng1, $lat1, $lng2, $lat2)
 {
     $r = W2Map::EARTH_RADIUS;
     $dlat = deg2rad($lat2 - $lat1);
     $dlng = deg2rad($lng2 - $lng1);
     $a = pow(sin($dlat / 2), 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * pow(sin($dlng / 2), 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return round($r * $c, 2);
 }
示例#26
0
 private function getDistance($lngOne, $latOne, $lngTwo, $latTwo)
 {
     $dlat = deg2rad($latTwo - $latOne);
     $dlng = deg2rad($lngTwo - $lngOne);
     $disA = pow(sin($dlat / 2), 2) + cos(deg2rad($latOne)) * cos(deg2rad($latTwo)) * pow(sin($dlng / 2), 2);
     $disB = 2 * atan2(sqrt($disA), sqrt(1 - $disA));
     $proDistance = $this->earth * $disB;
     return sprintf('%.2f', $proDistance) . 'KM';
 }
示例#27
0
文件: Geolocation.php 项目: zedx/core
 protected function _haversine($lat1, $long1, $lat2, $long2, $R = '6367.5')
 {
     $delta_lat = deg2rad($lat2 - $lat1);
     $delta_long = deg2rad($long2 - $long1);
     $a = sin($delta_lat / 2) * sin($delta_lat / 2) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin($delta_long / 2) * sin($delta_long / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $d = $R * $c;
     return $d;
 }
示例#28
0
 public function getDistanceTo(GeoPointValue $point)
 {
     $dLat = deg2rad($point->getLatitude() - $this->getLatitude());
     $dLon = deg2rad($point->getLongitude() - $this->getLongitude());
     $lat1 = deg2rad($this->getLatitude());
     $lat2 = deg2rad($point->getLatitude());
     $a = sin($dLat / 2) * sin($dLat / 2) + sin($dLon / 2) * sin($dLon / 2) * cos($lat1) * cos($lat2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return $c * static::EARTH_RADIUS;
 }
示例#29
0
 /**
  * @param $x1
  * @param $x2
  * @param $y1
  * @param $y2
  * @return int
  */
 private static function distance($x1, $x2, $y1, $y2)
 {
     $R = 6371;
     // km
     $dY = deg2rad($y2 - $y1);
     $dX = deg2rad($x2 - $x1);
     $a = sin($dY / 2) * sin($dY / 2) + cos(deg2rad($y1)) * cos(deg2rad($y2)) * sin($dX / 2) * sin($dY / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return $R * $c;
 }
示例#30
0
 /**
  * Calculate the distance between two
  * points using the Haversine formula.
  *
  * Supply instances of the coordinate class.
  * 
  * http://en.wikipedia.org/wiki/Haversine_formula
  *
  * @param Treffynnon\Navigator\Coordinate $point1
  * @param Treffynnon\Navigator\Coordinate $point2
  * @return float
  */
 public function calculate(N\LatLong $point1, N\LatLong $point2)
 {
     $celestialBody = $this->getCelestialBody();
     $deltaLat = $point2->getLatitude()->get() - $point1->getLatitude()->get();
     $deltaLong = $point2->getLongitude()->get() - $point1->getLongitude()->get();
     $a = sin($deltaLat / 2) * sin($deltaLat / 2) + cos($point1->getLatitude()->get()) * cos($point2->getLatitude()->get()) * sin($deltaLong / 2) * sin($deltaLong / 2);
     $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
     $d = $celestialBody->volumetricMeanRadius * $c * 1000;
     return $d;
 }