Example #1
0
 public static function isPointOnLine($point, $line)
 {
     $dx = $line->point1->x - $line->point2->x;
     $dy = $line->point1->y - $line->point2->y;
     $dz = $line->point1->z - $line->point2->z;
     // Create array of p
     $p = array();
     if (!Constant::isNumbersEqual($dx, 0)) {
         $p[] = ($point->x - $line->point2->x) / $dx;
     } else {
         // X coordinate of all point must be same
         if (!Constant::isNumbersEqual($point->x, $line->point1->x)) {
             return 0;
         }
     }
     if (!Constant::isNumbersEqual($dy, 0)) {
         $p[] = ($point->y - $line->point2->y) / $dy;
     } else {
         // Y coordinate of all point must be same
         if (!Constant::isNumbersEqual($point->y, $line->point1->y)) {
             return 0;
         }
     }
     if (!Constant::isNumbersEqual($dz, 0)) {
         $p[] = ($point->z - $line->point2->z) / $dz;
     } else {
         // Z coordinate of all point must be same
         if (!Constant::isNumbersEqual($point->z, $line->point1->z)) {
             return 0;
         }
     }
     // CASE 4
     if (count($p) == 0) {
         return 4;
     }
     // All members in p array must be same
     $isEqual = TRUE;
     if (count($p) > 1) {
         for ($i = 1; $i < count($p); $i++) {
             if (!Constant::isNumbersEqual($p[$i], $p[0])) {
                 $isEqual = FALSE;
             }
         }
     }
     // CASE 0
     if (!$isEqual) {
         return 0;
     }
     // CASE 2
     if (Constant::isNumbersEqual($p[0], 0) || Constant::isNumbersEqual($p[0], 1)) {
         return 2;
     }
     // CASE 3
     if ($p[0] > 0 && $p[0] < 1) {
         return 3;
     }
     // CASE 1
     return 1;
 }
 /**
  * @covers Classes\Utils\Math\Lines::findOverlappingOfTwoLines
  */
 public function testFindOverlappingOfTwoLines_9()
 {
     $p1 = new \Classes\Utils\AbstractInstance\Point(3, 3, 3);
     $p2 = new \Classes\Utils\AbstractInstance\Point(5, 5, 5);
     $p3 = new \Classes\Utils\AbstractInstance\Point(10, 10, 10);
     $p4 = new \Classes\Utils\AbstractInstance\Point(0, 0, 0);
     $line1 = new \Classes\Utils\AbstractInstance\Line($p1, $p2);
     $line2 = new \Classes\Utils\AbstractInstance\Line($p3, $p4);
     $overlap1 = array();
     $overlap2 = array();
     $this->assertEquals(Lines::findOverlappingOfTwoLines($line1, $line2, $overlap1, $overlap2), TRUE);
     $this->assertEquals(Constant::isNumbersEqual($overlap1[0], 0), TRUE);
     $this->assertEquals(Constant::isNumbersEqual($overlap1[1], 2 * sqrt(3)), TRUE);
     $this->assertEquals(Constant::isNumbersEqual($overlap2[0], 5 * sqrt(3)), TRUE);
     $this->assertEquals(Constant::isNumbersEqual($overlap2[1], 7 * sqrt(3)), TRUE);
 }