Question

I'm generating circles using the Midpoint circle algorithm. I don't want to draw these circles. Instead, I want to store them as polygons. Obviously, the coordinates are in the wrong order so if I would draw these circles using e.g. Graphics.DrawPolygon the circle would become a mesh of lines.

Q: How can I modify the algorithm to generate a correctly defined polygon? Or, how can I create a valid polygon from a set of points (in this case belonging to a circle)?

Update: This did the trick.

var firstHalf = points.Where(p => p.Y >= cy).OrderBy(p => p.X);
var secondHalf = points.Where(p => p.Y < cy).OrderByDescending(p => p.X);

var polygon = new List<Point>();
polygon.AddRange(firstHalf);
polygon.AddRange(secondHalf);
Was it helpful?

Solution

For the circle, it should be enough to sort the two halfs, e.g. sort in x above y_mid ascending and below y_mid descending. Togther those point should by your polygon.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top