public function attackEntity(Entity $player) { if ($this->attackDelay > 30 && mt_rand(1, 32) < 4 && $this->distanceSquared($player) <= 200) { $this->attackDelay = 0; $f = 2; $yaw = $this->yaw + mt_rand(-220, 220) / 10; $pitch = $this->pitch + mt_rand(-120, 120) / 10; $nbt = new CompoundTag("", ["Pos" => new ListTag("Pos", [new DoubleTag("", $this->x + -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 2), new DoubleTag("", $this->y + 2), new DoubleTag("", $this->z + cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI) * 2)]), "Motion" => new ListTag("Motion", [new DoubleTag("", -sin($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI)), new DoubleTag("", -sin($pitch / 180 * M_PI) * $f), new DoubleTag("", cos($yaw / 180 * M_PI) * cos($pitch / 180 * M_PI))]), "Rotation" => new ListTag("Rotation", [new FloatTag("", $yaw), new FloatTag("", $pitch)])]); $fireball = Entity::createEntity("FireBall", $this->chunk, $nbt, $this); if ($fireball instanceof FireBall) { $fireball->setExplode(true); } $fireball->setMotion($fireball->getMotion()->multiply($f)); $ev = new EntityShootBowEvent($this, Item::get(Item::ARROW, 0, 1), $fireball, $f); $this->server->getPluginManager()->callEvent($ev); $projectile = $ev->getProjectile(); if ($ev->isCancelled()) { $projectile->kill(); } elseif ($projectile instanceof Projectile) { $this->server->getPluginManager()->callEvent($launch = new ProjectileLaunchEvent($projectile)); if ($launch->isCancelled()) { $projectile->kill(); } else { $projectile->spawnToAll(); $this->level->addSound(new LaunchSound($this), $this->getViewers()); } } } }
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 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; }
protected function _createPie($parameter) { $step = ($parameter['end'] - $parameter['start']) / $parameter['detail']; // center $centerTop = new Image_3D_Point(0, 0, 0.5); $centerBottom = new Image_3D_Point(0, 0, -0.5); // Add polygones for top and bottom of the pie $x = cos($parameter['start']) * $parameter['outside']; $y = sin($parameter['start']) * $parameter['outside']; $top = new Image_3D_Point($x, $y, 0.5); $bottom = new Image_3D_Point($x, $y, -0.5); // Polygones for the opening side $this->_addPolygon(new Image_3D_Polygon($top, $centerTop, $centerBottom)); $this->_addPolygon(new Image_3D_Polygon($bottom, $top, $centerBottom)); for ($i = 1; $i <= $parameter['detail']; $i++) { $x = cos($parameter['start'] + $i * $step) * $parameter['outside']; $y = sin($parameter['start'] + $i * $step) * $parameter['outside']; $newTop = new Image_3D_Point($x, $y, 0.5); $newBottom = new Image_3D_Point($x, $y, -0.5); $this->_addPolygon(new Image_3D_Polygon($centerTop, $top, $newTop)); $this->_addPolygon(new Image_3D_Polygon($centerBottom, $bottom, $newBottom)); // Rand $this->_addPolygon(new Image_3D_Polygon($top, $newBottom, $newTop)); $this->_addPolygon(new Image_3D_Polygon($top, $bottom, $newBottom)); $top = $newTop; $bottom = $newBottom; } // Polygones for the closing side $this->_addPolygon(new Image_3D_Polygon($top, $centerTop, $centerBottom)); $this->_addPolygon(new Image_3D_Polygon($bottom, $top, $centerBottom)); }
public function scopeNearLatLong($query, $lat, $lng, $radius = 10, $unit = 69.0) { if (!is_numeric($lat) || -90 >= $lat || $lat >= 90) { throw new RangeException("Latitude must be between -90 and 90 degrees."); } if (!is_numeric($lng) || -180 >= $lng || $lng >= 180) { throw new RangeException("Longitude must be between -180 and 180 degrees."); } $subQuery = clone $query; $latDistance = $radius / $unit; $latNorth = $lat - $latDistance; $latSouth = $lat + $latDistance; $lngDistance = $radius / ($unit * cos(deg2rad($lat))); $lngEast = $lng - $lngDistance; $lngWest = $lng + $lngDistance; $subQuery->selectRaw(DB::raw('*, (? * DEGREES( ACOS( COS(RADIANS(?)) * COS(RADIANS(latitude)) * COS(RADIANS(? - longitude)) + SIN(RADIANS(?)) * SIN(RADIANS(latitude)) ) )) AS distance'))->addBinding([$unit, $lat, $lng, $lat], 'select'); $subQuery->whereBetween('latitude', [$latNorth, $latSouth]); $subQuery->whereBetween('longitude', [$lngEast, $lngWest]); $query->from(DB::raw('(' . $subQuery->toSql() . ') as d')); $query->mergeBindings($subQuery->getQuery()); $query->where('distance', '<=', $radius); // // To use: // $latitude = 29.443778; // $longitude = -98.478903; // // Default radius is 10; default unit is miles. // Model::nearLatLong($latitude, $longitude)->get(); }
/** * 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); }
/** * This function generates a pie chart of the given data. * It uses the technology provided by the {@link Chart} class to generate a pie chart from the given data.<br> * You can pass the following options to the this method by using {@link Chart::get()}:<br> * * cx & cy - The coordinates of the center point of the pie chart.<br> * * r - The radius of the pie chart. * @param array An array of options, see {@link Chart::get()}. * @return string * @see Chart::get() */ function get($options) { $cx = $options["cx"] ? $options["cx"] : 200; $cy = $options["cy"] ? $options["cy"] : 200; $r = $options["r"] ? $options["r"] : 150; $x1 = $cx; $y1 = $cy - $r; $alpha = 0; $output = ""; $count = 0; $data = $this->chart->data; $sum = 0; foreach ($data as $obj) { $sum += $obj->value; } $colors = $this->chart->colors; foreach ($data as $obj) { $alpha = $alpha + $obj->percent / 100 * (2 * M_PI); $x2 = $cx + $r * sin($alpha); $y2 = $cy - $r * cos($alpha); $over180 = $obj->percent > 50 ? "1" : "0"; $color = $this->chart->getColor($count); $output .= "<path d='M{$cx},{$cy} L{$x1},{$y1} A{$r},{$r} 0 {$over180},1 {$x2},{$y2} Z' fill='{$color}' opacity='0.6'/>\n\n"; $x1 = $x2; $y1 = $y2; $count++; } if (isset($this->options["legend"])) { $x = $cx + $r * 1.2; $y = $cy - $r; $this->options["legend"]["x"] = $x; $this->options["legend"]["y"] = $y; } return $output; }
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; }
/** * 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); }
/** * Calculate Great Circle distance */ function __construct($latitude, $longitude, $latitude_origin, $longitude_origin) { $lat1 = $this->deg2rad($latitude_origin); $lat2 = $this->deg2rad($latitude); $lon1 = $this->deg2rad($longitude_origin); $lon2 = $this->deg2rad($longitude); $d = 2 * asin(sqrt(pow(sin(($lat1 - $lat2) / 2), 2) + cos($lat1) * cos($lat2) * pow(sin(($lon1 - $lon2) / 2), 2))); if ($d <= 1.0E-7) { $tc1 = 0; // less than 10 cm: going to self } elseif ($lat1 > M_PI / 2.0001) { $tc1 = M_PI; // starting from N pole } elseif ($lat1 < -M_PI / 2.0001) { $tc1 = 0; // starting from S pole } else { $tc1 = acos((sin($lat2) - sin($lat1) * cos($d)) / (sin($d) * cos($lat1))); if (sin($lon2 - $lon1) < 0) { $tc1 = 2 * M_PI - $tc1; } } $this->heading = rad2deg($tc1); $this->distance = rad2deg($d) * 60 * 1852; /* Assumes Earth radius of 6366.71 km */ }
/** * Calculate the distance between two * points using the Great Circle formula. * * Supply instances of the coordinate class. * * http://www.ga.gov.au/earth-monitoring/geodesy/geodetic-techniques/distance-calculation-algorithms.html#circle * * @param Treffynnon\Navigator\Coordinate $point1 * @param Treffynnon\Navigator\Coordinate $point2 * @return float */ public function calculate(N\LatLong $point1, N\LatLong $point2) { $celestialBody = $this->getCelestialBody(); $degrees = acos(sin($point1->getLatitude()->get()) * sin($point2->getLatitude()->get()) + cos($point1->getLatitude()->get()) * cos($point2->getLatitude()->get()) * cos($point2->getLongitude()->get() - $point1->getLongitude()->get())); $d = $degrees * $celestialBody->volumetricMeanRadius; return $d * 1000; }
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 function testDrawing() { $pdf = new Zend_Pdf(); // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page1 = $pdf->newPage('A4'); // Add new page generated by Zend_Pdf_Page object (page is not attached to the document) $pdf->pages[] = $page2 = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE); // Create new font $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // Apply font and draw text $page1->setFont($font, 36); $page1->setFillColor(Zend_Pdf_Color_Html::color('#9999cc')); $page1->drawText('Helvetica 36 text string', 60, 500); // Use font object for another page $page2->setFont($font, 24); $page2->drawText('Helvetica 24 text string', 60, 500); // Use another font $page2->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES), 32); $page2->drawText('Times-Roman 32 text string', 60, 450); // Draw rectangle $page2->setFillColor(new Zend_Pdf_Color_GrayScale(0.8)); $page2->setLineColor(new Zend_Pdf_Color_GrayScale(0.2)); $page2->setLineDashingPattern(array(3, 2, 3, 4), 1.6); $page2->drawRectangle(60, 400, 400, 350); // Draw circle $page2->setLineDashingPattern(Zend_Pdf_Page::LINE_DASHING_SOLID); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); $page2->drawCircle(85, 375, 25); // Draw sectors $page2->drawCircle(200, 375, 25, 2 * M_PI / 3, -M_PI / 6); $page2->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0)); $page2->drawCircle(200, 375, 25, M_PI / 6, 2 * M_PI / 3); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0)); $page2->drawCircle(200, 375, 25, -M_PI / 6, M_PI / 6); // Draw ellipse $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 0)); $page2->drawEllipse(250, 400, 400, 350); $page2->setFillColor(new Zend_Pdf_Color_Cmyk(1, 0, 0, 0)); $page2->drawEllipse(250, 400, 400, 350, M_PI / 6, 2 * M_PI / 3); $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 1, 0)); $page2->drawEllipse(250, 400, 400, 350, -M_PI / 6, M_PI / 6); // Draw and fill polygon $page2->setFillColor(new Zend_Pdf_Color_Rgb(1, 0, 1)); $x = array(); $y = array(); for ($count = 0; $count < 8; $count++) { $x[] = 140 + 25 * cos(3 * M_PI_4 * $count); $y[] = 375 + 25 * sin(3 * M_PI_4 * $count); } $page2->drawPolygon($x, $y, Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE, Zend_Pdf_Page::FILL_METHOD_EVEN_ODD); // Draw line $page2->setLineWidth(0.5); $page2->drawLine(60, 375, 400, 375); $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
/** * 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); }
public function renderGraph() { $this->i['top_heading_height'] = max(self::$c['size']['headers'] + 22 + self::$c['size']['key'], 48); $this->i['top_start'] = $this->i['top_heading_height'] + 50; $this->update_graph_dimensions($this->i['graph_width'], $this->i['graph_height'] + $this->i['top_start'], true); // Do the actual work $this->render_graph_init(); $this->graph_key_height(); $this->render_graph_key(); $this->render_graph_heading(); $data = array(1, 2, 3, 6, 7, 8, 9, 10); $center_block_x = round($this->i['graph_width'] / 2); $center_block_y = round($this->i['graph_height'] / 2); for ($ring = 0, $blocks_per_ring = count($data) <= 5 ? 5 : 4, $ring_size = ceil(count($data) / $blocks_per_ring); $ring < $ring_size; $ring++) { $depth = ($ring + 1) * (min($center_block_x, $center_block_y) / ($ring_size + 0.25)); for ($i = $ring * $blocks_per_ring, $i_size = $i + $blocks_per_ring; $i < $i_size; $i++) { $this_degree = 360 / $blocks_per_ring * ($i % $blocks_per_ring + $ring / $ring_size); $this_block_x = round($center_block_x + cos(deg2rad($this_degree)) * $depth); $this_block_y = round($center_block_y - sin(deg2rad($this_degree)) * $depth); $this->svg_dom->draw_svg_line($center_block_x, $center_block_y, $this_block_x, $this_block_y, self::$c['color']['notches'], 2); $this->svg_dom->add_element('rect', array('x' => $this_block_x - 20, 'y' => $this_block_y - 20, 'width' => 40, 'height' => 40, 'fill' => self::$c['color']['alert'])); } } $this->svg_dom->add_element('rect', array('x' => $center_block_x - 50, 'y' => $center_block_y - 50, 'width' => 100, 'height' => 100, 'fill' => self::$c['color']['alert'])); }
/** * Calculate an (approximate) OpenXML column width, based on font size and text contained * * @param int $fontSize Font size (in pixels or points) * @param bool $fontSizeInPixels Is the font size specified in pixels (true) or in points (false) ? * @param string $columnText Text to calculate width * @param int $rotation Rotation angle * @return int Column width */ public static function calculateColumnWidth($fontSize = 9, $fontSizeInPixels = false, $columnText = '', $rotation = 0) { if (!$fontSizeInPixels) { // Translate points size to pixel size $fontSize = PHPExcel_Shared_Font::fontSizeToPixels($fontSize); } // If it is rich text, use rich text... if ($columnText instanceof PHPExcel_RichText) { $columnText = $columnText->getPlainText(); } // Only measure the part before the first newline character if (strpos($columnText, "\r") !== false) { $columnText = substr($columnText, 0, strpos($columnText, "\r")); } if (strpos($columnText, "\n") !== false) { $columnText = substr($columnText, 0, strpos($columnText, "\n")); } // Calculate column width $columnWidth = (strlen($columnText) * $fontSize + 5) / $fontSize * 256 / 256; // Calculate approximate rotated column width if ($rotation !== 0) { if ($rotation == -165) { // stacked text $columnWidth = 4; // approximation } else { // rotated text $columnWidth = $columnWidth * cos(deg2rad($rotation)) + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation } } // Return return round($columnWidth, 6); }
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); } }
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; }
/** * get distance between to geocoords using great circle distance formula * @param Point $point1 * @param Point $point2 * @param string $unit M=miles, K=kilometers, N=nautical miles, I=inches, F=feet */ function distanceBetweenPoints($point1, $point2, $unit = 'K') { $lat1 = $point1->lat; $lng1 = $point1->lng; $lat2 = $point2->lat; $lng2 = $point2->lng; // calculate miles $M = 69.09 * rad2deg(acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lng1 - $lng2)))); switch (strtoupper($unit)) { case 'K': // kilometers return $M * 1.609344; break; case 'N': // nautical miles return $M * 0.868976242; break; case 'F': // feet return $M * 5280; break; case 'I': // inches return $M * 63360; break; case 'M': // miles return $M; break; default: // miles return $M; break; } }
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 }
/** * Adjust axes for block spacing, setting the depth unit */ protected function AdjustAxes(&$x_len, &$y_len) { // make sure project_angle is in range if ($this->project_angle < 1) { $this->project_angle = 1; } elseif ($this->project_angle > 90) { $this->project_angle = 90; } $ends = $this->GetAxisEnds(); $bars = $ends['k_max'][0] - $ends['k_min'][0] + 1; $a = deg2rad($this->project_angle); $depth = $this->depth; $u = $x_len / ($bars + $depth * cos($a)); $d = $u * $depth * sin($a); if ($d > $y_len) { // doesn't fit - use 1/2 y length $d = $y_len / 2; $u = $d / $depth * sin($a); } $c = $u * $depth * cos($a); $x_len -= $c; $y_len -= $d; $this->depth_unit = $u; return array($c, $d); }
public function onCommand(CommandSender $sender, Command $cmd, $label, array $sub) { $mm = "[TeleportView] "; if ($sender->getName() == "CONSOLE") { $sender->sendMessage($mm . ($this->isKorean() ? "게임내에서만 사용가능합니다." : "Please run this command in-game")); return true; } $yaw = $sender->getYaw(); $ptch = $sender->getPitch(); $yawS = -sin($yaw / 180 * M_PI); $yawC = cos($yaw / 180 * M_PI); $ptchS = -sin($ptch / 180 * M_PI); $ptchC = cos($ptch / 180 * M_PI); $x = $sender->getX(); $y = $sender->getY() + $sender->getEyeHeight(); $z = $sender->getZ(); $l = $sender->getLevel(); for ($f = 0; $f < 50; ++$f) { $x += $yawS * $ptchC; $y += $ptchS; $z += $yawC * $ptchC; $b = $l->getBlock(new Position($x, $y, $z, $l)); if ($b->isSolid) { $sender->teleport(new Position($x - $yawS * $ptchC, $y - $ptchS + 0.1, $z - $yawC * $ptchC, $l)); $f = true; } } if (!isset($f)) { $sender->sendMessage($mm . ($this->isKorean() ? "타겟 블럭이 너무 멉니다." : "TargetBlock is too far")); } return true; }
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])); } } }
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"); }
/** * @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 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 onCommand(CommandSender $sender, Command $cmd, $label, array $sub) { $mm = "[TeleportView] "; if ($sender->getName() == "CONSOLE") { $sender->sendMessage($mm . ($this->isKorean() ? "게임내에서만 사용가능합니다." : "Please run this command in-game")); return true; } $yaw = $sender->getYaw(); $pitch = $sender->getPitch(); $yawS = -sin($yaw / 180 * M_PI); $yawC = cos($yaw / 180 * M_PI); $pitchS = -sin($pitch / 180 * M_PI); $pitchC = cos($pitch / 180 * M_PI); $x = $sender->x; $y = $sender->y + $sender->getEyeHeight(); $z = $sender->z; $l = $sender->getLevel(); $ps = $this->getServer()->getOnlinePlayers(); for ($f = 0; $f < 50; ++$f) { $x += $yawS * $pitchC; $y += $pitchS; $z += $yawC * $pitchC; $b = $l->getBlock(new Position($x, $y, $z, $l)); if ($b->isSolid()) { break; } if ($f >= 50) { $sender->sendMessage($mm . ($this->isKorean() ? "타겟 블럭이 너무 멉니다." : "TargetBlock is too far")); return true; } } $sender->teleport(new Position($x, $y, $z, $sender->getLevel())); return true; }
/** * @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; }
/** * 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); }
function normalizedBoundingBox($center, $tolerance, $fromProj = null, $toProj = null) { if ($fromProj !== null || $toProj !== null) { $projector = new MapProjector(); } // create the bounding box in lat/lon first if ($fromProj !== null) { $projector->setSrcProj($fromProj); $center = $projector->projectPoint($center); } // approximate upper/lower bounds for lat/lon before calculating GCD $dLatRadians = $tolerance / EARTH_RADIUS_IN_METERS; // by haversine formula $dLonRadians = 2 * asin(sin($dLatRadians / 2) / cos($center['lat'] * M_PI / 180)); $dLatDegrees = $dLatRadians * 180 / M_PI; $dLonDegrees = $dLonRadians * 180 / M_PI; $min = array('lat' => $center['lat'] - $dLatDegrees, 'lon' => $center['lon'] - $dLonDegrees); $max = array('lat' => $center['lat'] + $dLatDegrees, 'lon' => $center['lon'] + $dLonDegrees); if ($toProj !== null) { $projector->setSrcProj(GEOGRAPHIC_PROJECTION); $projector->setDstProj($toProj); $min = $projector->projectPoint($min); $max = $projector->projectPoint($max); } return array('min' => $min, 'max' => $max, 'center' => $center); }