distance() static public method

static public distance ( $point1, $point2 )
 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;
 }
 public function random_point_generation_disk($sizeX, $minDist, $maxDist)
 {
     $sizeY = $sizeX;
     // Initial point generation
     $this->add_point(new Point(round($sizeX / 2), round($sizeY / 2), '0'));
     $initialPoint = reset($this->vertices);
     for ($i = 65; $i < 91; $i++) {
         $letters[] = chr($i);
     }
     for ($i = 97; $i < 123; $i++) {
         $letters[] = chr($i);
     }
     $i = 0;
     // Point creation procedure
     $maxMissedPoints = 1000;
     $missedPointCount = 0;
     while ($missedPointCount < $maxMissedPoints) {
         $x = rand(0, $sizeX - 1);
         $y = rand(0, $sizeY - 1);
         $point = new Point($x, $y, $letters[$i]);
         $pointCreationFlag = false;
         if (Point::distance($point, $initialPoint) <= $sizeX / 2) {
             $pointCreationFlag = $this->add_point($point, $minDist, $maxDist);
         }
         if ($pointCreationFlag) {
             $missedPointCount = 0;
             $i++;
         } else {
             $missedPointCount++;
         }
     }
 }
Esempio n. 3
0
        $this->y = $this->validate($y);
    }
    public function __get($name)
    {
        return $this->{$name};
    }
    public function __set($name, $value)
    {
        $this->{$name} = $this->validate($value);
    }
    public function distance(Point $other)
    {
        return hypot($this->x - $other->x, $this->y - $other->y);
    }
    public function __toString()
    {
        return sprintf("(%g, %g)", $this->x, $this->y);
    }
}
function compare($x, $y)
{
    if ($x == $y) {
        echo $x . " is equal to " . $y . PHP_EOL;
    } else {
        echo $x . " is not equal to " . $y . PHP_EOL;
    }
}
$object = new Point(1, "a");
$object1 = new Point(6, 0);
echo $object->distance($object1) . PHP_EOL;
var_dump($object);
 public function getPerimeter()
 {
     $return = null;
     if (count($this->points) >= 2) {
         $perimeterPoints = $this->points;
         $perimeterPoints[] = $perimeterPoints[0];
         $perimeter = 0;
         for ($i = 0; $i < count($this->points); $i++) {
             $perimeter += Point::distance($perimeterPoints[$i], $perimeterPoints[$i + 1]);
         }
         $return = $perimeter;
     }
     return $return;
 }
Esempio n. 5
0
<!DOCTYPE HTML>
<html>
<body>

<?php 
ini_set('display_errors', 1);
error_reporting(E_ALL | E_STRICT);
?>


<?php 
# this code could go into a file named use_point.php
include "Point.php";
$p1 = new Point(0.0, 0.0);
$p2 = 3;
print "Distance between {$p1} and {$p2} is " . $p1->distance($p2) . "\n\n";
var_dump($p2);
# var_dump prints detailed state of an object
?>

</body>
</html>