本文整理汇总了PHP中rad2deg函数的典型用法代码示例。如果您正苦于以下问题:PHP rad2deg函数的具体用法?PHP rad2deg怎么用?PHP rad2deg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rad2deg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPoint
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;
}
示例2: get_tile_nw
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);
}
示例3: get_nearest_timezone
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';
}
示例4: updateMove
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;
}
示例5: handleSaveImage
/**
* Обработаем создание нового изображения для дальнейшего скачивания пользователем.
*/
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;
}
示例6: estetico_distance
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;
}
}
}
示例7: calculateDistance
/**
* 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;
}
示例8: getAngleSize
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: distance
/**
* 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';
// }
}
示例10: distanceBetween
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;
}
示例11: latitudeRange
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));
}
示例12: boxshadow_filters
/**
* 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;
}
示例13: anglePolar
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];
}
示例14: getRange
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;
}
示例15: approximate
/**
* 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;
}