Explaining DrawArc method?

11,536

Solution 1

you imagine 2-D Coordinate axes and clockwise rotation ,
Start angle : shows the point where you want to start drawing from X axes
Sweep angle : measure of clockwise rotation ,

also MSDN Said:
startAngle: Angle in degrees measured clockwise from the x-axis to the starting point of the arc.

sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc.

for example : Horizantal Arc and Vertical Arc :

  switch (ArcType)
        {
            case ArcType.Horizantal :
                g.DrawArc(Pens.Black, 0, 15, 15, 15, 0, -180); 
                break; 
            case ArcType.Vertical:
                g.DrawArc(Pens.Black, 0, 15, 15,15, -90,180);                    
                break;
        } 

Solution 2

The coordinates are for drawing a complete ellipse from the top and left by width and height. Which part of the ellipse is actually drawn is determined by start and end angles. If the circle is a clock, then 3:00 is 0, 6:00 is 90, 9:00 is 180 and 12:00 is 270.

Share:
11,536
ykh
Author by

ykh

Updated on June 04, 2022

Comments

  • ykh
    ykh almost 2 years

    I have a task in which I have to draw a Figure of Eight, so I thought of it as drawing four arcs. I tried using the DrawArc method but I really don't understand how does it work at all.

    The DrawArc method takes 4 parameters: 1-The pen. 2-Rectangle to draw in. 3-Start angle. 4-Sweep angle.

    What I don't get is the start and sweep angle, could anybody with knowledge tell me what are these 2 parameters and how do they effect the drawing ?

    Also does giving the rectangle parameter takes the (0,0) as starting point.

    Edit:

    I have tried the following code:

            e.Graphics.DrawArc(drawPen, 0, 0, 600, 400, 45, 90);
            e.Graphics.DrawArc(drawPen, 0, 345, 600, 400, -45, -90);
    

    which resulted in the following:

    enter image description here

    I would like to make it larger, I have played with the code but not success, I didn't understand what I am doing, I was just changing numbers, that is why I asked for an explanation.

  • Ivan P.
    Ivan P. over 5 years
    You wrote: "sweepAngle: Angle in degrees measured clockwise from the startAngle parameter to ending point of the arc". So, it means that sweepAngle = desiredAbsolueEndAngle - startAngle. I think
  • quilkin
    quilkin over 2 years
    I was confused by this as well - then I realized that the start position (x,y) is the top left-hand corner of the bounding box of the complete ellipse. It's not the centre of the ellipse, as you would draw it on paper in Maths.