public function get_list($lat, $long, $page, $pagesize, $activity_type) { $where = array("status" => 0, "invite_time" => array("gt", time())); if ($activity_type !== false) { $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.activity_type=" . $activity_type . " AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC"; $where["activity_type"] = intval($activity_type); } else { $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.status=0 AND i.invite_time>" . time() . " ORDER BY i.pigcms_id DESC, u.sex DESC"; } $start = ($page - 1) * $pagesize; $count = $this->where($where)->count(); $sql .= " limit {$start}, {$pagesize}"; $mode = new Model(); $res = $mode->query($sql); $today = strtotime(date("Y-m-d")) + 86400; $tomorrow = $today + 86400; $lastday = $tomorrow + 86400; foreach ($res as &$v) { $v["_time"] = date("Y-m-d H:i", $v["invite_time"]); $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000); $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m"); $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天 " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"]))); $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"]))); $v["age"] = 100 < $v["age"] || $v["age"] < 0 ? "保密" : $v["age"] . "岁"; } return array("data" => $res, "total" => $count); }
/** * this function does some simple syntax cleaning: * - removes all spaces * - replaces '**' by '^' * then it runs a regex to split the contents into tokens. the set * of possible tokens in this case is predefined to numbers (ints of floats) * math operators (*, -, +, /, **, ^) and parentheses. */ public function tokenize() { $this->content = str_replace(array("\n", "\r", "\t", " "), '', $this->content); $this->content = str_replace('**', '^', $this->content); $this->content = str_replace('PI', (string) PI(), $this->content); $this->tokens = preg_split('@ ([\\d\\.]+) |( sin\\( |log\\( |ln\\( |pow\\( |exp\\( |acos\\( |cos\\( |sum\\( |avg\\( |tan\\( |sqrt\\( |if\\( |\\+ |\\- |\\* |/ |\\^ |\\( |\\) ) @ix', $this->content, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); return $this; }
/** * 计算两组经纬度坐标 之间的距离 * params :lat1 纬度1; lng1 经度1; lat2 纬度2; lng2 经度2; len_type (1:m or 2:km); * return m or km */ public static function getDistanceByLongitudeAndLatitude($lat1, $lng1, $lat2, $lng2, $len_type = 2, $decimal = 1) {/*{{{*/ $radLat1 = $lat1 * PI ()/ 180.0; //PI()圆周率 $radLat2 = $lat2 * PI() / 180.0; $a = $radLat1 - $radLat2; $b = ($lng1 * PI() / 180.0) - ($lng2 * PI() / 180.0); $s = 2 * asin(sqrt(pow(sin($a/2),2) + cos($radLat1) * cos($radLat2) * pow(sin($b/2),2))); $s = $s * self::EARTH_RADIUS; $s = round($s * 1000); if ($len_type > 1) { $s /= 1000; } return round($s, $decimal); }/*}}}*/
function AA_getLatLongXYZ($x, $y, $zoom) { $debug = $_GET['debug']; $lon = -180; // x $lonWidth = 360; // width 360 $lat = -1; $latHeight = 2; $tilesAtThisZoom = 1 << 17 - $zoom; $lonWidth = 360.0 / $tilesAtThisZoom; $lon = -180 + $x * $lonWidth; $latHeight = 2.0 / $tilesAtThisZoom; $lat = ($tilesAtThisZoom / 2 - $y - 1) * $latHeight; if ($debug) { echo "(uniform) lat:{$latlatHt}:{$latHeight}<br>"; } // convert lat and latHeight to degrees in a transverse mercator projection // note that in fact the coordinates go from about -85 to +85 not -90 to 90! $latHeight += $lat; $latHeight = 2 * atan(exp(PI() * $latHeight)) - PI() / 2; $latHeight *= 180 / PI(); $lat = 2 * atan(exp(PI() * $lat)) - PI() / 2; $lat *= 180 / PI(); if ($debug) { echo "pre subtract lat: {$lat} latHeight {$latHeight}<br>"; } $latHeight -= $lat; if ($debug) { echo "lat: {$lat} latHeight {$latHeight}<br>"; } if ($lonWidth < 0) { $lon = $lon + $lonWidth; $lonWidth = -$lonWidth; } if ($latHeight < 0) { $lat = $lat + $latHeight; $latHeight = -$latHeight; } return array($lon, $lat, $lon + lonWidth, $lat + latHeight); }
/** * returns a Rectangle2D with x = lon, y = lat, width=lonSpan, height=latSpan * for an x,y,zoom as used by google. */ function getLatLonXYZ($x, $y, $zoom) { $debug = isset($_GET['debug']) ? $_GET['debug'] : 0; $lon = -180; // x $lonWidth = 360; // width 360 $lat = -1; $latHeight = 2; $tilesAtThisZoom = 1 << $zoom; $lonWidth = 360.0 / $tilesAtThisZoom; $lon = -180 + $x * $lonWidth; $latHeight = 2.0 / $tilesAtThisZoom; $lat = ($tilesAtThisZoom / 2 - $y - 1) * $latHeight; if ($debug) { echo "(uniform) lat:{$lat} latHt:{$latHeight}<br>"; } // convert lat and latHeight to degrees in a transverse mercator projection // note that in fact the coordinates go from about -85 to +85 not -90 to 90! $latHeight += $lat; $latHeight = 2 * atan(exp(PI() * $latHeight)) - PI() / 2; $latHeight *= 180 / PI(); $lat = 2 * atan(exp(PI() * $lat)) - PI() / 2; $lat *= 180 / PI(); if ($debug) { echo "pre subtract lat: {$lat} latHeight {$latHeight}<br>"; } $latHeight -= $lat; if ($debug) { echo "lat: {$lat} latHeight {$latHeight}<br>"; } if ($lonWidth < 0) { $lon = $lon + $lonWidth; $lonWidth = -$lonWidth; } if ($latHeight < 0) { $lat = $lat + $latHeight; $latHeight = -$latHeight; } $rect = new aRectangle(); $rect->x = $lon; $rect->y = $lat; $rect->height = $latHeight; $rect->width = $lonWidth; return $rect; }
public function mysign() { $invitation_signs = D("Invitation_sign")->field("invid")->where(array("uid" => $this->user_session["uid"]))->order("invid DESC")->select(); $invids = $pre = ""; foreach ($invitation_signs as $is) { $invids .= $pre . $is["invid"]; $pre = ","; } $today = strtotime(date("Y-m-d")) + 86400; $tomorrow = $today + 86400; $lastday = $tomorrow + 86400; if ($invids) { $sql = "SELECT i.*, u.* FROM " . C("DB_PREFIX") . "user as u INNER JOIN " . C("DB_PREFIX") . "invitation as i ON i.uid=u.uid WHERE i.pigcms_id IN ({$invids}) ORDER BY i.pigcms_id DESC, u.sex DESC"; $mode = new Model(); $res = $mode->query($sql); foreach ($res as &$v) { $v["_time"] = date("Y-m-d H:i", $v["invite_time"]); $v["juli"] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($this->_lat * PI() / 180 - $v["lat"] * PI() / 180) / 2), 2) + COS($this->_lat * PI() / 180) * COS($v["lat"] * PI() / 180) * POW(SIN(($this->_long * PI() / 180 - $v["long"] * PI() / 180) / 2), 2))) * 1000); $v["juli"] = 1000 < $v["juli"] ? number_format($v["juli"] / 1000, 1) . "km" : ($v["juli"] < 100 ? "<100m" : $v["juli"] . "m"); $v["invite_time"] = $v["invite_time"] < $today ? "今天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $tomorrow ? "明天 " . date("H:i", $v["invite_time"]) : ($v["invite_time"] < $lastday ? "后天 " . date("H:i", $v["invite_time"]) : date("m-d H:i", $v["invite_time"]))); $v["birthday"] && ($v["age"] = date("Y") - date("Y", strtotime($v["birthday"]))); } $this->assign("date_list", $res); } $this->display(); }
public function calculateVerticalSection(&$dataArray, $vs_angle = 0) { for ($i = 1; $i <= count($dataArray); $i++) { $kx = $dataArray[$i]['X'] - $dataArray[1]['X']; $ky = $dataArray[$i]['Y'] - $dataArray[1]['Y']; $dept = sqrt(pow($kx, 2) + pow($ky, 2)); if ($ky == 0) { $angle = 0; } else { $angle = rad2deg(atan(abs($kx / $ky))); } if ($kx == 0 and $ky == 0) { $angle = 0; } if ($kx >= 0 and $ky > 0) { $angle = $angle; } if ($kx > 0 and $ky == 0) { $angle = rad2deg(PI() / 2); } if ($kx >= 0 and $ky < 0) { $angle = rad2deg(PI()) - $angle; } if ($kx <= 0 and $ky < 0) { $angle = rad2deg(PI()) * $angle; } if ($kx < 0 and $ky == 0) { $angle = rad2deg(3 * PI() / 2); } if ($kx <= 0 and $ky > 0) { $angle = rad2deg(2 * PI()) - $angle; } $dataArray[$i]['CL_DEP'] = $dept; $dataArray[$i]['CL_Angle'] = $angle; $dataArray[$i]['V_SECTION'] = $dept * cos(deg2rad($angle - $vs_angle)); if ($i > 1) { $dataArray[$i]['DLS'] = rad2deg(acos(cos(deg2rad($dataArray[$i - 1]['alfa'])) * cos(deg2rad($dataArray[$i]['alfa'])) + sin(deg2rad($dataArray[$i - 1]['alfa'])) * sin(deg2rad($dataArray[$i]['alfa'])) * cos(deg2rad($dataArray[$i]['beta'] - $dataArray[$i - 1]['beta'])))) * 30.48 / ($dataArray[$i]['MD'] - $dataArray[$i - 1]['MD']); } else { $dataArray[$i]['DLS'] = 0; } } }
<?php //Settings: $c = 999; //Higher number = better PI //Code: $pico = 0; $c1 = 180 / $c; echo "Debug1: " . $c1 . "\n"; $c2 = sin($c1); echo "Debug2: " . $c2 . "\n"; $pico = $c * $c2; echo "Short PI: " . PI() . "\n Counted PI:\n"; echo $pico;
function GetDistance($lat1, $lng1, $lat2, $lng2, $len_type = 1, $decimal = 2) { define('EARTH_RADIUS', 6378.137); //地球半径,假设地球是规则的球体 define('PI', 3.1415926); $earth = 6378.137; $pi = 3.1415926; $radLat1 = $lat1 * PI() / 180.0; //PI()圆周率 $radLat2 = $lat2 * PI() / 180.0; $a = $radLat1 - $radLat2; $b = $lng1 * PI() / 180.0 - $lng2 * PI() / 180.0; $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))); $s = $s * EARTH_RADIUS; $s = round($s * 1000); if ($len_type > 1) { $s /= 1000; } //logwrite('jisuan:'.$s); return round($s, $decimal); }
public function wap_get_store_list_by_catid($cat_id, $area_id, $order, $lat, $long, $cat_url) { $stores = D('Store_category')->field('store_id')->where("cat_id='{$cat_id}'")->select(); foreach ($stores as $s) { $store_ids[] = $s['store_id']; } $store_ids && ($where['store_id'] = array('in', $store_ids)); if ($cat_url == 'dianying' && empty($store_ids)) { return false; } // $where['have_meal'] = 1; $where['status'] = 1; $area_id && ($where['area_id'] = $area_id); $count = D('Merchant_store')->where($where)->count(); //排序 switch ($order) { case 'distance': $order = "ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(({$lat} * PI() / 180- `lat` * PI()/180)/2),2)+COS({$lat} *PI()/180)*COS(`lat`*PI()/180)*POW(SIN(({$long} *PI()/180- `long`*PI()/180)/2),2)))*1000) ASC"; //'`g`.`price` ASC,`g`.`group_id` DESC'; break; // case 'priceDesc': // $order = '`g`.`price` DESC,`g`.`group_id` DESC'; // break; // case 'solds': // $order = '`g`.`sale_count` DESC,`g`.`group_id` DESC'; // break; // case 'rating': // $order = '`g`.`score_mean` DESC,`g`.`group_id` DESC'; // break; // case 'start': // $order = '`g`.`last_time` DESC,`g`.`group_id` DESC'; // break; // case 'priceDesc': // $order = '`g`.`price` DESC,`g`.`group_id` DESC'; // break; // case 'solds': // $order = '`g`.`sale_count` DESC,`g`.`group_id` DESC'; // break; // case 'rating': // $order = '`g`.`score_mean` DESC,`g`.`group_id` DESC'; // break; // case 'start': // $order = '`g`.`last_time` DESC,`g`.`group_id` DESC'; // break; default: $order = '`store_id` DESC'; } import('@.ORG.wap_group_page'); $p = new Page($count, C('config.group_page_row'), C('config.group_page_val')); $list = D('Merchant_store')->field(true)->where($where)->order($order)->limit($p->firstRow . ',' . $p->listRows)->select(); // echo D('Merchant_store')->_sql(); $return['pagebar'] = $p->show(); if ($list) { $store_image_class = new store_image(); foreach ($list as &$v) { $images = $store_image_class->get_allImage_by_path($v['pic_info']); $v['image'] = $images ? array_shift($images) : ''; $v['juli'] = ROUND(6378.138 * 2 * ASIN(SQRT(POW(SIN(($lat * PI() / 180 - $v['lat'] * PI() / 180) / 2), 2) + COS($lat * PI() / 180) * COS($v['lat'] * PI() / 180) * POW(SIN(($long * PI() / 180 - $v['long'] * PI() / 180) / 2), 2))) * 1000); $v['juli'] = $v['juli'] > 1000 ? number_format($v['juli'] / 1000, 1) . 'km' : ($v['juli'] < 100 ? '<100m' : $v['juli'] . 'm'); } } $return['store_list'] = $list; return $return; }
Press CTRL and try to roll MouseWheeeel...<br /> Look at source code of this webpage ;)<br /> </i><br /> <input type="submit" value=".: DRAW :."> </form> </div> <pre><?php //This will draw the ASCII "neverending" sinus curve. //Writen by (c) Harvie in 2oo6 //Settings: $start = 0; //0 //First X $step = 0.07000000000000001; //0.1 //Increase X on every line by this number $reset = 2 * PI(); //When X >= reset, then it will be reseted to zero $zoom = 1; //1 //This will repeat every line few times $offset = 1.1; //1.1 //1 //0 -> Zero offset will draw only half of sin curve. $width = 35; //20 //35 //40 //This will stretch every line. $sleep = "0"; //15000 - Wait between lines in microseconds $line = " "; // " " // ":" //chr ( 176 ) //This is the string, that will be repeated from display start to the curve (curve inlay). $endline = "+<br />\n"; // "#<br />\n" // ".<br />\n" //chr ( 219 )."<br />\n" //This is the string, that will be printed at end of every line (curve outline). //Read settings from form: if ($_GET["start"] != "") {
public function calcFrame($time, $arrKeyFrame) { $from = 0; $to = 999999999; $fromCnt = 0; $toCnt = 0; for ($i = 0; $i < sizeof($arrKeyFrame); $i++) { if ($arrKeyFrame[$i]["time"] <= $time && $arrKeyFrame[$i]["time"] >= $from) { $from = $arrKeyFrame[$i]["time"]; $fromCnt = $i; } if ($arrKeyFrame[$i]["time"] >= $time && $arrKeyFrame[$i]["time"] <= $to) { $to = $arrKeyFrame[$i]["time"]; $toCnt = $i; } } if ($to == 0) { // после последнего фрейма $to = $from; } if ($from == $to) { return $arrKeyFrame[$fromCnt]["angle"]; } if ($arrKeyFrame[$fromCnt]["speed"] == STL_SPEED_NORMAL) { // обычная скорость без ускорений/замедлений $a = $arrKeyFrame[$fromCnt]["angle"] + ($time - $from) * ($arrKeyFrame[$toCnt]["angle"] - $arrKeyFrame[$fromCnt]["angle"]) / ($to - $from); } else { if ($arrKeyFrame[$fromCnt]["speed"] == STL_SPEED_ACCELERATION) { // ускорение $b = ($time - $from) / ($to - $from); // множитель линейно $b = 1 + cos(PI() + $b * (PI() / 2)); // множитель $a = $arrKeyFrame[$toCnt]["angle"] - $arrKeyFrame[$fromCnt]["angle"]; $a = $arrKeyFrame[$fromCnt]["angle"] + $a * $b; } else { if ($arrKeyFrame[$fromCnt]["speed"] == STL_SPEED_DECELERATION) { // замедление $b = ($time - $from) / ($to - $from); // множитель линейно $b = sin($b * (PI() / 2)); // множитель $a = $arrKeyFrame[$toCnt]["angle"] - $arrKeyFrame[$fromCnt]["angle"]; $a = $arrKeyFrame[$fromCnt]["angle"] + $a * $b; } } } return "{$a}"; }
static function gps_distance($lon1, $lat1, $lon2, $lat2) { return 2 * ATAN2(SQRT(SIN(($lat1 - $lat2) * PI() / 180 / 2) * SIN(($lat1 - $lat2) * PI() / 180 / 2) + COS($lat2 * PI() / 180) * COS($lat1 * PI() / 180) * SIN(($lon1 - $lon2) * PI() / 180 / 2) * SIN(($lon1 - $lon2) * PI() / 180 / 2)), SQRT(1 - SIN(($lat1 - $lat2) * PI() / 180 / 2) * SIN(($lat1 - $lat2) * PI() / 180 / 2) + COS($lat2 * PI() / 180) * COS($lat1 * PI() / 180) * SIN(($lon1 - $lon2) * PI() / 180 / 2) * SIN(($lon1 - $lon2) * PI() / 180 / 2))) * 6378140; }