How to get the coordinates of the pixels inside an ellipse? (screenshot)

陌路散爱 提交于 2019-12-23 02:34:33

问题


I need to get the coordinates of all the pixels inside this particular region of an ellipse.

I know the size of the grid, the center of the elipse and the vertical_radix and horizontal_radix.

I searched on the math forums but couldn't find anything useful.

So for the next example the grid is 26 by 26. Center of the ellipse is at (13, 7) and vertical_radix is 7 and horizontal_radix = 13.

Knowing this I need the coordinates (pair of x and y) of all the grey pixels.

I just need like a function that knowing this 6 params (grid_width, grid_height, x_center, y_center, vertical_radix, horizontal_radix) could get my coordinates. (any of the tagged languages)

Thanks.


回答1:


Scale the x and y offsets of the dots from the center into a unit circle, then check the distance from the center.

EDIT:

Assuming a center of (x, y), a point at (x1, y1), and an ellipse with axes of (a, b):

The scaled point is (2(x1-x)/a, 2(y1-y)/b). See if this is more or less than 1 from (0, 0), i.e. square each component and compare the sum with 1.



来源:https://stackoverflow.com/questions/9933114/how-to-get-the-coordinates-of-the-pixels-inside-an-ellipse-screenshot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!