How to draw sector ( Quarter Circle) in windows phone dynamically?

c#, silverlight, windows-phone

Solution

With minimum changes to your code (`/**/` signifies changed or added lines).

PathFigure pthFigure1 = new PathFigure();
/**/ pthFigure1.StartPoint = new Point(0, 100);// starting cordinates of arcs
ArcSegment arcSeg1 = new ArcSegment();
/**/ arcSeg1.Point = new Point(100, 0);   // ending cordinates of arcs
/**/ arcSeg1.Size = new Size(100, 100);
arcSeg1.IsLargeArc = false;
arcSeg1.SweepDirection = SweepDirection.Clockwise;
/**/ LineSegment lineSeg = new LineSegment();
/**/ lineSeg.Point = new Point(100,100);
PathSegmentCollection myPathSegmentCollection1 = new PathSegmentCollection();
myPathSegmentCollection1.Add(arcSeg1);
/**/ myPathSegmentCollection1.Add(lineSeg);
pthFigure1.Segments = myPathSegmentCollection1;
PathFigureCollection pthFigureCollection1 = new PathFigureCollection();
pthFigureCollection1.Add(pthFigure1);
...

It seems that you missinterpret the meaning of `ArcSegment.RotationAngle`.

The math of it:

Problem

I want to draw the Shape as in the image. I have drawn half circle using Arc Segment, Now I want to draw Quarter circle, or A Sector, But I am unable to draw it. I used this code to draw Arc, I tried to change the size, and the angle is also not working. What should I do to draw Quarter circle / Sector ?? Code I used to draw Arc is : ``` PathFigure pthFigure1 = new PathFigure(); pthFigure1.StartPoint = new Point(50, 60);// starting cordinates of arcs ArcSegment arcSeg1 = new ArcSegment(); arcSeg1.Point = new Point(100, 82); // ending cordinates of arcs arcSeg1.Size = new Size(10, 10); arcSeg1.IsLargeArc = false; arcSeg1.SweepDirection = SweepDirection.Clockwise; arcSeg1.RotationAngle = 90; PathSegmentCollection myPathSegmentCollection1 = new PathSegmentCollection(); myPathSegmentCollection1.Add(arcSeg1); pthFigure1.Segments = myPathSegmentCollection1; PathFigureCollection pthFigureCollection1 = new PathFigureCollection(); pthFigureCollection1.Add(pthFigure1); PathGeometry pthGeometry1 = new PathGeometry(); pthGeometry1.Figures = pthFigureCollection1; System.Windows.Shapes.Path arcPath1 = new System.Windows.Shapes.Path(); arcPath1.Data = pthGeometry1; arcPath1.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 23, 0)); this.LayoutRoot.Children.Add(arcPath1); ```

Original source