Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw an ellipse with arbitrary orientation pixel by pixel?

I have to draw an ellipse of arbitrary size and orientation pixel by pixel. It seems pretty easy to draw an ellipse whose major and minor axes align with the x and y axes, but rotating the ellipse by an arbitrary angle seems trickier. Initially I though it might work to draw the unrotated ellipse and apply a rotation matrix to each point, but it seems as though that could cause errors do to rounding, and I need rather high precision.

Is my suspicion about this method correct? How could I accomplish this task more precisely?

I'm programming in C++ (although that shouldn't really matter since this is a more algorithm-oriented question).

Edit: as David pointed out, I guess I may really be wondering how to do pixel interpolation.

like image 269
amc Avatar asked Jun 11 '10 19:06

amc


2 Answers

Use the Bresenham method of drawing axis-aligned ellipses, but apply a shear to the drawn ellipse. You will also need to modify the lengths of the axes. A sheared ellipse is also an ellipse. This method preserves the Bresenham advantage of drawing filled ellipses using horizontal line segments. What you need in order to do this is the function which maps a specification of an ellipse in terms of axes and rotation into a different set of axes and a shear. A solution is available online at http://scratch.mit.edu/projects/50039326/ with a discussion about the method and a description of the math involved at http://scratch.mit.edu/discuss/topic/94194/

The mapping was discovered by Nathan Dinsmore (user nXIII at the MIT Scratch site)

like image 115
Graham Toal Avatar answered Sep 27 '22 18:09

Graham Toal


Bresenham (famous for his line drawing algorithm) also has an algorithm for drawing an ellipse. You can try to google bresenham ellipse.

like image 30
Martin Liversage Avatar answered Sep 27 '22 16:09

Martin Liversage