views:

156

answers:

1

Hey folks,

I have been looking all over the Web for a way to plot an ellipse from rectangle coordinates, that is, top-left corner (x, y) and size (width and height). The only ones I can find everywhere are based on the Midpoint/Bresenham algorithm and I can't use that because when working with integer pixels, I lose precisions because these algorithms use a center point and radials.

The ellipse MUST be limited to the rectangle's coordinates, so if I feed it a rectangle where the width and height are 4 (or any even number), I should get an ellipse that completely fits in a 4x4 rectangle, and not one that will be 5x5 (like what those algorithms are giving me).

Does anyone know of any way to accomplish this?

Thanks!

+4  A: 

Can you not get the width and height (divided by 2) and center of the rectangle then plug that into any ellipse drawing routine as its major, minor axis and center? I guess I'm not seeing the problem all the way here.

Michael Dorgan
No, I can't, because for even width and height the resulting ellipse's width and height will be incremented by one pixel from the original, seeing as it plots the pixel at center + axis and center - axis. I need it to be perfectly within the bounds, my "pixels" are 32x32 so this is very visible.
Xeon06
So the problem is sub pixel accuracy and reflecting about the quadrants is causing an overwrite on some edges. Given that, you should be able to store a non-integer width height (or at least a fixed point value with 1 bit for fraction) to handle this. Then the problem is finding or writing an ellipse generator that works with non integer widths and heights. That shouldn't be too difficult to find, but I haven't looked so perhaps not?
Michael Dorgan