Example #1
0
 public function drawSegment(Line $line, array $options = array())
 {
     $point1 = $this->drawPoint($line->getPointA(), $options);
     $point2 = $this->drawPoint($line->getPointB(), $options);
     $data_segment = json_encode(array_merge($options, $this->getOptionsByPrefix(self::SEGMENT_PREFIX)), JSON_NUMERIC_CHECK);
     $name_segment = 'l' . uniqid();
     $data_ghostline = json_encode(array_merge($options, $this->getOptionsByPrefix(self::GHOST_LINE_PREFIX)), JSON_NUMERIC_CHECK);
     $name_ghostline = 'gl' . uniqid();
     if ($this->getOption('build_segment_ghost') == true && (!array_key_exists('build_segment_ghost', $options) || $options['build_segment_ghost'] == true)) {
         $this->addOutput("var {$name_ghostline} = {$this->_brd}.create('line', [{$point1},{$point2}], {$data_ghostline});");
     }
     $this->addOutput("var {$name_segment} = {$this->_brd}.create('line', [{$point1},{$point2}], {$data_segment});");
     return $name_segment;
 }
Example #2
0
 /**
  * Test if two segments are parallels
  *
  * This will test if the two lines drawn from the two segments verify the Thales theorem
  * by comparing [ab] (segment 1), [cd] (segment 2) and a fifth point [e] used to build
  * triangles:
  *
  *      [ae]/[ce] == [be]/[de] ?
  *
  * @param   \Maths\Geometry\Line     $line1
  * @param   \Maths\Geometry\Line     $line2
  * @return  bool
  */
 public static function areParallels(Line $line1, Line $line2)
 {
     if ($line1->isHorizontal() && $line2->isHorizontal() || $line1->isVertical() && $line2->isVertical()) {
         return true;
     }
     $line1->rearrange();
     $line2->rearrange();
     $abs = array($line1->getPointA()->getAbscissa(), $line1->getPointB()->getAbscissa(), $line2->getPointA()->getAbscissa(), $line2->getPointB()->getAbscissa());
     $ords = array($line1->getPointA()->getOrdinate(), $line1->getPointB()->getOrdinate(), $line2->getPointA()->getOrdinate(), $line2->getPointB()->getOrdinate());
     $e = new Point(rand(0, 10) + (max($abs) + abs(min($abs))), rand(0, 10) + (max($ords) + abs(min($ords))));
     $segAE = new Segment($line1->getPointA(), $e);
     $segBE = new Segment($line1->getPointB(), $e);
     $intersectCE = self::getLinesIntersection($segAE, $line2);
     $segCE = new Segment($intersectCE, $e);
     $intersectDE = self::getLinesIntersection($segBE, $line2);
     $segDE = new Segment($intersectDE, $e);
     /*
     echo <<<TYPEOTHER
             var demo1 = brd.create('point', [{$line1->getPointA()->x},{$line1->getPointA()->y}], {
                 name: 'a'
             });
             var demo2 = brd.create('point', [{$line1->getPointB()->x},{$line1->getPointB()->y}], {
                 name: 'b'
             });
             var segment1 = brd.create('line', [demo1,demo2], {straightFirst:false,straightLast:false});
     
             var demo3 = brd.create('point', [{$intersectCE->x},{$intersectCE->y}], {
                 name: 'c'
             });
             var demo4 = brd.create('point', [{$intersectDE->x},{$intersectDE->y}], {
                 name: 'd'
             });
             var segment2 = brd.create('line', [demo3,demo4], {straightFirst:false,straightLast:false});
     
             var demo5 = brd.create('point', [{$e->x},{$e->y}], {
                 name: 'e'
             });
             var segment3 = brd.create('line', [demo1,demo5], {straightFirst:false,straightLast:false,color:'#404040'});
             var segment4 = brd.create('line', [demo2,demo5], {straightFirst:false,straightLast:false,color:'#404040'});
             var segment5 = brd.create('line', [demo3,demo5], {straightFirst:false,straightLast:false,color:'#404040'});
             var segment6 = brd.create('line', [demo4,demo5], {straightFirst:false,straightLast:false,color:'#404040'});
     TYPEOTHER;
     */
     return (bool) ($segAE->getLength() / $segCE->getLength() == $segBE->getLength() / $segDE->getLength());
 }