Reputation: 4820
I have an ellipse:
Ellipse2D e2D = new Ellipse2D.Float(startPoint.x, startPoint.y, x - startPoint.x, y - startPoint.y);
And what I need is to get coordinates of all points that form circumference.
ArrayList<Point> oneDraw = new ArrayList<>();
for (int i = startX; i < borderX; i++)
for (int j = startY; j < borderY; j++)
if (e2D.contains(new Point(i, j)))
oneDraw.add(new Point(i, j));
By doing so, I put all coordinates that are inside my circle to the list, but I don't need this.
Thank you for the answer and spent time.
Upvotes: 1
Views: 487
Reputation: 88707
Your approach would add all pixels in the box which are inside the ellipse to the list, i.e. you'd get the area of the ellipse rather than its circumference. I'd say it would be better to look for the correct formula and solve it for discrete x/y pairs.
Or yet better apply one of the algorithms for drawing ellipses that can be found on the net, e.g. this one: http://www.mathopenref.com/coordcirclealgorithm.html
Then get the pixels that have been drawn (if still needed).
Edit: if you have a look at the source code of Ellipse2D
you can either get an an idea of how to implement your own algorithm or you could just use getPathIterator()
with a uniform transform and then "rasterize" the path elements into your list.
Upvotes: 0
Reputation: 168815
Upvotes: 1