How to draw a full ellipse in a StreamGeometry in WPF?

Posted by romkyns on Stack Overflow See other posts from Stack Overflow or by romkyns
Published on 2010-06-05T09:41:11Z Indexed on 2010/06/05 9:42 UTC
Read the original article Hit count: 398

Filed under:

The only method in a StreamGeometryContext that seems related to ellipses is the ArcTo method. Unfortunately it is heavily geared to joining lines rather than drawing ellipses.

In particular, the position of the arc is determined by a starting and ending point. For a full ellipse the two coincide obviously, and the exact orientation becomes undefined.

So far the best way of drawing an ellipse centered on 100,100 of size 10,10 that I found is like this:

using (var ctx = geometry.Open())
{
    ctx.BeginFigure(new Point(100+5, 100), isFilled: true, isClosed: true);
    ctx.ArcTo(
        new Point(100 + 5*Math.Cos(0.01), 100 + 5*Math.Sin(0.01)), // need a small angle but large enough that the ellipse is positioned accurately
        new Size(10/2, 10/2), // docs say it should be 10,10 but in practice it appears that this should be half the desired width/height...
        0, true, SweepDirection.Counterclockwise, true, true);
}

Which is pretty ugly, and also leaves a small "flat" area (although not visible at normal zoom levels).

How else might I draw a full ellipse using StreamGeometryContext?

© Stack Overflow or respective owner

Related posts about wpf