Beispiel #1
0
 /**
  * @param Point $a
  * @param Point $b
  *
  * @return Line
  */
 public static function combineToRisingLine(Point $a, Point $b)
 {
     $minX = min($a->getX(), $b->getX());
     $maxX = max($a->getX(), $b->getX());
     $minY = min($a->getY(), $b->getY());
     $maxY = max($a->getY(), $b->getY());
     return new self(new Point($minX, $minY), new Point($maxX, $maxY));
 }
 /**
  * @return PointSet
  */
 public function produce()
 {
     /*
      * Bressenham's Midpoint Circle algorithm
      * http://stackoverflow.com/questions/1022178/how-to-make-a-circle-on-a-grid
      * http://rosettacode.org/wiki/Bitmap/Midpoint_circle_algorithm
      */
     $d = 3 - 2 * $this->radius;
     $x = 0;
     $y = $this->radius;
     $result = new PointSet();
     do {
         $this->addRow($result, new Point($this->center->getX() + $x, $this->center->getY() + $y), new Point($this->center->getX() - $x, $this->center->getY() + $y));
         $this->addRow($result, new Point($this->center->getX() - $x, $this->center->getY() - $y), new Point($this->center->getX() + $x, $this->center->getY() - $y));
         $this->addRow($result, new Point($this->center->getX() - $y, $this->center->getY() + $x), new Point($this->center->getX() + $y, $this->center->getY() + $x));
         $this->addRow($result, new Point($this->center->getX() - $y, $this->center->getY() - $x), new Point($this->center->getX() + $y, $this->center->getY() - $x));
         if ($d < 0) {
             $d = $d + 4 * $x + 6;
         } else {
             $d = $d + 4 * ($x - $y) + 10;
             --$y;
         }
         ++$x;
     } while ($x <= $y);
     return $result;
 }
Beispiel #3
0
 /**
  * @param Point $a
  * @param Point $b
  *
  * @return LinearFunction
  *
  * @throws \RuntimeException When $a and $b points have same x
  */
 public static function fromTwoPoints(Point $a, Point $b)
 {
     if ($a->getX() === $b->getX()) {
         throw new \RuntimeException('Line can be defined only by two points with different X');
     }
     $k = ($a->getY() - $b->getY()) / ($a->getX() - $b->getX());
     $n = $a->getY() - $k * $a->getX();
     return new self($k, $n);
 }