The code underneath draws a segment if you insert a segment number. This works fine. Now I want to draw the segment like this always:
I have tried to change the "90" in the $start array but this doesn't solve my problem. So I'm lost now. I appreciate any help.
<?php
function segment_circle($segments, $size = 200) {
$radius = $size / 2;
$segment_arc = 360 / $segments;
$generate_arc = function($start_angle, $end_angle) use ($radius) {
$start = [
'x' => $radius + ($radius * cos( ($end_angle - 90) * pi() / 180 )),
'y' => $radius + ($radius * sin( ( $end_angle - 90) * pi() / 180 ))
];
$end = [
'x' => $radius + ($radius * cos( ($start_angle - 90) * pi() / 180 )),
'y' => $radius + ($radius * sin( ($start_angle - 90) * pi() / 180 ))
];
$arc = $end_angle - $start_angle <= 180 ? '0' : '1';
return implode( ' ', [
// Move to
'M', $start[ 'x' ], $start[ 'y' ],
// Bogen zeichnen
'A', $radius, $radius, 0, $arc, 0, $end[ 'x' ], $end[ 'y' ],
// Line to / Close Path
'L', $radius, $radius, 'Z'
]);
};
?>
<svg width="<?php echo $size ?>" height="200" viewBox="0 0 <?php echo $size ?> <?php echo $size ?>" xmlns="http://www.w3.org/2000/svg">
<?php for ($i = 0; $i < 1; $i++): ?>
<?php
$start_angle = $segment_arc * $i;
$end_angle = $segment_arc * ($i + 1);
?>
<path fill="#FFFFFF" stroke="#000" stroke-width="1" d="<?php echo $generate_arc($start_angle, $end_angle) ?>" />
<?php endfor ?>
</svg>
<?php
}
echo segment_circle($getSegment);
}
Currently it draws this:



