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

后端 未结 3 1415
失恋的感觉
失恋的感觉 2021-02-14 09:13

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

相关标签:
3条回答
  • 2021-02-14 09:42

    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)

    0 讨论(0)
  • 2021-02-14 09:47

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

    0 讨论(0)
  • 2021-02-14 09:48

    Use:

    x = X cos(a) - Y sin(a)
    y = Y cos(a) + X sin(a)
    

    Where a is the angle of anticlockwise rotation, (x, y) are the new coordinates, and (X, Y) are the old.

    You should use floats to preserve precision. Just go through every point, apply the transformation, and voilà.

    Edit: after some searching, here's some code from Microsoft: http://research.microsoft.com/en-us/um/people/awf/graphics/bres-ellipse.html that draws rastered conic sections.

    0 讨论(0)
提交回复
热议问题