/** * 2Moons * Copyright (C) 2012 Jan Kröpke * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * @package 2Moons * @author Jan Kröpke <*****@*****.**> * @copyright 2012 Jan Kröpke <*****@*****.**> * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3 License * @version 1.7.3 (2013-05-19) * @info $Id: CreateOnePlanetRecord.php 2640 2013-03-23 19:23:26Z slaver7 $ * @link http://2moons.cc/ */ function CreateOnePlanetRecord($Galaxy, $System, $Position, $Universe, $PlanetOwnerID, $PlanetName, $HomeWorld = false, $AuthLevel = 0, $Iron, $Gold, $Crystal, $Elyrium, $iPlanetCount) { global $LNG; $CONF = Config::getAll(NULL, $Universe); if (Config::get('max_galaxy') < $Galaxy || 1 > $Galaxy) { throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position); } if (Config::get('max_system') < $System || 1 > $System) { throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position); } if (Config::get('max_planets') < $Position || 1 > $Position) { throw new Exception("Access denied for CreateOnePlanetRecord.php.<br>Try to create a planet at position:" . $Galaxy . ":" . $System . ":" . $Position); } if (CheckPlanetIfExist($Galaxy, $System, $Position, $Universe)) { return false; } $tp = 0; if ($iPlanetCount >= 3) { $tp = 1; } $FieldFactor = Config::get('planet_factor'); require 'includes/PlanetData.php'; $Pos = ceil($Position / (Config::get('max_planets') / count($PlanetData))); $TMax = $PlanetData[$Pos]['temp']; $TMin = $TMax - 40; $Fields = $PlanetData[$Pos]['fields'] * Config::get('planet_factor'); $Types = $PlanetData[$Pos]['image']; $Name = !empty($PlanetName) ? $GLOBALS['DATABASE']->sql_escape($PlanetName) : $LNG['type_planet'][1]; $GLOBALS['DATABASE']->query("INSERT INTO " . PLANETS . " SET\n\t\t\t\tname = '" . $Name . "',\n\t\t\t\tuniverse = " . $Universe . ",\n\t\t\t\tid_owner = " . $PlanetOwnerID . ",\n\t\t\t\tgalaxy = " . $Galaxy . ",\n\t\t\t\tsystem = " . $System . ",\n\t\t\t\tplanet = " . $Position . ",\n\t\t\t\tlast_update = " . TIMESTAMP . ",\n\t\t\t\tplanet_type = '1',\n\t\t\t\tcolo_metal = " . $Iron . ",\n\t\t\t\tcolo_crystal = " . $Gold . ",\n\t\t\t\tcolo_deut = " . $Crystal . ",\n\t\t\t\tcolo_elyrium = " . $Elyrium . ",\n\t\t\t\tteleport_portal = " . $tp . ",\n\t\t\t\timage = '" . $Types . "',\n\t\t\t\tdiameter = " . floor(1000 * sqrt($Fields)) . ",\n\t\t\t\tfield_max = " . ($HomeWorld ? Config::get('initial_fields') : floor($Fields)) . ",\n\t\t\t\ttemp_min = " . $TMin . ",\n\t\t\t\ttemp_max = " . $TMax . ",\n\t\t\t\tmetal = " . Config::get('metal_start') . ",\n\t\t\t\tmetal_perhour = " . Config::get('metal_basic_income') . ",\n\t\t\t\tcrystal = " . Config::get('crystal_start') . ",\n\t\t\t\tcrystal_perhour = " . Config::get('crystal_basic_income') . ",\n\t\t\t\tdeuterium = " . Config::get('deuterium_start') . ",\n\t\t\t\tdeuterium_perhour = " . Config::get('deuterium_basic_income') . ",\n\t\t\t\telyrium = " . Config::get('deuterium_start') . ",\n\t\t\t\telyrium_perhour = " . Config::get('deuterium_basic_income') . ";"); return $GLOBALS['DATABASE']->GetInsertID(); }
public function roundedRect($xPosition, $yPosition, $width, $height, $round, $style = '') { $k = $this->k; $hp = $this->h; if ($style == 'F') { $op = 'f'; } elseif ($style == 'FD' || $style == 'DF') { $op = 'B'; } else { $op = 'S'; } $MyArc = 4 / 3 * (sqrt(2) - 1); $this->_out(sprintf('%.2F %.2F m', ($xPosition + $round) * $k, ($hp - $yPosition) * $k)); $xc = $xPosition + $width - $round; $yc = $yPosition + $round; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $yPosition) * $k)); $this->arcFunction($xc + $round * $MyArc, $yc - $round, $xc + $round, $yc - $round * $MyArc, $xc + $round, $yc); $xc = $xPosition + $width - $round; $yc = $yPosition + $height - $round; $this->_out(sprintf('%.2F %.2F l', ($xPosition + $width) * $k, ($hp - $yc) * $k)); $this->arcFunction($xc + $round, $yc + $round * $MyArc, $xc + $round * $MyArc, $yc + $round, $xc, $yc + $round); $xc = $xPosition + $round; $yc = $yPosition + $height - $round; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($yPosition + $height)) * $k)); $this->arcFunction($xc - $round * $MyArc, $yc + $round, $xc - $round, $yc + $round * $MyArc, $xc - $round, $yc); $xc = $xPosition + $round; $yc = $yPosition + $round; $this->_out(sprintf('%.2F %.2F l', $xPosition * $k, ($hp - $yc) * $k)); $this->arcFunction($xc - $round, $yc - $round * $MyArc, $xc - $round * $MyArc, $yc - $round, $xc, $yc - $round); $this->_out($op); }
function isprime($x) { if ($x < 2) { return false; } if ($x < 4) { return true; } if ($x == 5) { return true; } if ($x % 2 == 0) { return false; } if ($x % 5 == 0) { return false; } if (($x + 1) % 6 != 0) { if (($x - 1) % 6 != 0) { return false; } } $lim = sqrt($x) + 1.0; for ($y = 3; $y < $lim; $y += 2) { if ($x % $y == 0) { return false; } } return true; }
/** * draws relation links and arrows shows foreign key relations * * @param boolean $showColor Whether to use one color per relation or not * @param integer $i The id of the link to draw * * @global object $pdf The current PDF document * * @access public * * @return void * * @see PMA_Schema_PDF */ public function relationDraw($showColor, $i) { global $pdf; if ($showColor) { $d = $i % 6; $j = ($i - $d) / 6; $j = $j % 4; $j++; $case = array(array(1, 0, 0), array(0, 1, 0), array(0, 0, 1), array(1, 1, 0), array(1, 0, 1), array(0, 1, 1)); list($a, $b, $c) = $case[$d]; $e = 1 - ($j - 1) / 6; $pdf->SetDrawColor($a * 255 * $e, $b * 255 * $e, $c * 255 * $e); } else { $pdf->SetDrawColor(0); } $pdf->setLineWidthScale(0.2); $pdf->lineScale($this->xSrc, $this->ySrc, $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc); $pdf->lineScale($this->xDest + $this->destDir * $this->wTick, $this->yDest, $this->xDest, $this->yDest); $pdf->setLineWidthScale(0.1); $pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick, $this->ySrc, $this->xDest + $this->destDir * $this->wTick, $this->yDest); /* * Draws arrows -> */ $root2 = 2 * sqrt(2); $pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc + $this->wTick / $root2); $pdf->lineScale($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc - $this->wTick / $root2); $pdf->lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest + $this->wTick / $root2); $pdf->lineScale($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest - $this->wTick / $root2); $pdf->SetDrawColor(0); }
/** * see class description * * @param array $A * Either a vector or a collection of tokens to be transformed to a vector * @param array $B * Either a vector or a collection of tokens to be transformed to a vector * @return float The euclidean distance between $A and $B */ public function dist(&$A, &$B) { if (is_int(key($A))) { $v1 = array_count_values($A); } else { $v1 =& $A; } if (is_int(key($B))) { $v2 = array_count_values($B); } else { $v2 =& $B; } $r = array(); foreach ($v1 as $k => $v) { $r[$k] = $v; } foreach ($v2 as $k => $v) { if (isset($r[$k])) { $r[$k] -= $v; } else { $r[$k] = $v; } } return sqrt(array_sum(array_map(function ($x) { return $x * $x; }, $r))); }
/** * CholeskyDecomposition * * Class constructor - decomposes symmetric positive definite matrix * @param mixed Matrix square symmetric positive definite matrix */ public function __construct($A = null) { if ($A instanceof Matrix) { $this->L = $A->getArray(); $this->m = $A->getRowDimension(); for ($i = 0; $i < $this->m; ++$i) { for ($j = $i; $j < $this->m; ++$j) { for ($sum = $this->L[$i][$j], $k = $i - 1; $k >= 0; --$k) { $sum -= $this->L[$i][$k] * $this->L[$j][$k]; } if ($i == $j) { if ($sum >= 0) { $this->L[$i][$i] = sqrt($sum); } else { $this->isspd = false; } } else { if ($this->L[$i][$i] != 0) { $this->L[$j][$i] = $sum / $this->L[$i][$i]; } } } for ($k = $i + 1; $k < $this->m; ++$k) { $this->L[$i][$k] = 0.0; } } } else { throw new Exception(JAMAError(ArgumentTypeException)); } }
/** * @param Coordinate $point * @param Line $line * * @return float */ public function getPerpendicularDistance(Coordinate $point, Line $line) { $ellipsoid = $point->getEllipsoid(); $ellipsoidRadius = $ellipsoid->getArithmeticMeanRadius(); $firstLinePointLat = $this->deg2radLatitude($line->getPoint1()->getLat()); $firstLinePointLng = $this->deg2radLongitude($line->getPoint1()->getLng()); $firstLinePointX = $ellipsoidRadius * cos($firstLinePointLng) * sin($firstLinePointLat); $firstLinePointY = $ellipsoidRadius * sin($firstLinePointLng) * sin($firstLinePointLat); $firstLinePointZ = $ellipsoidRadius * cos($firstLinePointLat); $secondLinePointLat = $this->deg2radLatitude($line->getPoint2()->getLat()); $secondLinePointLng = $this->deg2radLongitude($line->getPoint2()->getLng()); $secondLinePointX = $ellipsoidRadius * cos($secondLinePointLng) * sin($secondLinePointLat); $secondLinePointY = $ellipsoidRadius * sin($secondLinePointLng) * sin($secondLinePointLat); $secondLinePointZ = $ellipsoidRadius * cos($secondLinePointLat); $pointLat = $this->deg2radLatitude($point->getLat()); $pointLng = $this->deg2radLongitude($point->getLng()); $pointX = $ellipsoidRadius * cos($pointLng) * sin($pointLat); $pointY = $ellipsoidRadius * sin($pointLng) * sin($pointLat); $pointZ = $ellipsoidRadius * cos($pointLat); $normalizedX = $firstLinePointY * $secondLinePointZ - $firstLinePointZ * $secondLinePointY; $normalizedY = $firstLinePointZ * $secondLinePointX - $firstLinePointX * $secondLinePointZ; $normalizedZ = $firstLinePointX * $secondLinePointY - $firstLinePointY * $secondLinePointX; $length = sqrt($normalizedX * $normalizedX + $normalizedY * $normalizedY + $normalizedZ * $normalizedZ); $normalizedX /= $length; $normalizedY /= $length; $normalizedZ /= $length; $thetaPoint = $normalizedX * $pointX + $normalizedY * $pointY + $normalizedZ * $pointZ; $length = sqrt($pointX * $pointX + $pointY * $pointY + $pointZ * $pointZ); $thetaPoint /= $length; $distance = abs(M_PI / 2 - acos($thetaPoint)); return $distance * $ellipsoidRadius; }
function calc_distance($r1, $a1, $r2, $a2) { assert($r1 >= 0); assert($a1 >= 0 && $a1 <= 360000); assert($r2 >= 0); assert($a2 >= 0 && $a2 <= 360000); // First, calculate X1,Y1 and X2,Y2, the coordinates inside the // (virtual) galaxy grid $Y1 = $r1 * cos(deg2rad($a1 / 1000)); // RADS! Which in fact, doesn't mind // since all points are virtual $X1 = $r1 * sin(deg2rad($a1 / 1000)); $Y2 = $r2 * cos(deg2rad($a2 / 1000)); $X2 = $r2 * sin(deg2rad($a2 / 1000)); // Get the (absolute) delta of the 2 points $DX = abs($X1 - $X2); $DY = abs($Y1 - $Y2); // Pythagoras says: c^2 = a^2 + b^2. At least, he used to say, he's dead now... $c = sqrt($DX * $DX + $DY * $DY); // round ($c, 4); // PHP >= 4.0.4?? $c = $c * 1000; // Keep 3 digits after the comma $c = round($c); // Round it $c = $c / 1000; // And back with those digits... return $c; // Return schuine zijde }
function Prime($n) { $count = 0; $primeNumber = 0; if ($n < 2) { if ($n == 1) { $count = 1; $primeNumber = 2; } } else { $count = 2; $primeNumber = 3; } for ($k = 5; $count < $n; $k += 2) { if (($k + 1) % 6 == 0 || ($k - 1) % 6 == 0) { $isTrivial = True; $limit = ceil(sqrt($k)); for ($i = 5; $i <= $limit; $i += 2) { if ($k % $i == 0) { $isTrivial = False; break; } } if ($isTrivial) { $count++; $primeNumber = $k; } } } return $primeNumber; }
public function Calc() { $this->icalculated = true; $n = count($this->ix); $sx2 = 0; $sy2 = 0; $sxy = 0; $sx = 0; $sy = 0; for ($i = 0; $i < $n; ++$i) { $sx2 += $this->ix[$i] * $this->ix[$i]; $sy2 += $this->iy[$i] * $this->iy[$i]; $sxy += $this->ix[$i] * $this->iy[$i]; $sx += $this->ix[$i]; $sy += $this->iy[$i]; } if ($n * $sx2 - $sx * $sx > __LR_EPSILON) { $this->ib = ($n * $sxy - $sx * $sy) / ($n * $sx2 - $sx * $sx); $this->ia = ($sy - $this->ib * $sx) / $n; $sx = $this->ib * ($sxy - $sx * $sy / $n); $sy2 = $sy2 - $sy * $sy / $n; $sy = $sy2 - $sx; $this->iDet = $sx / $sy2; $this->iCorr = sqrt($this->iDet); if ($n > 2) { $this->iStdErr = sqrt($sy / ($n - 2)); } else { $this->iStdErr = NAN; } } else { $this->ib = 0; $this->ia = 0; } }
public function inverse($p) { $lon; $lat; $p->x = ($p->x - $this->x0) / $this->a; /* descale and de-offset */ $p->y = ($p->y - $this->y0) / $this->a; $p->x /= $this->k0; $p->y /= $this->k0; if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) { $c = 2.0 * atan2($rho, $this->R2); $sinc = sin($c); $cosc = cos($c); $lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho); $lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc); } else { $lat = $this->phic0; $lon = 0.0; } $p->x = $lon; $p->y = $lat; Proj4php::$proj['gauss']->inverse->apply($this, array($p)); $p->x = Proj4php::$common->adjust_lon($p->x + $this->long0); /* adjust longitude to CM */ return $p; }
/** * @depends testDiLog */ public function testWorks() { $partitions = array(); for ($i = 1; $i <= 100; $i++) { $partitions[$i] = new Partition(array('treatment' => "{$i}", 'size' => 1)); } $treatments = array(); for ($i = 0; $i < 100; $i++) { $treatments[$i] = 0; } $n = 100000; $p = 0.01; for ($i = 0; $i < $n; $i++) { $key = uniqid('', true); $treatment = Splitter::getTreatment($key, 32126754, $partitions); $treatments[(int) $treatment - 1]++; } $mean = $n * $p; $stddev = sqrt($mean * (1 - $p)); $min = (int) ($mean - 4 * $stddev); $max = (int) ($mean + 4 * $stddev); $range = range($min, $max); for ($i = 0; $i < count($treatments); $i++) { $message = "Value: " . $treatments[$i] . " is out of range " . print_r($range, true); $this->assertTrue(in_array($treatments[$i], $range), $message); } }
/** * Create a Distance object * * @param string latitude of first point * @param string longitude of first point * @param string latitude2 of second point * @param string longitude2 of second point * @param bool True if the distance is in Kms, otherwise returns Miles */ public function __construct($latitude = 0, $longitude = 0, $latitude2 = 0, $longitude2 = 0, $in_kms = TRUE) { $EARTH_RADIUS_MILES = 3963; // Miles $miles2kms = 1.609; $dist = 0; // Convert degrees to radians $latitude = $latitude * M_PI / 180; $longitude = $longitude * M_PI / 180; $latitude2 = $latitude2 * M_PI / 180; $longitude2 = $longitude2 * M_PI / 180; if ($latitude != $latitude2 || $longitude != $longitude2) { // The two points are not the same $dist = sin($latitude) * sin($latitude2) + cos($latitude) * cos($latitude2) * cos($longitude2 - $longitude); // Safety check if ($dist > 0) { $sqrt = sqrt(1 - $dist * $dist); if ($sqrt > 0) { $dist = $EARTH_RADIUS_MILES * (-1 * atan($dist / $sqrt) + M_PI / 2); } } } if ($in_kms) { $dist = $dist * $miles2kms; } $this->dist = round($dist, 2); }
function ClippingRoundedRect($x, $y, $w, $h, $r, $outline = false) { $k = $this->k; $hp = $this->h; $op = $outline ? 'S' : 'n'; $MyArc = 4 / 3 * (sqrt(2) - 1); $this->_out(sprintf('q %.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k)); $xc = $x + $w - $r; $yc = $y + $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $y) * $k)); $this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc); $xc = $x + $w - $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $yc) * $k)); $this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r); $xc = $x + $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($y + $h)) * $k)); $this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc); $xc = $x + $r; $yc = $y + $r; $this->_out(sprintf('%.2F %.2F l', $x * $k, ($hp - $yc) * $k)); $this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r); $this->_out(' W ' . $op); }
function codesword_sd_ohlc($real, $period = 20) { $std_dev = []; $k = 2; //the standard deviation multiplier $ctr = 0; for ($i = $period - 1; $i < count($real); $i++) { //get the mean/average $sum = 0; for ($j = 0; $j < $period; $j++) { $temp = $i - $j; $sum += $real[$temp][4]; } $fMean = $sum / $period; //compute the variance $fVariance = 0; for ($j = 0; $j < $period; $j++) { $temp = $i - $j; $fVariance += pow($real[$temp][4] - $fMean, 2); } $fVariance = $fVariance / $period; //timestamp value $std_dev[$ctr][0] = $real[$i][0]; //mean value $std_dev[$ctr][1] = $fMean; //standard deviation value $std_dev[$ctr][2] = round(sqrt($fVariance), 4); $ctr++; } return $std_dev; }
protected function score($a, $b) { $sumA = 0; $sumASquare = 0; $sumB = 0; $sumBSquare = 0; $total = 0; $l = 0; foreach ($a as $i => $val) { if (!$b[$i]) { continue; } $sumA += $a[$i]; $sumB += $b[$i]; $sumASquare += pow($a[$i], 2); $sumBSquare += pow($b[$i], 2); $total += $a[$i] * $b[$i]; $l++; } if (!$l) { return 0; } $num = $total - $sumA * $sumB / $l; $den = sqrt(($sumASquare - pow($sumA, 2) / $l) * ($sumBSquare - pow($sumB, 2) / $l)); return $den > 0 ? (double) ($num / $den) : 0; }
public function inverse($p) { #$rh; /* Rho */ #$z; /* angle */ #$sinc, $cosc; #$c; #$lon , $lat; /* Inverse equations -----------------*/ $p->x = ($p->x - $this->x0) / $this->a; $p->y = ($p->y - $this->y0) / $this->a; $p->x /= $this->k0; $p->y /= $this->k0; if ($rh = sqrt($p->x * $p->x + $p->y * $p->y)) { $c = atan2($rh, $this->rc); $sinc = sin($c); $cosc = cos($c); $lat = Sourcemap_Proj::asinz($cosc * $this->sin_p14 + $p->y * $sinc * $this->cos_p14 / $rh); $lon = atan2($p->x * $sinc, $rh * $this->cos_p14 * $cosc - $p->y * $this->sin_p14 * $sinc); $lon = Sourcemap_Proj::adjust_lon($this->long0 + lon); } else { $lat = $this->phic0; $lon = 0.0; } $p->x = $lon; $p->y = $lat; return p; }
/** * @param type $p * @return type */ public function inverse($p) { // descale and de-offset $p->x = ($p->x - $this->x0) / $this->a; $p->y = ($p->y - $this->y0) / $this->a; $p->x /= $this->k0; $p->y /= $this->k0; if ($rho = sqrt($p->x * $p->x + $p->y * $p->y)) { $c = 2.0 * atan2($rho, $this->R2); $sinc = sin($c); $cosc = cos($c); $lat = asin($cosc * $this->sinc0 + $p->y * $sinc * $this->cosc0 / $rho); $lon = atan2($p->x * $sinc, $rho * $this->cosc0 * $cosc - $p->y * $this->sinc0 * $sinc); } else { $lat = $this->phic0; $lon = 0.0; } $p->x = $lon; $p->y = $lat; //$p = Proj4php::$proj['gauss']->inverse($p); $p = parent::inverse($p); // adjust longitude to CM $p->x = Common::adjust_lon($p->x + $this->long0); return $p; }
function RoundedRect($x, $y, $w, $h, $r, $style = '') { $k = $this->k; $hp = $this->h; if ($style == 'F') { $op = 'f'; } elseif ($style == 'FD' || $style == 'DF') { $op = 'B'; } else { $op = 'S'; } $MyArc = 4 / 3 * (sqrt(2) - 1); $this->_out(sprintf('%.2F %.2F m', ($x + $r) * $k, ($hp - $y) * $k)); $xc = $x + $w - $r; $yc = $y + $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - $y) * $k)); $this->_Arc($xc + $r * $MyArc, $yc - $r, $xc + $r, $yc - $r * $MyArc, $xc + $r, $yc); $xc = $x + $w - $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', ($x + $w) * $k, ($hp - $yc) * $k)); $this->_Arc($xc + $r, $yc + $r * $MyArc, $xc + $r * $MyArc, $yc + $r, $xc, $yc + $r); $xc = $x + $r; $yc = $y + $h - $r; $this->_out(sprintf('%.2F %.2F l', $xc * $k, ($hp - ($y + $h)) * $k)); $this->_Arc($xc - $r * $MyArc, $yc + $r, $xc - $r, $yc + $r * $MyArc, $xc - $r, $yc); $xc = $x + $r; $yc = $y + $r; $this->_out(sprintf('%.2F %.2F l', $x * $k, ($hp - $yc) * $k)); $this->_Arc($xc - $r, $yc - $r * $MyArc, $xc - $r * $MyArc, $yc - $r, $xc, $yc - $r); $this->_out($op); }
function primeFactors($n) { if (!is_numeric($n)) { trigger_error("Argument must be numeric", E_USER_NOTICE); return false; } if ($n === 1) { $factors[1] = 1; return $factors; } $e = 0; $factors = []; while ($n % 2 == 0) { $factors[2] = 2; $n = $n / 2; $e++; } if ($e > 0) { $factors[2] = $e; $e = 0; } for ($i = 3; $i <= sqrt($n); $i = $i + 2, $e = 0) { while ($n % $i == 0) { $e++; $n = $n / $i; } if ($e > 0) { $factors[$i] = $e; } } if ($n > 2) { $factors[$n] = 1; } return $factors; }
function render_block($left_side, $top_side, $right_side) { global $size; $size = 2048; $x1 = (2 - sqrt(3)) * 0.25 * $size; $x2 = 0.5 * $size; $x3 = (2 + sqrt(3)) * 0.25 * $size; $y1 = 0; $y2 = 0.25 * $size; $y3 = 0.5 * $size; $y4 = 0.75 * $size; $y5 = $size; $first_poligon = array($x1, $y2, $x2, $y3, $x2, $y5, $x1, $y4); $second_poligon = array($x1, $y2, $x2, $y1, $x3, $y2, $x2, $y3); $third_poligon = array($x2, $y3, $x3, $y2, $x3, $y4, $x2, $y5); $im = imagecreatetruecolor($size, $size); // Transparentbackground imagealphablending($im, true); imagesavealpha($im, true); $trans = imagecolorallocatealpha($im, 0, 0, 0, 127); imagefill($im, 0, 0, $trans); imagetranslatedtexture($im, $first_poligon, imagelight(load_png($left_side), 96)); imagetranslatedtexture($im, $second_poligon, load_png($top_side)); imagetranslatedtexture($im, $third_poligon, imagelight(load_png($right_side), 64)); return $im; }
/** * draws relation links and arrows * shows foreign key relations * * @param boolean $showColor Whether to use one color per relation or not * * @global object $eps The current EPS document * * @access public * @see PMA_EPS * * @return void */ public function relationDraw($showColor) { global $eps; /* Commented because $color unused. if ($showColor) { $listOfColors = array( 'red', 'grey', 'black', 'yellow', 'green', 'cyan', 'orange' ); shuffle($listOfColors); $color = $listOfColors[0]; } else { $color = 'black'; }*/ // draw a line like -- to foreign field $eps->line($this->xSrc, $this->ySrc, $this->xSrc + $this->srcDir * $this->wTick, $this->ySrc, 1); // draw a line like -- to master field $eps->line($this->xDest + $this->destDir * $this->wTick, $this->yDest, $this->xDest, $this->yDest, 1); // draw a line that connects to master field line and foreign field line $eps->line($this->xSrc + $this->srcDir * $this->wTick, $this->ySrc, $this->xDest + $this->destDir * $this->wTick, $this->yDest, 1); $root2 = 2 * sqrt(2); $eps->line($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc + $this->wTick / $root2, 1); $eps->line($this->xSrc + $this->srcDir * $this->wTick * 0.75, $this->ySrc, $this->xSrc + $this->srcDir * (0.75 - 1 / $root2) * $this->wTick, $this->ySrc - $this->wTick / $root2, 1); $eps->line($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest + $this->wTick / $root2, 1); $eps->line($this->xDest + $this->destDir * $this->wTick / 2, $this->yDest, $this->xDest + $this->destDir * (0.5 + 1 / $root2) * $this->wTick, $this->yDest - $this->wTick / $root2, 1); }
function stdev(Array $x) { $n = count($x); if($n == 0 || ($n - 1) == 0) return null; $sum = sum($x); $sumSq = sum_sq($x); return sqrt(($sumSq - (pow($sum, 2)/$n))/($n - 1)); }
function wp_rp_generate_auto_tags($post) { $suitable_words = wp_rp_get_unigrams(); $words = array_slice(array_merge(explode(' ', $post->post_title), explode(' ', $post->post_content)), 0, WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_WORDS); $bag_of_words = array(); foreach ($words as $word) { $word = strtolower($word); $word = preg_replace('/[\\W_]+/', '', $word); $stem = PorterStemmer::Stem($word); if ($stem) { if (!isset($bag_of_words[$stem])) { $bag_of_words[$stem] = 1; } else { $bag_of_words[$stem] += 1; } } } $selected_words = array(); foreach ($bag_of_words as $word => $freq) { if (isset($suitable_words[$word])) { $selected_words[$word] = $suitable_words[$word] * sqrt($freq); } } asort($selected_words); $selected_words = array_reverse($selected_words, true); $auto_tags = array_slice($selected_words, 0, WP_RP_RECOMMENDATIONS_AUTO_TAGS_MAX_TAGS, true); return array_keys($auto_tags); }
/** * @param $number * @return float * @throws \Exception */ public static function get($number) { if (static::isNotValid($number)) { throw new \Exception('Number must not be zero or negative.'); } return round(pow((sqrt(5) + 1) / 2, $number - 1) / sqrt(5)); }
/** * 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); }
function find_squares($num) { $ct = 0; $max = sqrt($num) + 1; $i = 0; $squares = array(); while ($i <= $max) { $remainder = $num - $i * $i; if (sqrt($remainder) == (int) sqrt($remainder)) { // echo "for $num - $i " . sqrt($remainder) . "\n"; $found = false; for ($j = 0; $j < count($squares); $j++) { if ($i == $squares[$j] || sqrt($remainder) == $squares[$j]) { $found = true; break; } } if (!$found) { $ct++; array_push($squares, $i); array_push($squares, sqrt($remainder)); } } $i++; } return $ct; }
static function aireTriangle($pointA, $pointB, $pointC) { $AB = Point::distance($pointA, $pointB); $BC = Point::distance($pointB, $pointC); $AC = Point::distance($pointC, $pointA); return sqrt(($AB + $BC + $AC) * (-$AB + $BC + $AC) * ($AB - $BC + $AC) * ($AB + $BC - $AC)) / 4; }
function Correlation($array1, $array2) { $avg_array1 = average($array1); $avg_array2 = average($array2); #print "$avg_array1----- $avg_array2<br>"; $sum_correlation_up = 0; for ($i = 0; $i < count($array1); $i++) { $sum_correlation_up = $sum_correlation_up + ($array1[$i] - $avg_array1) * ($array2[$i] - $avg_array2); } #print $sum_correlation_up."<br>"; $sum_array1_sumpow2 = 0; for ($i = 0; $i < count($array1); $i++) { $sum_array1_sumpow2 = $sum_array1_sumpow2 + pow($array1[$i] - $avg_array1, 2); } $sum_array1_sumpow2_sqrt = sqrt($sum_array1_sumpow2); #rint $sum_array1_sumpow2_sqrt."<br>"; $sum_array2_sumpow2 = 0; for ($i = 0; $i < count($array1); $i++) { $sum_array2_sumpow2 = $sum_array2_sumpow2 + pow($array2[$i] - $avg_array2, 2); } $sum_array2_sumpow2_sqrt = sqrt($sum_array2_sumpow2); #print $sum_array2_sumpow2_sqrt."<br>"; $correlation = $sum_correlation_up / ($sum_array1_sumpow2_sqrt * $sum_array2_sumpow2_sqrt); return $correlation; }
function get_primes7($n) { if ($n < 2) { return array(); } if ($n == 2) { return array(2); } $s = range(3, $n, 2); $mroot = sqrt($n); $half = count($s); $i = 0; $m = 3; while ($m <= $mroot) { if ($s[$i]) { $j = (int) (($m * $m - 3) / 2); $s[$j] = 0; while ($j < $half) { $s[$j] = 0; $j += $m; } } $i = $i + 1; $m = 2 * $i + 3; } $res = array(2); foreach ($s as $v) { if ($v) { $res[] = $v; } } return $res; }