示例#1
0
文件: BoundingBox.php 项目: XTAIN/geo
 /**
  * @param Point    $center
  * @param Distance $distance
  *
  * @return BoundingBox
  * @author Maximilian Ruta <*****@*****.**>
  */
 public static function createFromCenterAndDistance(Point $center, Distance $distance)
 {
     $distanceInDegrees = $distance->getInGeographicDegrees() / 2;
     $sw = new Point($center->getLatitude() - $distanceInDegrees, $center->getLongitude() - $distanceInDegrees);
     $ne = new Point($center->getLatitude() + $distanceInDegrees, $center->getLongitude() + $distanceInDegrees);
     return new BoundingBox($sw, $ne);
 }
示例#2
0
 public function testWithoutUnit()
 {
     $Distance = new Distance();
     $this->assertEquals('100', $Distance->set(0.1)->stringMeter(false));
     $this->assertEquals('0,10', $Distance->set(0.1)->stringKilometer(false, 2));
     $this->assertEquals('1.0', $Distance->set(1.609)->stringMiles(false, 1));
 }
示例#3
0
 public static function fromCenterAndDistance(GeolocationInterface $center, Distance $distance)
 {
     $radLat = deg2rad($center->getLat());
     $radLon = deg2rad($center->getLong());
     // angular distance in radians on a great circle
     $radDist = $distance->getMeters() / GeolocationInterface::EARTH_RADIUS;
     $minLat = $radLat - $radDist;
     $maxLat = $radLat + $radDist;
     $deltaLon = asin(sin($radDist) / cos($radLat));
     $minLon = $radLon - $deltaLon;
     //if (minLon < MIN_LON) {minLon += 2d * Math.PI;}
     $maxLon = $radLon + $deltaLon;
     //if (maxLon > MAX_LON) {maxLon -= 2d * Math.PI;}
     $min = new Geolocation(rad2deg($maxLat), rad2deg($minLon));
     $max = new Geolocation(rad2deg($minLat), rad2deg($maxLon));
     return new BoundingBox($min, $max);
 }
 public function distance()
 {
     $distance = 0;
     for ($i = 0; $i < count($this->places) - 1; $i++) {
         $distance += Distance::between($this->places[$i]->point, $this->places[$i + 1]->point);
     }
     return $distance;
 }
示例#5
0
 /**
  * Execute a Helmert Transform on this ECEF using the specified Bursa-Wolf Parameters
  *
  * @param     BursaWolfParameters    $bursaWolfParameters    The Bursa-Wolf parameter to use for the transform
  * @return    void
  * @throws    Exception
  */
 private function helmertTransform(BursaWolfParameters $bursaWolfParameters)
 {
     $ppmScaling = 1 + $bursaWolfParameters->getScaleFactor() / 1000000;
     $xCoordinate = $bursaWolfParameters->getTranslationVectors()->getX()->getValue() + $this->xCoordinate->getValue() * $ppmScaling + -$bursaWolfParameters->getRotationMatrix()->getX()->getValue(Angle::RADIANS) * $this->yCoordinate->getValue() + $bursaWolfParameters->getRotationMatrix()->getY()->getValue(Angle::RADIANS) * $this->zCoordinate->getValue();
     $yCoordinate = $bursaWolfParameters->getTranslationVectors()->getY()->getValue() + $bursaWolfParameters->getRotationMatrix()->getZ()->getValue(Angle::RADIANS) * $this->xCoordinate->getValue() + $this->yCoordinate->getValue() * $ppmScaling + -$bursaWolfParameters->getRotationMatrix()->getX()->getValue(Angle::RADIANS) * $this->zCoordinate->getValue();
     $zCoordinate = $bursaWolfParameters->getTranslationVectors()->getZ()->getValue() + -$bursaWolfParameters->getRotationMatrix()->getY()->getValue(Angle::RADIANS) * $this->xCoordinate->getValue() + $bursaWolfParameters->getRotationMatrix()->getX()->getValue(Angle::RADIANS) * $this->yCoordinate->getValue() + $this->zCoordinate->getValue() * $ppmScaling;
     $this->xCoordinate->setValue($xCoordinate);
     $this->yCoordinate->setValue($yCoordinate);
     $this->zCoordinate->setValue($zCoordinate);
 }
示例#6
0
 private function createRoadmaps(Roadmap $roadmap)
 {
     $places = $roadmap->getRemainingPlaces();
     $from = $roadmap->getLastPlace();
     $selections = [];
     foreach ($places as $selection) {
         $selections[] = ["distance" => Distance::between($from->point, $selection->point), "place" => $selection];
     }
     usort($selections, function ($a, $b) {
         return $a["distance"] <=> $b["distance"];
     });
     $selections = $this->selection->select($selections);
     $roadmaps = [];
     foreach ($selections as $i => $selection) {
         $currentRoadmap = $roadmap;
         if ($i != count($selections) - 1) {
             $currentRoadmap = clone $roadmap;
         }
         $currentRoadmap->addPlace($selection["place"]);
         $roadmaps[] = $currentRoadmap;
     }
     return $roadmaps;
 }
