function getPoint($xtile, $ytile, $zoom)
{
    $n = pow(2, $zoom);
    $lon_deg = $xtile / $n * 360.0 - 180.0;
    $lat_deg = rad2deg(atan(sinh(pi() * (1 - 2 * $ytile / $n))));
    return $lon_deg . "," . $lat_deg;
}
Example #2
0
 public static function get_tile_nw($xtile, $ytile, $zoom)
 {
     $n = pow(2, $zoom);
     $lon = $xtile / $n * 360.0 - 180.0;
     $lat = rad2deg(atan(sinh(pi() * (1 - 2 * $ytile / $n))));
     return array($lat, $lon);
 }
 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';
 }
Example #4
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;
 }
 /**
  * Обработаем создание нового изображения для дальнейшего скачивания пользователем.
  */
 private function handleSaveImage()
 {
     $items = $_POST['items'];
     $category = $_POST['cat'];
     $image = $_POST['img'];
     $fileName = Image::getName($category, $image);
     $Palette = new RGB();
     $Imagine = new Imagine();
     $Image = $Imagine->open(IMG_1920x1080 . $fileName);
     foreach ($items as $item) {
         $text = $item['text'];
         $fontSize = $item['fontSize'];
         $x = $item['relativeX'];
         $y = $item['relativeY'];
         $sizedFontSize = $fontSize * 1920 / 500;
         $sizedX = $this->coeffX * $x;
         $sizedY = $this->coeffY * $y;
         $Font = $Imagine->font(FONT_DIR . 'Arial.ttf', $sizedFontSize, $Palette->color($item['color']));
         $Position = new Point($sizedX, $sizedY);
         $angle = rad2deg($item['angle']);
         $Image->draw()->text($text, $Font, $Position, $angle);
     }
     $id = uniqid();
     $filePath = IMG_DOWNLOAD . $id . Image::EXTENSION;
     $Image->save($filePath);
     header('Content-Type: application/json; charset=utf8');
     echo json_encode(['id' => $id], JSON_UNESCAPED_UNICODE);
     exit;
 }
Example #6
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;
        }
    }
}
Example #7
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;
 }
 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);
 }
 /**
  * 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';
     //        }
 }
Example #10
0
 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;
 }
Example #11
0
 public static function latitudeRange($latitude, $longitude, $distance)
 {
     // Estimate the min and max latitudes within $distance of a given location.
     $long = deg2rad($longitude);
     $lat = deg2rad($latitude);
     $radius = self::earthRadius($latitude);
     $angle = $distance / $radius;
     $minlat = $lat - $angle;
     $maxlat = $lat + $angle;
     $rightangle = pi() / 2;
     if ($minlat < -$rightangle) {
         // wrapped around the south pole
         $overshoot = -$minlat - $rightangle;
         $minlat = -$rightangle + $overshoot;
         if ($minlat > $maxlat) {
             $maxlat = $minlat;
         }
         $minlat = -$rightangle;
     }
     if ($maxlat > $rightangle) {
         // wrapped around the north pole
         $overshoot = $maxlat - $rightangle;
         $maxlat = $rightangle - $overshoot;
         if ($maxlat < $minlat) {
             $minlat = $maxlat;
         }
         $maxlat = $rightangle;
     }
     return array(rad2deg($minlat), rad2deg($maxlat));
 }
Example #12
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;
}
 static function anglePolar($pointA, $pointB, $pointC)
 {
     if (!isset(self::$anglePolarTable[$pointA->guid . ';' . $pointB->guid . ';' . $pointC->guid])) {
         $Ax = $pointA->x - $pointB->x;
         $Ay = $pointA->y - $pointB->y;
         $Cx = $pointC->x - $pointB->x;
         $Cy = $pointC->y - $pointB->y;
         if ($Ax <= 0 && pow($Ay, 2) == 0) {
             $Apolar = 180;
         } else {
             $Apolar = rad2deg(2 * atan($Ay / ($Ax + sqrt(pow($Ax, 2) + pow($Ay, 2)))));
         }
         if ($Cx + sqrt(pow($Cx, 2) + pow($Cy, 2)) == 0) {
             $Cpolar = 180;
         } else {
             $Cpolar = rad2deg(2 * atan($Cy / ($Cx + sqrt(pow($Cx, 2) + pow($Cy, 2)))));
         }
         $result = $Cpolar - $Apolar;
         if ($result < 0) {
             $result += 360;
         }
         self::$anglePolarTable[$pointA->guid . ';' . $pointB->guid . ';' . $pointC->guid] = $result;
     }
     return self::$anglePolarTable[$pointA->guid . ';' . $pointB->guid . ';' . $pointC->guid];
 }
Example #14
0
 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;
 }
Example #15
0
 /**
  * Approximates a quadratic Bézier curve given the start point, a control
  * point, and the end point.
  *
  * All of the points, both input and output, are provided as arrays with
  * floats where [0 => x coordinate, 1 => y coordinate].
  *
  * @param float[] $p0 The start point (x0, y0).
  * @param float[] $p1 The end point (x1, y1).
  * @param bool    $fa The large arc flag.
  * @param bool    $fs The sweep flag.
  * @param float   $rx The x radius.
  * @param float   $ry The y radius.
  * @param float   $xa The x-axis angle / the ellipse's rotation (radians).
  *
  * @return array[] An approximation for the curve, as an array of points.
  */
 public function approximate($p0, $p1, $fa, $fs, $rx, $ry, $xa)
 {
     $rx = abs($rx);
     $ry = abs($ry);
     $xa = fmod($xa, M_PI * 2);
     if ($xa < 0) {
         $xa += M_PI * 2;
     }
     // out-of-range parameter handling according to W3; see
     // https://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
     if ($p0[0] == $p1[0] && $p0[1] == $p1[1]) {
         // arc with equal points is treated as nonexistent
         return array();
     } elseif ($rx == 0 || $ry == 0) {
         // arc with no radius is treated as straight line
         return array($p0, $p1);
     }
     $params = self::endpointToCenter($p0, $p1, $fa, $fs, $rx, $ry, $xa);
     list($center, $angleStart, $angleDelta) = $params;
     // TODO implement better calculation for $numSteps
     // It would be better if we had access to the rasterization scale for
     // this, otherwise there is no way to make this accurate for every zoom
     $dist = abs($p0[0] - $p1[0]) + abs($p0[1] - $p1[1]);
     $numSteps = max(8, ceil(rad2deg($angleDelta) * $dist / 1000));
     $stepSize = $angleDelta / $numSteps;
     $points = array();
     for ($i = 0; $i <= $numSteps; ++$i) {
         $angle = $angleStart + $stepSize * $i;
         $points[] = self::calculatePoint($center, $rx, $ry, $xa, $angle);
     }
     return $points;
 }
