开发者

Ellipse thickness algorithm

Does anybody knows an algorithm for drawing an ellipse with thickness? I googled, but I found only algorithms that draws an 1 pixel width ellipse, like this: http://homepage.smc.edu/kennedy_john/belipse.pdf

开发者_如何学运维

Thanks.


By an ellipse with thickness do you mean the difference between two ellipses, one where the two axes have been lengthened by 1/2-thickness and the other where they have been shortened by 1/2-thickness?

If so, then you can adapt the linked algorithm into a scanline fill algorithm. One thing you want to do is work only along the shorter axis. (working along the longer axis works too, but involves redundant computation).

Let's say it's wider than it is tall. (If it's the other way around you just flip axes when drawing.) In that case you'll be drawing one or two horizontal line segments for each y position.

  • For each value of y from the top of the outer ellipse to the center of the ellipses:
    • If y is above inner ellipse:
      • Draw one horizontal line segment from the upper left quadrant point on the outer ellipse to the upper right quadrant point on the outer ellipse.
    • Else (y is not above inner ellipse):
      • Draw two horizontal line segments:
        • One from the upper left quadrant point of the outer ellipse to the upper left quadrant point of the inner ellipse.
        • Another from the upper right quadrant point of the inner ellipse to the upper right quadrant point of the outer ellipse.
    • Either way, mirror all drawing over the x-axis of the ellipses to render the bottom two quadrants.


how accurate do you need to be?

do you want the real ellipse point in the approximate center of the 'x' pixel width border? have the real elipse point be the inside edge? outside edge?

I ask b/c the gentleman's algorithm you found strives to stick with integer math where possible, so I'll append to his algorithm with integer work as well.

  • inside edge: alter the Plot4EllipsePoints sub routine to paint x pixels instead of one, where the new x pixels are further away from the ellipse center. 2 pixel eg:

    procedure Plot4EllipsePoints(X,Y : longint);

    begin
       PutPixel(CX+X, CY+Y);          {point in quadrant 1}
       PutPixel(CX+X+1, CY+Y+1);          {point in quadrant 1}
       PutPixel(CX-X, CY+Y);          {point in quadrant 2}
       PutPixel(CX-X-1, CY+Y+1);          {point in quadrant 2}
       PutPixel(CX-X, CY-Y);          {point in quadrant 3}
       PutPixel(CX-X-1, CY-Y-1);          {point in quadrant 3}
       PutPixel(CX+X, CY-Y)           {point in quadrant 4}
       PutPixel(CX+X+1, CY-Y-1)           {point in quadrant 4}
    end;
    

    taken from :http://homepage.smc.edu/kennedy_john/belipse.pdf

  • outside edge: same as inside edge, but closer to the ellipse center.
  • centered: perform the inside edge + outside edge both. This will only have odd thicknesses, 1 pix, 3 pix, 5 pix.


Let E1 be an ellipse of radius r + thickness / 2 and E2 an ellipse of radius r - thickness / 2.

Adapt the Scanline Fill Algorithm to fill E1 without filling E2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