function __construct($NAME = NULL, $DESCRIPTION = NULL, $LONG = NULL, $LAT = NULL, $ALT = NULL, $HEAD = NULL, $TILT = NULL, $RANGE = NULL) { $this->NAME = is_null($NAME) ? "Building and Wall" : $NAME; $this->DESCRIPTION = is_null($DESCRIPTION) ? "Building and Wall share textures" : $DESCRIPTION; $this->LONG = is_null($LONG) ? "-79.37380981445312" : $LONG; $this->LAT = is_null($LAT) ? "43.656211853027344" : $LAT; $this->ALT = is_null($ALT) ? "311" : $ALT; $this->HEAD = is_null($HEAD) ? "-40.34248730008207" : $HEAD; $this->TILT = is_null($TILT) ? "34.9531454664821" : $TILT; $this->RANGE = is_null($RANGE) ? "50.90180128676323" : $RANGE; $this->RADIAN = 180 / pi(); //create the xml document $this->xmlDoc = new DOMDocument('1.0', 'UTF-8'); $kml = $this->xmlDoc->appendChild($this->xmlDoc->createElementNS('http://www.opengis.net/kml/2.2', 'kml')); //create the root element $this->folTag = $kml->appendChild($this->xmlDoc->createElement("Folder")); $this->folTag->appendChild($this->xmlDoc->createElement("name", $this->NAME)); $this->folTag->appendChild($this->xmlDoc->createElement("description", $this->DESCRIPTION)); $lokTag = $this->folTag->appendChild($this->xmlDoc->createElement("Camera")); $lokTag->appendChild($this->xmlDoc->createElement("longitude", $this->LONG)); $lokTag->appendChild($this->xmlDoc->createElement("latitude", $this->LAT)); $lokTag->appendChild($this->xmlDoc->createElement("altitude", $this->ALT)); $lokTag->appendChild($this->xmlDoc->createElement("heading", $this->HEAD)); $lokTag->appendChild($this->xmlDoc->createElement("tilt", $this->TILT)); $lokTag->appendChild($this->xmlDoc->createElement("range", $this->RANGE)); }
/** * Convert this UTM reference to a latitude and longitude * * @return the converted latitude and longitude */ function toLatLng() { $wgs84 = new ReferenceEllipsoid(ReferenceEllipsoid::WGS84_MAJ, ReferenceEllipsoid::WGS84_MIN); $UTM_F0 = 0.9996; $a = $wgs84->maj; $eSquared = $wgs84->ecc; $ePrimeSquared = $eSquared / (1.0 - $eSquared); $e1 = (1 - sqrt(1 - $eSquared)) / (1 + sqrt(1 - $eSquared)); $x = $this->easting - 500000.0; $y = $this->northing; $zoneNumber = $this->lngZone; $zoneLetter = $this->latZone; $longitudeOrigin = ($zoneNumber - 1.0) * 6.0 - 180.0 + 3.0; // Correct y for southern hemisphere if (ord($zoneLetter) - ord("N") < 0) { $y -= 10000000.0; } $m = $y / $UTM_F0; $mu = $m / ($a * (1.0 - $eSquared / 4.0 - 3.0 * $eSquared * $eSquared / 64.0 - 5.0 * pow($eSquared, 3.0) / 256.0)); $phi1Rad = $mu + (3.0 * $e1 / 2.0 - 27.0 * pow($e1, 3.0) / 32.0) * sin(2.0 * $mu) + (21.0 * $e1 * $e1 / 16.0 - 55.0 * pow($e1, 4.0) / 32.0) * sin(4.0 * $mu) + 151.0 * pow($e1, 3.0) / 96.0 * sin(6.0 * $mu); $n = $a / sqrt(1.0 - $eSquared * sin($phi1Rad) * sin($phi1Rad)); $t = tan($phi1Rad) * tan($phi1Rad); $c = $ePrimeSquared * cos($phi1Rad) * cos($phi1Rad); $r = $a * (1.0 - $eSquared) / pow(1.0 - $eSquared * sin($phi1Rad) * sin($phi1Rad), 1.5); $d = $x / ($n * $UTM_F0); $latitude = ($phi1Rad - $n * tan($phi1Rad) / $r * ($d * $d / 2.0 - (5.0 + 3.0 * $t + 10.0 * $c - 4.0 * $c * $c - 9.0 * $ePrimeSquared) * pow($d, 4.0) / 24.0 + (61.0 + 90.0 * $t + 298.0 * $c + 45.0 * $t * $t - 252.0 * $ePrimeSquared - 3.0 * $c * $c) * pow($d, 6.0) / 720.0)) * (180.0 / pi()); $longitude = $longitudeOrigin + ($d - (1.0 + 2.0 * $t + $c) * pow($d, 3.0) / 6.0 + (5.0 - 2.0 * $c + 28.0 * $t - 3.0 * $c * $c + 8.0 * $ePrimeSquared + 24.0 * $t * $t) * pow($d, 5.0) / 120.0) / cos($phi1Rad) * (180.0 / pi()); return new LatLng($latitude, $longitude); }
static function metersToLatLon($mx, $my) { $lng = $mx / self::originShift() * 180.0; $lat = $my / self::originShift() * 180.0; $lat = 180 / pi() * (2 * atan(exp($lat * pi() / 180.0)) - pi() / 2.0); return new GoogleMapPoint($lat, $lng); }
function TrueSolarTime($Hours, $ET, $SITE, $TIME) { //Calculations if ($TIME['LocalTime'] == 1) { //True solar time, radian for ($i = 0; $i < $TIME['Ndays']; $i++) { for ($j = 0; $j < $TIME['Nsteps']; $j++) { $w[$i][$j] = ($Hours[$i][$j] - 12) * 15 * pi() / 180; } } } elseif ($TIME['LocalTime'] == 2) { //Daily loop for ($d = 0; $d < $TIME['Ndays']; $d++) { //Daylight Saving Time, DST if ($d < $TIME['DOCS'] || $d >= $TIME['DOCW']) { $DST[$d] = $TIME['DSTW'][$d]; } else { $DST[$d] = $TIME['DSTS'][$d]; } //Hourly loop for ($h = 0; $h < $TIME['Nsteps']; $h++) { //True solar time, radian $w[$d][$h] = ($Hours[$d][$h] - (12 + $DST[$d][$h])) * 15 * pi / 180 + ($SITE['Longitude'] - $SITE['StandardLongitude']) * pi / 180 + $ET[$d]; } } //end foreach } //end elseif return $w; }
function timeout() { global $da, $background, $back_width, $back_height, $frame, $images, $frame_num; $background->copy_area(0, 0, $back_width, $back_height, $frame, 0, 0); $f = $frame_num % CYCLE_LEN / CYCLE_LEN; $xmid = $back_width / 2.0; $ymid = $back_height / 2.0; $radius = min($xmid, $ymid) / 2.0; for ($i = 0; $i < N_IMAGES; $i++) { $ang = 2.0 * pi() * $i / N_IMAGES - $f * 2.0 * pi(); $iw = $images[$i]->get_width(); $ih = $images[$i]->get_height(); $r = $radius + $radius / 3.0 * sin($f * 2.0 * pi()); $xpos = floor($xmid + $r * cos($ang) - $iw / 2.0 + 0.5); $ypos = floor($ymid + $r * sin($ang) - $ih / 2.0 + 0.5); $k = $i & 1 ? sin($f * 2.0 * pi()) : cos($f * 2.0 * pi()); $k = 2.0 * $k * $k; $k = max(0.25, $k); $r1 = new GdkRectangle($xpos, $ypos, $iw * $k, $ih * $k); $r2 = new GdkRectangle(0, 0, $back_width, $back_height); $dest = $r1->intersect($r2); $images[$i]->composite($frame, $dest->x, $dest->y, $dest->width, $dest->height, $xpos, $ypos, $k, $k, Gdk::INTERP_NEAREST, $i & 1 ? max(127, abs(255 * sin($f * 2.0 * pi()))) : max(127, abs(255 * cos($f * 2.0 * pi())))); } $da->queue_draw(); $frame_num++; return true; }
public function approximate() { $correlation = $this->getCorrelation(); $step = $this->getStep(); $this->_tau = 0; for ($i = 0; $i < count($correlation); $i++) { if ($correlation[$i] < 0) { $p1 = new Model_Coordinate($step * ($i - 1), $correlation[$i - 1]); $p2 = new Model_Coordinate($step * $i, $correlation[$i]); $k = ($p2->getY() - $p1->getY()) / ($p2->getX() - $p1->getX()); $b = $p2->getY() - $k * $p2->getX(); $this->_tau = -$b / $k; break; } } $this->_beta = pi() / (2 * $this->_tau); $s1 = 0; $s2 = 0; for ($i = 0; $i * $step < $this->_tau; $i++) { $tau = $i * $step; $ro_tau = $correlation[$i]; $s1 += abs($tau * log($ro_tau / cos($this->_beta * $tau))); $s2 += $tau * $tau; } if ($this->_tau < $step) { $this->_alpha = 1; } else { $this->_alpha = $s1 / $s2; } }
public function testGetTheVolumeOfSphere() { $radius = 4; $result = 4 / 3 * pi() * sqrt($radius) * $radius; $volume_sphere = new Shape() / Sphere($radius); $this->assertEquals($result, $volume_sphere); }
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>"; }
public static function getClubs($userLongitude, $userLatitude, $range = 10) { $searchRange = 180 / pi() * ($range / 6372.797); $lngR = abs($searchRange / cos($userLatitude * pi() / 180.0)); $maxLat = $userLatitude + $searchRange; $minLat = $userLatitude - $searchRange; $maxLng = $userLongitude + $lngR; $minLng = $userLongitude - $lngR; $con = DBUtil::connectDB(); $sql = "SELECT * FROM club where ((latitude BETWEEN {$minLat} AND {$maxLat}) AND (longitude BETWEEN {$minLng} AND {$maxLng}))"; $result = mysql_query($sql, $con); $clubs = []; while ($row = mysql_fetch_array($result)) { $r = []; $r['id'] = $row['id']; $r['name'] = $row['name']; $r['longitude'] = $row['longitude']; $r['latitude'] = $row['latitude']; $r['images'] = json_decode($row['images']); $r['address'] = $row['address']; $r['meta'] = json_decode($row['meta']); $clubs[] = $r; } mysql_close(); return $clubs; }
public static function distance($lat1, $long1, $lat2, $long2) { //радиус Земли $R = 6372795; //перевод коордитат в радианы $lat1 *= pi() / 180; $lat2 *= pi() / 180; $long1 *= pi() / 180; $long2 *= pi() / 180; //вычисление косинусов и синусов широт и разницы долгот $cl1 = cos($lat1); $cl2 = cos($lat2); $sl1 = sin($lat1); $sl2 = sin($lat2); $delta = $long2 - $long1; $cdelta = cos($delta); $sdelta = sin($delta); //вычисления длины большого круга $y = sqrt(pow($cl2 * $sdelta, 2) + pow($cl1 * $sl2 - $sl1 * $cl2 * $cdelta, 2)); $x = $sl1 * $sl2 + $cl1 * $cl2 * $cdelta; $ad = atan2($y, $x); $dist = $ad * $R; $dist = round($dist); return $dist; }
public function distanceBetween(Geopoint $pointA, Geopoint $pointB, $algorithm = 'flat', $unit = null) { if (!$unit) $unit = $this->defaultUnit; switch ($algorithm) { case 'haversine': $theta = ($pointA->longitude - $pointB->longitude); $dist = sin(deg2rad($pointA->latitude)) * sin(deg2rad($pointB->latitude)) + cos(deg2rad($pointA->latitude)) * cos(deg2rad($pointB->latitude)) * cos(deg2rad($theta)); $dist = acos($dist); $distance = rad2deg($dist); break; case 'flat': default: $distanceEW = ($pointB->longitude - $pointA->longitude) * cos($pointA->latitude); $distanceNS = $pointB->latitude - $pointA->latitude; $distance = sqrt( ($distanceEW * $distanceEW) + ($distanceNS * $distanceNS)); break; } $distance *= 2 * pi() * $this->earthRadius[$unit] / 360.0; return $distance; }
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; }
private function get_condition() { if ($this->input['jd'] || $this->input['wd']) { //gps坐标转百度坐标 $baidu_zuobiao = GpsToBaidu($this->input['jd'], $this->input['wd']); $this->input['baidu_longitude'] = $baidu_zuobiao['x']; $this->input['baidu_latitude'] = $baidu_zuobiao['y']; } $distance = $this->input['distance']; if ($this->input['baidu_longitude'] && $this->input['baidu_latitude'] && $distance) { $baidu_longitude = $this->input['baidu_longitude']; $baidu_latitude = $this->input['baidu_latitude']; $range = 180 / pi() * $distance / 6372.797; //里面的 $distance 就代表搜索 $distance 之内,单位km $lngR = $range / cos($baidu_latitude * pi() / 180); //echo $range;exit() $maxLat = $baidu_latitude + $range; //最大纬度 $minLat = $baidu_latitude - $range; //最小纬度 $maxLng = $baidu_longitude + $lngR; //最大经度 $minLng = $baidu_longitude - $lngR; //最小经度 $condition .= ' AND t1.baidu_longitude >=' . $minLng . ' AND t1.baidu_longitude <=' . $maxLng . ' AND t1.baidu_latitude >=' . $minLat . ' AND t1.baidu_latitude <= ' . $maxLat . ' AND t1.baidu_latitude != "" AND t1.baidu_longitude != ""'; } return $condition; }
public function MetersToLatLon($mx, $my) { $lon = $mx / $this->originShift * 180.0; $lat = $my / $this->originShift * 180.0; $lat = 180 / pi() * (2 * atan(exp($lat * pi() / 180.0)) - pi() / 2.0); return array($lat, $lon); }
protected function explodeTestData($locale, $currencyCode) { // valid values for all currencies $validDomainValues = [(double) -10, (double) 0, (double) 10]; // invalid values for all currencies $invalidDomainValues = [-1, 0, 1, null, false, true, "", "123", "foo", [], ['foo' => 'bar'], new \stdClass(), NAN, INF, -INF]; $tmpValid = $validDomainValues; $tmpInvalid = $invalidDomainValues; // Build fraction digits test data $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); $formatter->setTextAttribute($formatter::CURRENCY_CODE, $currencyCode); $fractionDigits = $formatter->getAttribute(\NumberFormatter::FRACTION_DIGITS); $tmpValid[] = (double) (1 + pow(10, -$fractionDigits)); $tmpInvalid[] = (double) (1 + pow(10, -($fractionDigits + 1))); $pi = pi(); $tmpValid[] = round($pi, $fractionDigits); if ($fractionDigits > 2) { $tmpValid[] = round($pi, $fractionDigits - 1); $tmpValid[] = (double) (1 + pow(10, -($fractionDigits - 1))); } $tmpInvalid[] = round($pi, $fractionDigits + 1); $return = []; foreach ($tmpValid as $value) { $return[] = [$value, true]; } foreach ($tmpInvalid as $value) { $return[] = [$value, false]; } return $return; }
/** * 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; }
function drawRhythm($daysAlive, $period, $color) { global $daysToShow, $image, $diagramWidth, $diagramHeight; // get day on which to center $centerDay = $daysAlive - ($daysToShow / 2); // calculate diagram parameters $plotScale = ($diagramHeight - 25) / 2; $plotCenter = ($diagramHeight - 25) / 2; // draw the curve for($x = 0; $x <= $daysToShow; $x++) { // calculate phase of curve at this day, then Y value // within diagram $phase = (($centerDay + $x) % $period) / $period * 2 * pi(); $y = 1 - sin($phase) * (float)$plotScale + (float)$plotCenter; // draw line from last point to current point if($x > 0) imageLine($image, $oldX, $oldY, $x * $diagramWidth / $daysToShow, $y, $color); // save current X/Y coordinates as start point for next line $oldX = $x * $diagramWidth / $daysToShow; $oldY = $y; } }
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; }
function imagecharx($img, $char, $x0, $y0, $ylist) { global $bk_color, $fg_color; $da = @imagecreate(10, 20) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($da, $bk_color[0], $bk_color[1], $bk_color[2]); $text_color = imagecolorallocate($da, $fg_color[0], $fg_color[1], $fg_color[2]); $color = imagecolorallocate($img, $fg_color[0], $fg_color[1], $fg_color[2]); $arg = rand(0, 18) / 100.0 * pi(); imagestring($da, 18, 0, 0, $char, $text_color); for ($i = 0; $i < 200; $i++) { $y = @floor($i / 10); $x = $i % 10; $point_color = imagecolorat($da, $x, $y); if ($point_color == $text_color) { for ($j = 0; $j < 12; $j++) { $dx = 0; $dy = 0; $p = 6; for ($s = 0; $s < $p; $s++) { $dx += rand(0, 1000 / $p) / 100; $dy += rand(0, 1000 / $p) / 100; } $xx = $x * 5 + $dx - 25; $yy = $y * 5 + $dy - 50; $x1 = cos($arg) * $xx - sin($arg) * $yy + 25; $y1 = sin($arg) * $xx + cos($arg) * $yy + 50; imagesetpixel($img, $x0 + $x1, $y0 + $y1, $color); } } } imagedestroy($da); }
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)); }
function AmbientTemperature($w, $ws, $METEO, $TIME) { //Daily maximum and minimum temperatures if ($TIME['Ndays'] == 365) { //All year $TM = MonthlyAverageToAll($METEO['TMm']); $Tm = MonthlyAverageToAll($METEO['Tmm']); } elseif ($TIME['Ndays'] == 12) { //Only characteristic days $TM = $METEO['TMm']; $Tm = $METEO['Tmm']; } //Calculations for ($d = 0; $d < $TIME['Ndays']; $d++) { //Daily coefficients $a3[$d] = -pi() / ($ws[$d] + 2 * pi() - pi() / 6); $b3[$d] = -$a3[$d] * $ws[$d]; $a4[$d] = pi() / ($ws[$d] - pi() / 6); $b4[$d] = -$a4[$d] * pi() / 6; $a5[$d] = pi() / (2 * pi() + $ws[$d] - pi() / 6); $b5[$d] = -(pi() + $a5[$d] * pi() / 6); for ($h = 0; $h < $TIME['Nsteps']; $h++) { if (-pi() < $w[$d][$h] && $w[$d][$h] < $ws[$d]) { $Ta[$d][$h] = $TM[$d] - ($TM[$d] - $Tm[$d]) / 2 * (1 + cos($a3[$d] * $w[$d][$h] + $b3[$d])); } elseif ($ws[$d] < $w[$d][$h] && $w[$d][$h] < pi() / 6) { $Ta[$d][$h] = $Tm[$d] + ($TM[$d] - $Tm[$d]) / 2 * (1 + cos($a4[$d] * $w[$d][$h] + $b4[$d])); } else { $Ta[$d][$h] = $TM[$d] - ($TM[$d] - $Tm[$d]) / 2 * (1 + cos($a5[$d] * $w[$d][$h] + $b5[$d])); } } //end FOR $h } //end FOREACH $d return $Ta; }
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); }
public function updatePosition($data) { $userID = RestUtils::authentication(); if (!$userID) { RestUtils::error(401, "Authentication Error"); } $OK = 200; $ERROR = 200; if (!isset($data['latitude']) || !isset($data['longitude'])) { return new Response($ERROR, "The parameters passed are not correct"); } $earthRadius = 6367; $theta = $data['longitude']; $phi = 90 - abs($data['latitude']); $theta = $theta * 2 * pi() / 360; $phi = $phi * 2 * pi() / 360; $x = $earthRadius * cos($theta) * sin($phi); $y = $earthRadius * sin($theta) * sin($phi); $z = $earthRadius * cos($phi); $updatePos = "UPDATE n_nebulauser SET x = {$x},\n\t\t\t\t\t\t y = {$y},\n\t\t\t\t\t\t z = {$z}\n\t\t\t\t\t WHERE id = {$userID}"; echo $updatePos; $execUpdate = $this->nebulaDB->query($updatePos); $selectContact = "SELECT c.*\n\t\t\t FROM n_nebulaoontact c INNER JOIN n_nebulauser n\n\t\t\t WHERE c.ownerID = {$userID}\n\t\t\t AND c.contactID =n.id\n\t\t\t AND n.x IS NOT NULL\n\t\t\t AND n.y IS NOT NULL\n\t\t\t AND n.z IS NOT NULL"; $execSelect = $this->nebulaDB->query($selectContact); while ($ind = mysql_fetch_assoc($execSelect)) { $contactID = $ind['contactID']; $updateQuery = "UPDATE n_usertouser SET distance = \n\t\t\t\t(SELECT((SELECT ASIN((SELECT((SELECT SQRT( (\n\t\t\t\tSELECT sum( (SELECT POW( (SELECT (\n\t\t\t\tSELECT x\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id = {$userID}) - (\n\t\t\t\tSELECT x\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id ={$contactID} ) AS DIFF ) , 2 ) ) + (\n\t\t\t\tSELECT POW( (SELECT (SELECT y\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id ={$userID}\n\t\t\t\t) - (\n\t\t\t\tSELECT y\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id ={$contactID} ) AS DIFF ) , 2 )\n\t\t\t\t) + (\n\t\t\t\tSELECT POW( (SELECT (\n\t\t\t\tSELECT z\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id ={$userID}\n\t\t\t\t) - (\n\t\t\t\tSELECT z\n\t\t\t\tFROM n_nebulauser\n\t\t\t\tWHERE id ={$contactID} ) AS DIFF ) , 2 ))))))/(2*6371)))))*(2*6371)))\n\t\t\t\tWHERE ownerID={$userID} and contactID={$contactID}"; $execUpdate = $this->nebulaDB->query($updateQuery); } if (mysql_affected_rows() <= 0) { return new Response($ERROR, "Unable to modify the position"); } return new Response($OK, "Position modiifed"); }
/** * Calculates bounding box of current font setting * * @return Array */ public function getBoxSize() { $box = array(); if ($this->hasApplicableFontFile()) { // get bounding box with angle 0 $box = imagettfbbox($this->getPointSize(), 0, $this->file, $this->text); // rotate points manually if ($this->angle != 0) { $angle = pi() * 2 - $this->angle * pi() * 2 / 360; for ($i = 0; $i < 4; $i++) { $x = $box[$i * 2]; $y = $box[$i * 2 + 1]; $box[$i * 2] = cos($angle) * $x - sin($angle) * $y; $box[$i * 2 + 1] = sin($angle) * $x + cos($angle) * $y; } } $box['width'] = intval(abs($box[4] - $box[0])); $box['height'] = intval(abs($box[5] - $box[1])); } else { // get current internal font size $width = $this->getInternalFontWidth(); $height = $this->getInternalFontHeight(); if (strlen($this->text) == 0) { // no text -> no boxsize $box['width'] = 0; $box['height'] = 0; } else { // calculate boxsize $box['width'] = strlen($this->text) * $width; $box['height'] = $height; } } return $box; }
function DrawLevels($startX, $startY, $startAngle, $startLength, $levels, &$lastPointX, &$lastPointY) { $angle = $startAngle; $lastPointX = 0; $lastPointY = 0; if ($levels == 0) { $this->Draw($startX, $startY, $startLength, $angle, &$lastPointX, &$lastPointY); $angle -= 60; $this->Draw($lastPointX, $lastPointY, $startLength, $angle, &$lastPointX, &$lastPointY); $angle -= -120; $this->Draw($lastPointX, $lastPointY, $startLength, $angle, &$lastPointX, &$lastPointY); $angle -= 60; $this->Draw($lastPointX, $lastPointY, $startLength, $angle, &$lastPointX, &$lastPointY); } else { $tempLength = (double) $startLength / 3.333333; $tempPointX = $startX; $tempPointY = $startY; $this->DrawLevels($tempPointX, $tempPointY, $angle, $tempLength, $levels - 1, &$lastPointX, &$lastPointY); $tempPointX = $startLength * cos($angle * (double) 180 / pi()) + $tempPointX; $tempPointY = $startLength * sin($angle * (double) 180 / pi()) + $tempPointY; $angle -= 60; $this->DrawLevels($tempPointX, $tempPointY, $angle, $tempLength, $levels - 1, &$lastPointX, &$lastPointY); $tempPointX = $startLength * cos($angle * (double) 180 / pi()) + $tempPointX; $tempPointY = $startLength * sin($angle * (double) 180 / pi()) + $tempPointY; $angle -= -120; $this->DrawLevels($tempPointX, $tempPointY, $angle, $tempLength, $levels - 1, &$lastPointX, &$lastPointY); $tempPointX = $startLength * cos($angle * (double) 180 / pi()) + $tempPointX; $tempPointY = $startLength * sin($angle * (double) 180 / pi()) + $tempPointY; $angle -= 60; $this->DrawLevels($tempPointX, $tempPointY, $angle, $tempLength, $levels - 1, &$lastPointX, &$lastPointY); } }
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; }
public function __construct($options) { parent::__construct(); $inner_radius = (double) $options['inner_radius']; $outer_radius = (double) $options['outer_radius']; $r1 = ($outer_radius - $inner_radius) / 2; $r2 = $inner_radius + $r1; $d1 = (int) round(max(1, $options['detail_1']) * 4); $d2 = (int) round(max(1, $options['detail_2']) * 4); $rings = array(); for ($i = 0; $i < $d1; ++$i) { $rings[$i] = array(); for ($j = 0; $j < $d2; ++$j) { $_i = $i / $d1; $_j = $j / $d2; $z = cos($_j * pi() * 2) * $r1; $z2 = sin($_j * pi() * 2) * $r1; $x = ($r2 + $z2) * cos($_i * pi() * 2); $y = ($r2 + $z2) * sin($_i * pi() * 2); $rings[$i][] = new Image_3D_Point($x, $y, $z); } } foreach ($rings as $i => $ring) { $i_next = ($i + 1) % count($rings); foreach ($ring as $j => $point) { $j_next = ($j + 1) % count($ring); $this->_addPolygon(new Image_3D_Polygon($rings[$i_next][$j], $rings[$i][$j], $rings[$i][$j_next])); $this->_addPolygon(new Image_3D_Polygon($rings[$i_next][$j], $rings[$i][$j_next], $rings[$i_next][$j_next])); } } }
/** * Get polygon area fast method * * @param float[][] $polygon * @param float $a * @param float $f * * @return float area of given polygon in square meters * @throws Exception */ public static function getArea($polygon, $a = 6378137.0) { if (!is_array($polygon) || !is_array($polygon[0])) { throw new Exception("Array of array of floats expected!"); } if ($polygon[0][0] != $polygon[count($polygon) - 1][0] || $polygon[0][1] != $polygon[count($polygon) - 1][1]) { $polygon[] = $polygon[0]; } $total = 0; $previous = $polygon[0]; $cx = 0; $cy = 0; for ($i = 1; $i < count($polygon); $i++) { $cx = $cx + $polygon[$i][1]; $cy = $cy + $polygon[$i][0]; } $cx = $cx / count($polygon); $cy = $cy / count($polygon); $xRef = $cx + 1; $yRef = $cy + 1; for ($i = 1; $i < count($polygon); $i++) { $current = $polygon[$i]; $earthRadians = $a * pi() / 180; // convert to cartesian coordinates in meters, note this not very exact $x1 = ($previous[1] - $xRef) * $earthRadians * cos($yRef * pi() / 180); $y1 = ($previous[0] - $yRef) * $earthRadians; $x2 = ($current[1] - $xRef) * $earthRadians * cos($yRef * pi() / 180); $y2 = ($current[0] - $yRef) * $earthRadians; $total += $x1 * $y2 - $x2 * $y1; $previous = $current; } return 0.5 * abs($total); }
/** * Draw the marker on the canvas * @param int $x The X (horizontal) position (in pixels) of the marker on * the canvas * @param int $y The Y (vertical) position (in pixels) of the marker on the * canvas * @param array $values The values representing the data the marker 'points' * to * @access private */ function _drawMarker($x, $y, $values = false) { $angle = pi() * rand(0, 360) / 180; $this->_deltaX = $this->_radius * cos($angle); $this->_deltaY = $this->_radius * sin($angle); parent::_drawMarker($x, $y, $values); }
public static function line($x1, $y1, $x2, $y2, $chars = array('#')) { if ($x2 != $x1) { if ($x2 < $x1) { list($x1, $x2) = array($x2, $x1); list($y2, $y1) = array($y1, $y2); } $slope = ($y2 - $y1) / ($x2 - $x1); $radians = atan($slope); } else { $radians = pi() / 2; } $radians += 2 * pi(); $dist = sqrt(pow($x2 - $x1, 2) + pow($y2 - $y1, 2)); $last_x = false; $last_y = false; $j = 0; $chars_length = count($chars); for ($i = 0; $i <= abs(ceil($dist)); $i += 1) { $x = round($i * cos($radians) + $x1); $y = round($i * sin($radians) + $y1); if ($x != $last_x || $last_y != $y) { Output::string($chars[$j++ % $chars_length], $y, $x); } $last_x = $x; $last_y = $y; } }