本文整理汇总了PHP中acos函数的典型用法代码示例。如果您正苦于以下问题:PHP acos函数的具体用法?PHP acos怎么用?PHP acos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acos函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
}
示例2: 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';
// }
}
示例3: 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;
}
示例4: distance
/**
* @get distance from latitude and longitute
*
* @param float $lat_from
* @param float $long_from
* @param float $lat_to
* @param float *long_to
* @param $unit options k, m, n, Default k
*
* @return float
*/
public static function distance($lat_from, $long_from, $lat_to, $long_to, $unit = 'k')
{
/*** distance unit ***/
switch ($unit) {
/*** miles ***/
case 'm':
$unit = 3963;
break;
/*** nautical miles ***/
/*** nautical miles ***/
case 'n':
$unit = 3444;
break;
default:
/*** kilometers ***/
$unit = 6371;
}
/*** 1 degree = 0.017453292519943 radius ***/
$degreeRadius = deg2rad(1);
/*** convert longitude and latitude to radians ***/
$lat_from *= $degreeRadius;
$long_from *= $degreeRadius;
$lat_to *= $degreeRadius;
$long_to *= $degreeRadius;
/*** apply the Great Circle Distance Formula ***/
$dist = sin($lat_from) * sin($lat_to) + cos($lat_from) * cos($lat_to) * cos($long_from - $long_to);
/*** radius of earth * arc cosine ***/
return $unit * acos($dist);
}
示例5: get_bearing
/**
* Get bearing from position to another
*
* Code from http://www.corecoding.com/getfile.php?file=25
*/
static function get_bearing(org_routamc_positioning_spot $from, org_routamc_positioning_spot $to)
{
if (round($from->longitude, 1) == round($to->longitude, 1)) {
if ($from->latitude < $to->latitude) {
$bearing = 0;
} else {
$bearing = 180;
}
} else {
$dist = org_routamc_positioning_utils::get_distance($from, $to, 'N');
$arad = acos((sin(deg2rad($to->latitude)) - sin(deg2rad($from->latitude)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($from->latitude))));
$bearing = $arad * 180 / pi();
if (sin(deg2rad($to->longitude - $from->longitude)) < 0) {
$bearing = 360 - $bearing;
}
}
$dirs = array('N', 'E', 'S', 'W');
$rounded = round($bearing / 22.5) % 16;
if ($rounded % 4 == 0) {
$dir = $dirs[$rounded / 4];
} else {
$dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
$dir .= $dirs[1 + 2 * floor($rounded / 8)];
}
return $dir;
}
示例6: 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';
}
示例7: calculateDistance
public function calculateDistance($lat_from, $long_from, $lat_to, $long_to, $unit = 'k')
{
switch ($unit) {
// miles
case 'm':
$unit = 3963;
break;
// nautical miles
// nautical miles
case 'n':
$unit = 3444;
break;
// kilometers
// kilometers
default:
$unit = 6371;
}
$degreeRadius = deg2rad(1);
$lat_from *= $degreeRadius;
$long_from *= $degreeRadius;
$lat_to *= $degreeRadius;
$long_to *= $degreeRadius;
// apply the Great Circle Distance Formula
$dist = sin($lat_from) * sin($lat_to) + cos($lat_from) * cos($lat_to) * cos($long_from - $long_to);
// radius of earth * arc cosine
return $unit * acos($dist);
}
示例8: getShape
public function getShape()
{
$c = $this->_points[2];
// base
$b = $this->_points[1];
// sides
$a = $this->_points[0];
// calculate angle, cosine rule
$alpha = acos((pow($b, 2) + pow($c, 2) - pow($a, 2)) / (2 * $b * $c));
// pythag to calc height and y distance
$height = abs(sin($alpha)) * $b;
$width = abs(cos($alpha)) * $b;
$x = 0;
// start point
$y = 100;
$points = array($x, $y, $x + $c, $y, $x + $width, $y - $height);
// draw
$image = imagecreatetruecolor(100, 100);
// sets background to red
$white = ImageColorAllocate($image, 255, 255, 255);
ImageFillToBorder($image, 0, 0, $white, $white);
$blue = imagecolorallocate($image, 0, 0, 255);
imagefilledpolygon($image, $points, 3, $blue);
return $image;
}
示例9: 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;
}
示例10: get_bearing
/**
* Get bearing from position to another
*
* Code from http://www.corecoding.com/getfile.php?file=25
*/
function get_bearing($from, $to)
{
if (round($from['longitude'], 1) == round($to['longitude'], 1)) {
if ($from['latitude'] < $to['latitude']) {
$bearing = 0;
} else {
$bearing = 180;
}
} else {
$dist = org_routamc_positioning_utils::get_distance($from, $to, 'N');
$arad = acos((sin(deg2rad($to['latitude'])) - sin(deg2rad($from['latitude'])) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($from['latitude']))));
$bearing = $arad * 180 / pi();
if (sin(deg2rad($to['longitude'] - $from['longitude'])) < 0) {
$bearing = 360 - $bearing;
}
}
$dirs = array("N", "E", "S", "W");
$rounded = round($bearing / 22.5) % 16;
if ($rounded % 4 == 0) {
$dir = $dirs[$rounded / 4];
} else {
$dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
$dir .= $dirs[1 + 2 * floor($rounded / 8)];
}
return $dir;
}
示例11: Generate
function Generate($level)
{
$CI =& get_instance();
$CI->load->library('10/Szogfuggvenyek/Haromszog_tangens', NULL, 'tangens');
$node = 'AC';
$length = rand(ceil($level / 2), $level);
$AB = $length + rand(ceil($level / 2), $level);
$question = 'Az $ABC$ derékszögű háromszög $' . $node . '$ befogója $' . $length . '$ cm, $AB$ átfogója $' . $AB . '$ cm hosszú. Számítsa ki az $ABC$ háromszög hegyesszögeinek nagyságát legalább két tizedesjegy pontossággal!';
$alpha = toDeg(acos($length / $AB));
$beta = 90 - $alpha;
$alphatext = str_replace('.', ',', round($alpha * 100) / 100);
$betatext = str_replace('.', ',', round($beta * 100) / 100);
$correct = array(round1($alpha), round1($beta));
$labels = array('$\\alpha$', '$\\beta$');
$solution = '$\\alpha=' . $alphatext . '°$ és $\\beta=' . $betatext . '°$.';
$hints[][] = 'Rajzoljunk egy derékszögű háromszöget:' . $CI->tangens->Triangle();
$hints[][] = 'Tudjuk, hogy az $\\textcolor{blue}{' . $node . '}$ befogó $' . $length . '$ cm hosszú:' . $CI->tangens->Triangle([$node], [$length], ['blue']);
$hints[][] = 'Tudjuk, hogy az $\\textcolor{green}{AB}$ átfogó $' . $AB . '$ cm hosszú:' . $CI->tangens->Triangle([$node, 'AB'], [$length, $AB], ['blue', 'green']);
$page[] = 'Az $\\alpha$ szög <b>koszinusza</b> a szög melletti befogó ($AC$) és az átfogó ($AB$) hányadosa:' . '$$\\cos\\alpha=\\frac{\\textcolor{blue}{AC}}{\\textcolor{green}{AB}}=' . '\\frac{\\textcolor{blue}{' . $length . '}}{\\textcolor{green}{' . $AB . '}}' . '$$';
$page[] = 'Az $\\alpha$ szöget úgy kapjuk meg, ha a hányados <b>arkusz koszinuszát</b> vesszük (ami a koszinusz függvény inverze), és az eredményt két tizedesjegyre kerekítjük:$$\\alpha=\\arccos\\frac{\\textcolor{blue}{' . $length . '}}{\\textcolor{green}{' . $AB . '}}=' . $alphatext . '°$$';
$page[] = '<b>Megjegyzés</b>: az eredményt a következőképpen lehet kiszámolni számológéppel:
<ol>
<li>Állítsuk be a gépet <b>DEG</b> módba (ha még nem tettük):<br /><kbd>MODE</kbd> <kbd>DEG</kbd></li>
<li>Az koszinusz függvény inverzét a <b>cos<sup>-1</sup></b> gomb segítségével lehet kiszámolni:<br />' . '<kbd>' . $length . '</kbd> <kbd>÷</kbd> <kbd>' . $AB . '</kbd> <kbd>=</kbd> <kbd>Shift</kbd> <kbd>cos<sup>-1</sup></kbd> <kbd>=</kbd></li>
</ol>';
$page[] = 'Tehát az $\\alpha$ szög <span class="label label-success">$' . $alphatext . '°$</span>.';
$hints[] = $page;
$page = [];
$page[] = 'Mivel a háromszög belső szögeinek összege $180°$, ezért a $\\beta$ szöget már könnyen ki lehet számolni:$$\\beta=180°-90°-' . $alphatext . '°$$';
$page[] = 'Tehát a $\\beta$ szög <span class="label label-success">$' . $betatext . '°$</span>.';
$hints[] = $page;
return array('question' => $question, 'correct' => $correct, 'solution' => $solution, 'hints' => $hints, 'labels' => $labels, 'type' => 'array');
}
示例12: isInArea
/**
* Compare two position and return is in area
* @param double $areaLat
* @param double $areaLng
* @param double $radius
* @param double $targetLat
* @param double $targetLng
* @return boolean
*/
public function isInArea($lat1, $lon1, $radius, $lat2, $lon2)
{
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$meter = $miles * 1609.344;
if ($meter <= $radius) {
return true;
} else {
return false;
}
// if ($unit == "K") {
// return ($miles * 1.609344);
// } else if ($unit == "N") {
// return ($miles * 0.8684);
// } else {
// return $miles;
// }
// }
// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "M") . " Miles<br>";
// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "K") . " Kilometers<br>";
// echo distance(32.9697, -96.80322, 29.46786, -98.53506, "N") . " Nautical Miles<br>";
}
示例13: bearing
function bearing($lat1, $lon1, $lat2, $lon2)
{
if (round($lon1, 1) == round($lon2, 1)) {
if ($lat1 < $lat2) {
$bearing = 0;
} else {
$bearing = 180;
}
} else {
$dist = distance($lat1, $lon1, $lat2, $lon2, 'N');
$arad = acos((sin(deg2rad($lat2)) - sin(deg2rad($lat1)) * cos(deg2rad($dist / 60))) / (sin(deg2rad($dist / 60)) * cos(deg2rad($lat1))));
$bearing = $arad * 180 / pi();
if (sin(deg2rad($lon2 - $lon1)) < 0) {
$bearing = 360 - $bearing;
}
}
$dirs = array("N", "E", "S", "W");
$rounded = round($bearing / 22.5) % 16;
if ($rounded % 4 == 0) {
$dir = $dirs[$rounded / 4];
} else {
$dir = $dirs[2 * floor((floor($rounded / 4) + 1) % 4 / 2)];
$dir .= $dirs[1 + 2 * floor($rounded / 8)];
#if ($rounded % 2 == 1)
# $dir = $dirs[round_to_int($rounded/4) % 4] . "-" . $dir;
}
$var_dist = "";
#return $dir;
if (isset($dist)) {
$var_dist = $dist . " miles";
}
return round($bearing, 0) . "º " . $dir . " " . $var_dist;
}
示例14: getDistanceFrom
/**
* Get distance from another position
*
* @param PositionAbstract $position Position to get distance from.
*
* @param string $units Units to return. Default (m) is miles.
* n = nautical miles, k = kilometers,
* f = feet, i = inches.
*
* @param float $adjustment Adjust the distance to take turns into account.
* 1.125 seems to be the most accurate.
*
* @return float Distance in the specified units
*/
public function getDistanceFrom(PositionAbstract $position, $units = 'm', $adjustment = 1.125)
{
$miles = $adjustment * 3959 * acos(cos(deg2rad($this->getLat())) * cos(deg2rad($position->getLat())) * cos(deg2rad($this->getLng()) - deg2rad($position->getLng())) + sin(deg2rad($this->getLat())) * sin(deg2rad($position->getLat())));
switch (strtolower($units)) {
case 'k':
// kilometers
return $miles * 1.609344;
break;
case 'n':
// nautical mile
return $miles * 0.868976242;
break;
case 'f':
// feet
return $miles * 5280;
break;
case 'i':
// inches
return $miles * 63360;
break;
case 'm':
default:
return $miles;
break;
}
}
示例15: distance
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);
}