The following array contains a list of coordinates that I’m using to draw a polygon with ImageMagick:
$points = [
['x' => 40, 'y' => 10],
['x' => 20, 'y' => 20],
['x' => 70, 'y' => 50],
['x' => 60, 'y' => 15],
];
What I want to do is loop through this array and calculate the mid-point of each polyline by comparing each consecutive pair of coordinates including the first and last set i.e. the check must wrap-around either at the start or end of the loop. Is there a way to do this programatically without a lot of kludgey code to count the number of elements in the array and if() tests to determine when the first or last element has been reached, etc.?
2
Answers
Is this what you’re after? Updated
output of this is
Use modulus to wrap around to 0 at the end.