Ejemplo n.º 1
0
 /**
  * Rectangle constructor.
  *
  * @param Point2d $pointA A point
  * @param Point2d $pointB B point
  * @param Point2d $pointC C point
  * @param Point2d $pointD D point
  * @throws Exception
  */
 public function __construct(Point2d $pointA, Point2d $pointB, Point2d $pointC, Point2d $pointD)
 {
     parent::__construct();
     $test1 = Point2d::getAngle($pointA, $pointD, $pointB);
     $test2 = Point2d::getAngle($pointB, $pointA, $pointC);
     $test3 = Point2d::getAngle($pointC, $pointB, $pointD);
     $test4 = Point2d::getAngle($pointD, $pointC, $pointA);
     if ($test1 != deg2rad(90) || $test2 != deg2rad(90) || $test3 != deg2rad(90) || $test4 != deg2rad(90)) {
         throw new Exception('Points must be draw a rectangle!');
     }
     $this->setPointA($pointA);
     $this->setPointB($pointB);
     $this->setPointC($pointC);
     $this->setPointD($pointD);
 }
Ejemplo n.º 2
0
 /**
  * @expectedException        Exception
  * @expectedExceptionMessage Points must be different than the center point!
  */
 public function testGetAngleException()
 {
     $p1 = new Point2d(0, 0);
     $p2 = new Point2d(0, 0);
     $p3 = new Point2d(0, 3);
     Point2d::getAngle($p1, $p2, $p3);
 }
Ejemplo n.º 3
0
 /**
  * Apply a vector on each point and return a new instance of Polygon
  *
  * @param Vector2d $vector
  * @return Polygon
  */
 public function translate(Vector2d $vector)
 {
     $buffer = clone $this;
     foreach ($buffer->_points as $index => $point) {
         $buffer->setPoint($index, Point2d::add($point, $vector));
     }
     return $buffer;
 }
Ejemplo n.º 4
0
 /**
  * Determines if this triangle is right
  *
  * @return bool
  */
 public function isRight()
 {
     $angles = [Point2d::getAngle($this->getPointA(), $this->getPointB(), $this->getPointC()), Point2d::getAngle($this->getPointB(), $this->getPointA(), $this->getPointC()), Point2d::getAngle($this->getPointC(), $this->getPointA(), $this->getPointB())];
     return in_array(deg2rad(90), $angles);
 }