如何获取椭圆内像素的坐标? (截屏) [英] How to get the coordinates of the pixels inside an ellipse? (screenshot)
问题描述
我需要获取椭圆的特定区域内所有像素的坐标.
I need to get the coordinates of all the pixels inside this particular region of an ellipse.
我知道网格的大小,椭圆的中心,vertical_radix和horizontal_radix.
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.
因此,在下一个示例中,网格为26 x 26. 椭圆的中心为(13,7),vertical_radix为7,horizontal_radix = 13.
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.
知道这一点后,我需要所有灰色像素的坐标(x和y对).
Knowing this I need the coordinates (pair of x and y) of all the grey pixels.
我只需要一个知道这6个参数(grid_width,grid_height,x_center,y_center,vertical_radix,horizontal_radix)的函数即可获取我的坐标. (任何标记的语言)
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)
谢谢.
推荐答案
将点距中心的x和y偏移量缩放为一个单位圆,然后检查距中心的距离.
Scale the x and y offsets of the dots from the center into a unit circle, then check the distance from the center.
假设(x,y)的中心,(x 1 ,y 1 )的点以及轴为(a,b)的椭圆:
Assuming a center of (x, y), a point at (x1, y1), and an ellipse with axes of (a, b):
定标点为(2(x 1 -x)/a,2(y 1 -y)/b).从(0,0)看这是大于还是小于1,即将每个分量平方并与1进行比较.
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.
这篇关于如何获取椭圆内像素的坐标? (截屏)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!