0

I've stumbled upon converting Ellipse to PathGeometry. I've tried to use ArcSegment to present Ellipse, but still don't know how to convert Ellipse size to ArcSegment size. I'm trying to segment Ellipse into two part, but there are other approaches, i.e. Bezier curves. Need clues how to convert Ellipse to ArcSegment collection. The whole process could be looking like that:

public static PathFigure ToFigures(this Ellipse ellipse)
{
    var pathFigure = new PathFigure {IsClosed = true};
    var arcSegment1 = new ArcSegment();
    var arcSegment2 = new ArcSegment();
    pathFigure.Segments.Add(arcSegment1);
    pathFigure.Segments.Add(arcSegment2);
    return pathFigure;
}
Dmitry Dyachkov
  • 1,715
  • 2
  • 19
  • 46
  • Are you just trying to have an ellipse segmented as two parts in arc segments? Or are arc segments even required and you could just do an EllipseGeometry or just a Path as an ellipse?? – Chris W. Oct 06 '15 at 13:01
  • Ellipse segmented into two parts will be fine. As source objects I have Ellipse or EllipseGeometry as a choice. For output, the PathGeometry or PathFigure is required. – Dmitry Dyachkov Oct 06 '15 at 13:06
  • So, one really simple way to do this if you don't want to/cant freehand your geometry. Open Blend, drop an ellipse on the artboard to your liking, then Right-Click -> Path -> Convert to Path. Except I'm still not exactly sure what you're trying to do since you mention a source and output. It sounds more like you're looking for a converter. – Chris W. Oct 06 '15 at 13:26
  • I need to create PathGeometry or PathFigure in the code, not in editor. – Dmitry Dyachkov Oct 06 '15 at 13:34
  • Dude your question is a little confusing. The first sentence you want to convert Ellipse to PathGeometry. Second sentence you say you're presenting ArcSegment as Ellipse. Then second to last sentence you want to convert Ellipse to ArcSegment Collection. What is it exactly you're trying to do? Are you looking for someone to give you a converter that converts Ellipse to Path, or Ellipse to ArcSegment Collection, or ArcSegment to Path. You might want to re-word. – Chris W. Oct 06 '15 at 13:40
  • These are the same egg views from different sides. Clues are in the code. PathGeomerty consists of PathFigures with segments inside. Using ArcSegment is the simple way. ArcSegments I want to add to PathFigure. I don't need to convert ArcSegment to Path, it's evident how to do it. Long story short, I need to present ellipse as two ArcSegment – Dmitry Dyachkov Oct 06 '15 at 13:53
  • Yea, for all I know you pasted something that looked similar to what you want hoping someone would do your work...happens all the time on SO. You're correct in your segments, now you'll just need to set your points and size, which since it's "evident how to do it", guess you don't need much help right? :D – Chris W. Oct 06 '15 at 14:02
  • Path path = new Path(){Data = PathGeometry}; – Dmitry Dyachkov Oct 06 '15 at 14:05
  • I don't understand how to get ArcSegment size from Ellipse size – Dmitry Dyachkov Oct 06 '15 at 14:05

1 Answers1

2

You could directly use an EllipseGeometry for the Path Data:

path = new Path
{
    Data = new EllipseGeometry { RadiusX = 100, RadiusY = 50 }
};

Using the size of the Ellipse it would look like this:

path = new Path
{
    Data = new EllipseGeometry
    {
        RadiusX = ellipse.ActualWidth / 2,
        RadiusY = ellipse.ActualHeight / 2
    }
};
Clemens
  • 123,504
  • 12
  • 155
  • 268