示例#7
0
 /**
  * Get the destination for a given initial bearing and distance along a great circle route
  *
  * @param     Angle                 $bearing      Initial bearing
  * @param     Distance              $distance     Distance to travel along the route
  * @param     ReferenceEllipsoid    $ellipsoid    If left blank, a default value of 6371009.0 metres will
  *                                                             be used for the Earth Mean Radius for the calculation;
  *                                                         If a reference ellipsoid is specified, the Authalic Radius for
  *                                                             that ellipsoid will be used.
  * @return    LatLong               The endpoint Lat/Long for a journey from this Lat/Long starting on a bearing
  *                                               of $bearing and travelling for $distance along a great circle route
  * @throws    Exception
  */
 public function getDestination(Angle $bearing, Distance $distance, ReferenceEllipsoid $ellipsoid = null)
 {
     if (!is_null($ellipsoid)) {
         $earthMeanRadius = $ellipsoid->getAuthalicRadius();
     } else {
         $earthMeanRadius = 6371009.0;
         // metres
     }
     $destinationLatitude = asin(sin($this->latitude->getValue(Angle::RADIANS)) * cos($distance->getValue() / $earthMeanRadius) + cos($this->latitude->getValue(Angle::RADIANS)) * sin($distance->getValue() / $earthMeanRadius) * cos($bearing->getValue(Angle::RADIANS)));
     $destinationLongitude = $this->longitude->getValue(Angle::RADIANS) + atan2(sin($bearing->getValue(Angle::RADIANS)) * sin($distance->getValue() / $earthMeanRadius) * cos($this->latitude->getValue(Angle::RADIANS)), cos($distance->getValue() / $earthMeanRadius) - sin($this->latitude->getValue(Angle::RADIANS)) * sin($destinationLatitude));
     return new LatLong(new LatLong\CoordinateValues(self::cleanLatitude($destinationLatitude), self::cleanLongitude($destinationLongitude), Angle::RADIANS));
 }
示例#8
0
 /**
  * @covers \Base\Geospatial\Distance
  */
 public function testGetter()
 {
     $distance = new Distance(1);
     $this->assertEquals(1, $distance->getMeters());
 }
示例#9
0
文件: Math.php 项目: folkevil/geokit
 /**
  * @param  mixed  $latLngOrBounds
  * @param  mixed  $distance       (in meters)
  * @return Bounds
  */
 public function shrink($latLngOrBounds, $distance)
 {
     return $this->transformBounds($latLngOrBounds, -Distance::normalize($distance)->meters());
 }
示例#10
0
 public function testResolveUnitAliasShouldThrowExceptionForInvalidAlias()
 {
     $this->setExpectedException('\\InvalidArgumentException');
     Distance::resolveUnitAlias('foo');
 }
示例#11
0
 public function testNegate()
 {
     $this->assertEquals(Distance::m(10)->neg()->m, -10);
 }
示例#12
0
 public function __construct($value = "")
 {
     self::$footToInch = $this->definitions[self::FOOT] / $this->definitions[self::INCH];
     $this->value = $value;
     parent::__construct();
 }
