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

后端 未结 3 1402
失恋的感觉
失恋的感觉 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: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.

提交回复
热议问题