circlePoint() public static method

Returns an x,y pair on circle, assuming center is 0,0.
public static circlePoint ( float $degrees, integer $diameter ) : array
$degrees float The degrees of arc to get the point for.
$diameter integer The diameter of the circle.
return array (x coordinate, y coordinate) of the point.
Example #1
0
File: Im.php Project: horde/horde
 /**
  * Draws an arc.
  *
  * @param integer $x      The x coordinate of the centre.
  * @param integer $y      The y coordinate of the centre.
  * @param integer $r      The radius of the arc.
  * @param integer $start  The start angle of the arc.
  * @param integer $end    The end angle of the arc.
  * @param string  $color  The line color of the arc.
  * @param string  $fill   The fill color of the arc (defaults to none).
  */
 public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none')
 {
     // Split up arcs greater than 180 degrees into two pieces.
     $this->_postSrcOperations[] = "-stroke {$color} -fill {$fill}";
     $mid = round(($start + $end) / 2);
     $x = round($x);
     $y = round($y);
     $r = round($r);
     if ($mid > 90) {
         $this->_postSrcOperations[] = "-draw \"ellipse {$x},{$y} {$r},{$r} {$start},{$mid}\"";
         $this->_postSrcOperations[] = "-draw \"ellipse {$x},{$y} {$r},{$r} {$mid},{$end}\"";
     } else {
         $this->_postSrcOperations[] = "-draw \"ellipse {$x},{$y} {$r},{$r} {$start},{$end}\"";
     }
     // If filled, draw the outline.
     if (!empty($fill)) {
         list($x1, $y1) = Horde_Image::circlePoint($start, $r * 2);
         list($x2, $y2) = Horde_Image::circlePoint($mid, $r * 2);
         list($x3, $y3) = Horde_Image::circlePoint($end, $r * 2);
         $verts = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1)));
         if ($mid > 90) {
             $verts1 = array(array('x' => $x + round($x2), 'y' => $y + round($y2)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1)));
             $verts2 = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x2), 'y' => $y + round($y2)));
             $this->polygon($verts1, $fill, $fill);
             $this->polygon($verts2, $fill, $fill);
         } else {
             $this->polygon($verts, $fill, $fill);
         }
         $this->polyline($verts, $color);
         $this->_postSrcOperations[] = '-stroke none -fill none';
     }
 }
Example #2
0
File: Svg.php Project: horde/horde
 /**
  * Draws an arc.
  *
  * @param integer $x      The x coordinate of the centre.
  * @param integer $y      The y coordinate of the centre.
  * @param integer $r      The radius of the arc.
  * @param integer $start  The start angle of the arc.
  * @param integer $end    The end angle of the arc.
  * @param string $color   The line color of the arc.
  * @param string $fill    The fill color of the arc (defaults to none).
  */
 public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = null)
 {
     if (!empty($fill)) {
         $style = 'fill:' . Horde_Image::getHexColor($fill) . '; ';
     } else {
         $style = 'fill:none;';
     }
     $style .= 'stroke:' . Horde_Image::getHexColor($color) . '; stroke-width:1';
     $mid = round(($start + $end) / 2);
     // Calculate the path entry.
     $path = '';
     // If filled, draw the outline.
     if (!empty($fill)) {
         // Start at the center of the ellipse the arc is on.
         $path .= "M {$x},{$y} ";
         // Draw out to ellipse edge.
         list($arcX, $arcY) = Horde_Image::circlePoint($start, $r * 2);
         $path .= 'L ' . round($x + $arcX) . ',' . round($y + $arcY) . ' ';
     }
     // Draw arcs.
     list($arcX, $arcY) = Horde_Image::circlePoint($mid, $r * 2);
     $path .= "A {$r},{$r} 0 0 1 " . round($x + $arcX) . ',' . round($y + $arcY) . ' ';
     list($arcX, $arcY) = Horde_Image::circlePoint($end, $r * 2);
     $path .= "A {$r},{$r} 0 0 1 " . round($x + $arcX) . ',' . round($y + $arcY) . ' ';
     // If filled, close the outline.
     if (!empty($fill)) {
         $path .= 'Z';
     }
     $path = trim($path);
     $this->_svg->addChild(new XML_SVG_Path(array('d' => $path, 'style' => $style)));
 }
Example #3
0
 /**
  * Draws an arc.
  *
  * @param integer $x      The x coordinate of the centre.
  * @param integer $y      The y coordinate of the centre.
  * @param integer $r      The radius of the arc.
  * @param integer $start  The start angle of the arc.
  * @param integer $end    The end angle of the arc.
  * @param string $color   The line color of the arc.
  * @param string $fill    The fill color of the arc (defaults to none).
  */
 public function arc($x, $y, $r, $start, $end, $color = 'black', $fill = 'none')
 {
     $points = Horde_Image::arcPoints($r, $start, $end);
     $points['x1'] += $x;
     $points['x2'] += $x;
     $points['x3'] += $x;
     $points['y1'] += $y;
     $points['y2'] += $y;
     $points['y3'] += $y;
     try {
         $draw = new ImagickDraw();
         $draw->setStrokeColor(new ImagickPixel($color));
         $draw->setFillColor(new ImagickPixel($fill));
         $draw->arc($x - $r, $y - $r, $x + $r, $y + $r, $start, $end);
     } catch (ImagickDrawException $e) {
         throw new Horde_Image_Exception($e);
     } catch (ImagickPixelException $e) {
         throw new Horde_Image_Exception($e);
     }
     // If filled, draw the outline.
     if (!empty($fill)) {
         $mid = round(($start + $end) / 2);
         list($x1, $y1) = Horde_Image::circlePoint($start, $r * 2);
         list($x2, $y2) = Horde_Image::circlePoint($mid, $r * 2);
         list($x3, $y3) = Horde_Image::circlePoint($end, $r * 2);
         $verts = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1)));
         if ($mid > 90) {
             $verts1 = array(array('x' => $x + round($x2), 'y' => $y + round($y2)), array('x' => $x, 'y' => $y), array('x' => $x + round($x1), 'y' => $y + round($y1)));
             $verts2 = array(array('x' => $x + round($x3), 'y' => $y + round($y3)), array('x' => $x, 'y' => $y), array('x' => $x + round($x2), 'y' => $y + round($y2)));
             $this->polygon($verts1, $fill, $fill);
             $this->polygon($verts2, $fill, $fill);
         } else {
             $this->polygon($verts, $fill, $fill);
         }
         $this->polyline($verts, $color);
     }
     try {
         $this->_imagick->drawImage($draw);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $draw->destroy();
 }