Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 828609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:45:03+00:00 2026-05-15T03:45:03+00:00

The only method in a StreamGeometryContext that seems related to ellipses is the ArcTo

  • 0

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?

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:45:04+00:00Added an answer on May 15, 2026 at 3:45 am

    As you noted, ArcTo cannot draw a complete ellipse. In fact it becomes numerically unstable as you attempt to reduce the “flat” area. Another consideration is that arc drawing is slower than Bezier drawing on modern hardware. This most modern systems use four bezier curves to approximate an ellipse rather than drawing a true ellipse.

    You can see that WPF’s EllipseGeometry does this by executing the following code, breaking on the DrawBezierFigure method call, and examining the PathFigure in the debugger:

    using(var ctx = geometry.Open())
    {
      var ellipse = new EllipseGeometry(new Point(100,100), 10, 10);
      var figure = PathGeometry.CreateFromGeometry(ellipse).Figures[0];
      DrawBezierFigure(ctx, figure);
    }
    
    void DrawBezierFigure(StreamGeometryContext ctx, PathFigure figure)
    {
      ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed);
      foreach(var segment in figure.Segments.OfType<BezierSegment>())
        ctx.BezierTo(segment.Point1, segment.Point2, segment.Point3, segment.IsStroked, segment.IsSmoothJoin);
    }
    

    The above code is a simple way to draw an efficient ellipse into a StreamGeometry, but is very special-case code. In actual practice I use several general-purpose extension methods defined for drawing an arbitrary Geometry into a StreamGeometryContext so I can simply write:

    using(var ctx = geometry.Open())
    {
      ctx.DrawGeometry(new EllipseGeometry(new Point(100,100), 10, 10));
    }
    

    Here is the implementation of the DrawGeometry extension method:

    public static class GeometryExtensions
    {
      public static void DrawGeometry(this StreamGeometryContext ctx, Geometry geo)
      {
        var pathGeometry = geo as PathGeometry ?? PathGeometry.CreateFromGeometry(geo);
        foreach(var figure in pathGeometry.Figures)
          ctx.DrawFigure(figure);
      }
    
      public static void DrawFigure(this StreamGeometryContext ctx, PathFigure figure)
      {
        ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed);
        foreach(var segment in figure.Segments)
        {
          var lineSegment = segment as LineSegment;
          if(lineSegment!=null) { ctx.LineTo(lineSegment.Point, lineSegment.IsStroked, lineSegment.IsSmoothJoin); continue; }
    
          var bezierSegment = segment as BezierSegment;
          if(bezierSegment!=null) { ctx.BezierTo(bezierSegment.Point1, bezierSegment.Point2, bezierSegment.Point3, bezierSegment.IsStroked, bezierSegment.IsSmoothJoin); continue; }
    
          var quadraticSegment = segment as QuadraticBezierSegment;
          if(quadraticSegment!=null) { ctx.QuadraticBezierTo(quadraticSegment.Point1, quadraticSegment.Point2, quadraticSegment.IsStroked, quadraticSegment.IsSmoothJoin); continue; }
    
          var polyLineSegment = segment as PolyLineSegment;
          if(polyLineSegment!=null) { ctx.PolyLineTo(polyLineSegment.Points, polyLineSegment.IsStroked, polyLineSegment.IsSmoothJoin); continue; }
    
          var polyBezierSegment = segment as PolyBezierSegment;
          if(polyBezierSegment!=null) { ctx.PolyBezierTo(polyBezierSegment.Points, polyBezierSegment.IsStroked, polyBezierSegment.IsSmoothJoin); continue; }
    
          var polyQuadraticSegment = segment as PolyQuadraticBezierSegment;
          if(polyQuadraticSegment!=null) { ctx.PolyQuadraticBezierTo(polyQuadraticSegment.Points, polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin); continue; }
    
          var arcSegment = segment as ArcSegment;
          if(arcSegment!=null) { ctx.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, arcSegment.IsStroked, arcSegment.IsSmoothJoin); continue; }
        }
      }
    }
    

    Another alternative is to compute the points yourself. The best approximation to an ellipse is found by setting the control points to (Math.Sqrt(2)-1)*4/3 of the radius. So you can explicitly compute the points and draw the Bezier as follows:

    const double ControlPointRatio = (Math.Sqrt(2)-1)*4/3;
    
    var x0 = centerX - radiusX;
    var x1 = centerX - radiusX * ControlPointRatio;
    var x2 = centerX;
    var x3 = centerX + radiusX * ControlPointRatio;
    var x4 = centerX + radiusX;
    
    var y0 = centerY - radiusY;
    var y1 = centerY - radiusY * ControlPointRatio;
    var y2 = centerY;
    var y3 = centerY + radiusY * ControlPointRatio;
    var y4 = centerY + radiusY;
    
    ctx.BeginFigure(new Point(x2,y0), true, true);
    ctx.BezierTo(new Point(x3, y0), new Point(x4, y1), new Point(x4,y2), true, true);
    ctx.BezierTo(new Point(x4, y3), new Point(x3, y4), new Point(x2,y4), true, true);
    ctx.BezierTo(new Point(x1, y4), new Point(x0, y3), new Point(x0,y2), true, true);
    ctx.BezierTo(new Point(x0, y1), new Point(x1, y0), new Point(x2,y0), true, true);
    

    Another option would be to use two ArcTo calls, but as I mentioned before this is less efficient. I’m sure you can figure out the details of the two ArcTo calls if you want to go that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The only reliable method that I a have found for using a script to
I understand that .NET FileStream's Flush method only writes the current buffer to disk,
I only want a method to activate if the pixel that is clicked is
Is Apple declaring method [CIImage initWithImage:(CIImage*)] that I'm not aware of? The only method
Is try-catch the only method to do that?
The only method provided by the DNN framework to get a module by ID
In my specific case: A WCF connection is established, but the only method with
Question Is there a way to define a method only once in C# (in
If I want to provide OpenID as the only registration method available AND want
Why does only the third method work? $('#jqtest').live('load', function() {$(this).html('hi');}); //1 $('#jqtest').load(function() {$(this).html('hi');}); //2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.