Example #16
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;
     }
 }
Example #17
0
 /**
  * Get a string representation of the coordinate in DMS notation
  * @param float $coord
  * @return string
  */
 public function get($coord)
 {
     $coord = rad2deg($coord);
     $degrees = (int) $coord;
     $compass = '';
     if ($this->direction == N::LAT) {
         if ($degrees < 0) {
             $compass = '******';
         } elseif ($degrees > 0) {
             $compass = '******';
         }
     } elseif ($this->direction == N::LONG) {
         if ($degrees < 0) {
             $compass = '******';
         } elseif ($degrees > 0) {
             $compass = '******';
         }
     }
     $minutes = $coord - $degrees;
     if ($minutes < 0) {
         $minutes -= 2 * $minutes;
     }
     if ($degrees < 0) {
         $degrees -= 2 * $degrees;
     }
     $minutes = $minutes * 60;
     $seconds = $minutes - (int) $minutes;
     $minutes = (int) $minutes;
     $seconds = (double) $seconds * 60;
     $coordinate = sprintf($this->output_format, $degrees, $minutes, $seconds, $compass);
     return $coordinate;
 }
Example #18
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 */
 }
Example #19
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>";
 }
Example #20
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;
}
 /**
  * @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;
 }
Example #22
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);
 }
Example #23
0
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
Example #25
0
 /**
  * 计算某个经纬度的周围某段距离的正方形的四个点
  *
  * @param lng float 经度
  * @param lat float 纬度
  * @param distance float 该点所在圆的半径,该圆与此正方形内切,默认值为0.5千米
  * @return array 正方形的四个点的经纬度坐标
  */
 public function squarePoint($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 _distance($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 * 111.18957696;
}
Example #27
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;
 }
function rad2dms($rad)
{
    $decdeg = rad2deg($rad);
    $degrees = floor(abs($decdeg));
    $minutes = floor((abs($decdeg) - $degrees) * 60);
    $seconds = round((abs($decdeg) - $degrees - $minutes / 60.0) * 3600);
    return ($rad < 0 ? '-' : '') . $degrees . "°" . str_pad($minutes, 2, '0', STR_PAD_LEFT) . "'" . str_pad($seconds, 2, '0', STR_PAD_LEFT) . "\"";
}
Example #29
0
/**
 *计算某个经纬度的周围某段距离的正方形的四个点
 *
 *@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));
}
Example #30
0
 /**
  * @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);
 }