public function arc($x, $y, $radius, $startAngle, $endAngle, $anticlockwise) 
    {
        $TARGET_CHORD_LENGTH_PIXELS = 3;
        
        $sectors = floor((M_PI * $radius * 2) / $TARGET_CHORD_LENGTH_PIXELS);
        if ($sectors < 9) {
            $sectors = 9;
        }
        
        $sectorAngle = M_PI * 2 / $sectors;

        if ($startAngle == $endAngle) {
            return;
        }

        if ($anticlockwise) {
            $sectorAngle = -$sectorAngle;

            if ($startAngle - $endAngle >= M_PI * 2) {
                $endAngle = $startAngle - M_PI * 2;
            } else {
                // Normalize end angle so that the sweep angle is in the range 
                // (0, -2PI]
                $endAngle += 
                    M_PI * 2 * ceil(($startAngle - $endAngle) / 
                    (M_PI * 2) - 1);
            }
        } else {
            if ($endAngle - $startAngle >= M_PI * 2) {
                $endAngle = $startAngle + M_PI * 2;
            } else {
                // Normalize end angle so that the sweep angle is in the range 
                // (0, 2PI]
                $endAngle -= 
                    M_PI * 2 * ceil(($endAngle - $startAngle) / 
                    (M_PI * 2) - 1);
            }
        }
        
        $dx;
        $dy;
        $sectors = ($endAngle - $startAngle) / $sectorAngle;

        $angle = $startAngle;
        
        for ($i = 0; $i < $sectors; $i++) {
            $dx = cos($angle) * $radius;
            $dy = sin($angle) * $radius;
            $this->lineTo($x + $dx, $y + $dy);
            $angle += $sectorAngle;
        }

        $dx = cos($endAngle) * $radius;
        $dy = sin($endAngle) * $radius;
        $this->lineTo($x + $dx, $y + $dy);
    }