Exemplo n.º 1
0
 public function __construct(Coords $p0, Coords $dir, $len, $r0, $r1)
 {
     $vl = $dir->distance(0, 0, 0);
     if ($vl == 1) {
         $this->ap = atan2($dir->y, $dir->x);
         $this->av = asin($dir->z);
         $this->dir = clone $dir;
     } else {
         $this->ap = atan2($dir->y, $dir->x);
         $this->av = asin($dir->z / $vl);
         $this->dir = Coords::fromPolar(1, $this->ap, $this->av);
     }
     $this->p0 = clone $p0;
     $this->p1 = $p0->translate($len * $this->dir->x, $len * $this->dir->y, $len * $this->dir->z);
     $this->len = $len;
     $this->r0 = $r0;
     $this->r1 = $r1;
     $cap = cos($this->ap - M_PI / 2);
     $sap = sin($this->ap - M_PI / 2);
     $sav = sin($this->av - M_PI / 2);
     $points[] = new Coords($this->p0->x + $this->r0 * $cap, $this->p0->y + $this->r0 * $sap, $this->p0->z + $this->r0 * $sav);
     $points[] = new Coords($this->p0->x - $this->r0 * $cap, $this->p0->y - $this->r0 * $sap, $this->p0->z - $this->r0 * $sav);
     $points[] = new Coords($this->p1->x + $this->r1 * $cap, $this->p1->y + $this->r1 * $sap, $this->p1->z + $this->r1 * $sav);
     $points[] = new Coords($this->p1->x - $this->r1 * $cap, $this->p1->y - $this->r1 * $sap, $this->p1->z - $this->r1 * $sav);
     $this->red = new Coords(floor(min($points[0]['x'], $points[1]['x'], $points[2]['x'], $points[3]['x'])), floor(min($points[0]['y'], $points[1]['y'], $points[2]['y'], $points[3]['y'])), floor(min($points[0]['z'], $points[1]['z'], $points[2]['z'], $points[3]['z'])));
     $this->blue = new Coords(ceil(max($points[0]['x'], $points[1]['x'], $points[2]['x'], $points[3]['x'])), ceil(max($points[0]['y'], $points[1]['y'], $points[2]['y'], $points[3]['y'])), ceil(max($points[0]['z'], $points[1]['z'], $points[2]['z'], $points[3]['z'])));
 }