Search code examples
c#pixelgeometry

defining a circle on x-y axis


I have such a grid square disk. Every grid represents a pixel. My aim is to most accurately aprroximate this disk as a circle (max from inside). Radius of the circle should be 1 so I have to define a x-y plane whose minimum and maximum values -1, +1 respectively. So pixel 35 is the origin (0,0). By the way I don't want to draw a circle, I just need such a circle which gives me the coordinates of every single pixel.

For example: for pixel 3, it should give me a coordinate approximately (0 , 0.8). I can define such a circle, but I am not sure about coordinates. I don't ask any code but some tips or advices would be appreciated. I am also using emgucv library for this project. Should I define this coordinates from scratch or is there any pre-defined class or something that speed me up.

thanks

enter image description here


Solution

  • To calculate the distances of the pixels from the origin relative to the circle's radius, you only need the radius. To get that you can go through the (quarter of) the perimiter of your "disk" and caclulate the min/max distances (as appropriate to your needs). The result is the radius of the circle

    To get the pixels' relative distance, calculate the pixel's distance to the origin and divide it by the above measured radius