示例#13
0
        $this->m = $m;
        $this->u = $u;
        $this->g = $g;
        $this->t = $t;
    }
    function HandleA($f, $u, $m, $g, $t)
    {
        $this->a = ($f * 1.732 / 2 - $u * ($m * $g - $f * 0.5)) / $m;
        $this->x = 0.5 * $this->a * $t * $t + $this->a * $this->a * $t * $t / (2 * $u * $m * $g);
    }
    function __destruct()
    {
        echo "1:结果是:" . $this->x;
    }
}
$resultA = new Distance(40, 0.5, 5, 10, 2);
$resultA->HandleA(40, 0.5, 5, 10, 2);
/**
一光滑R=1m的圆环内,小球获得初速度v0,从最低点沿轨道上升,恰好经过最高点,
求初速度v0?
*/
class Balance
{
    private $g;
    private $r;
    private $v0;
    function HandleB($g, $r)
    {
        $this->g = $g;
        $this->r = $r;
        $this->v0 = sqrt(5 * $this->g * $this->r);
示例#14
0
 /**
  * Creates individual Entry objects of the appropriate type and
  * stores them as members of this entry based upon DOM data.
  *
  * @param DOMNode $child The DOMNode to process
  */
 protected function takeChildFromDOM($child)
 {
     $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
     switch ($absoluteNodeName) {
         case $this->lookupNamespace('exif') . ':' . 'distance';
             $distance = new Distance();
             $distance->transferFromDOM($child);
             $this->_distance = $distance;
             break;
         case $this->lookupNamespace('exif') . ':' . 'exposure';
             $exposure = new Exposure();
             $exposure->transferFromDOM($child);
             $this->_exposure = $exposure;
             break;
         case $this->lookupNamespace('exif') . ':' . 'flash';
             $flash = new Flash();
             $flash->transferFromDOM($child);
             $this->_flash = $flash;
             break;
         case $this->lookupNamespace('exif') . ':' . 'focallength';
             $focalLength = new FocalLength();
             $focalLength->transferFromDOM($child);
             $this->_focalLength = $focalLength;
             break;
         case $this->lookupNamespace('exif') . ':' . 'fstop';
             $fStop = new FStop();
             $fStop->transferFromDOM($child);
             $this->_fStop = $fStop;
             break;
         case $this->lookupNamespace('exif') . ':' . 'imageUniqueID';
             $imageUniqueId = new ImageUniqueId();
             $imageUniqueId->transferFromDOM($child);
             $this->_imageUniqueId = $imageUniqueId;
             break;
         case $this->lookupNamespace('exif') . ':' . 'iso';
             $iso = new ISO();
             $iso->transferFromDOM($child);
             $this->_iso = $iso;
             break;
         case $this->lookupNamespace('exif') . ':' . 'make';
             $make = new Make();
             $make->transferFromDOM($child);
             $this->_make = $make;
             break;
         case $this->lookupNamespace('exif') . ':' . 'model';
             $model = new Model();
             $model->transferFromDOM($child);
             $this->_model = $model;
             break;
         case $this->lookupNamespace('exif') . ':' . 'time';
             $time = new Time();
             $time->transferFromDOM($child);
             $this->_time = $time;
             break;
     }
 }
示例#15
0
 public static function getDistances($results)
 {
     $distances = array();
     foreach ($results as $key => $value) {
         $newDistance = new Distance();
         $newDistance->setValue($value[2]);
         $distances[$value[0] . $value[1]] = $newDistance;
     }
     return $distances;
 }
示例#16
0
 public function saveDistanceList($con = null)
 {
     if (!$this->isValid()) {
         throw $this->getErrorSchema();
     }
     if (!isset($this->widgetSchema['distance_list'])) {
         // somebody has unset this widget
         return;
     }
     if (null === $con) {
         $con = $this->getConnection();
     }
     $c = new Criteria();
     $c->add(DistancePeer::DISTANCETYPE_ID, $this->object->getPrimaryKey());
     DistancePeer::doDelete($c, $con);
     $values = $this->getValue('distance_list');
     if (is_array($values)) {
         foreach ($values as $value) {
             $obj = new Distance();
             $obj->setDistancetypeId($this->object->getPrimaryKey());
             $obj->setTrackAId($value);
             $obj->save();
         }
     }
 }
示例#17
0
 /**
  * Subtract a distance
  * @param Distance $distance Another Distance object
  * @return Distance Returns a new Distance object of same unit as current Distance
  */
 public function subtract(Distance $distance)
 {
     $value = $this->value - $distance->to($this->unit)->value();
     return new Distance($value, $this->unit);
 }
 /**
  * Get the Radius of Curvature along the Prime Vertical at a specified latitude
  * for this Reference Ellipsoid object
  *
  * The formula used here is from http://www.epsg.org/guides/docs/G7-2.pdf
  *
  * @param     integer|float    $latitude    Angle of Latitude for the Radius of Curvature,
  *                                              positive when to the north of the equator, negative when to the south
  * @param     string           $degrad      Indicating whether the Angle of Latitude is being specified
  *                                              in degrees or radians
  * @param     string           $uom         Unit of Measure for the returned value
  * @return    float            The Radius of Curvature along the Prime Vertical at the specified latitude
  *                                 for this ellipsoid
  * @throws    Exception
  */
 public function getRadiusOfCurvaturePrimeVertical($latitude = null, $degrad = Angle::DEGREES, $uom = Distance::METRES)
 {
     $latitude = LatLong::validateLatitude($latitude, $degrad);
     if ($this->dirty) {
         $this->calculateDerivedParameters();
     }
     $radius = $this->semiMajorAxis->getValue() / pow(1 - $this->firstEccentricitySquared * self::sinSquared($latitude), 0.5);
     return Distance::convertFromMeters($radius, $uom);
 }
示例#19
0
 /**
  * Subtract another distance
  * @param \Runalyze\Activity\Distance $object
  * @return \Runalyze\Activity\Distance $this-reference
  */
 public function subtract(Distance $object)
 {
     $this->Distance -= $object->kilometer();
     return $this;
 }
示例#20
0
 public function add(Distance $distance)
 {
     return new Distance($this->getMeters() + $distance->getMeters());
 }
示例#21
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Distance $value A Distance object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Distance $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = serialize(array((string) $obj->getTrackAId(), (string) $obj->getTrackBId(), (string) $obj->getFeaturevectortypeId(), (string) $obj->getDistancetypeId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }