简体   繁体   中英

c# draw an arc in a rectangle

Spiral:

在此处输入图片说明

I have coded squares in C# based on the Fibonacci series exactly as shown in the included image. The problem I am having is trying to draw the arcs. I am not sure if I should be using arcs, curves or bezier curves. I assume an arc is what I want, but I have been unable to get the results I am trying for.

If someone could show me an example of how to draw an arc from corner to corner within a square it would be very much appreciated. I just hard coded the squares for fun. I want to try to write an algorithm to generate them, but right now I am stumped by the behavior of the arcs.

Bitmap bmp = new Bitmap(50, 50);
using (Graphics g = Graphics.FromImage(bmp))
{
    g.DrawArc(Pens.Black, new Rectangle(0, 0, 100, 100), 0, 90);
}

Parameters

  • Stroke color
  • Bounding box for the circle the arc would be part of
  • Starting angle (in degrees)
  • Ending angle (in degrees)

The arc is drawn clockwise from the starting arc. To do a counterclockwise arc, supply a negative value for the ending angle.

Bitmap bmp = new Bitmap(50, 50);
using (Graphics g = Graphics.FromImage(bmp))
{
    g.DrawArc(Pens.Black, new Rectangle(0, 0, 100, 100), 0, 90);
}

It seems the bounding box must be twice the size of the square in order for the arc to go from corner to corner.

Curve

The "rectangle" is a square. The center of the arc is a corner, the radius is a side, the starting angle is a multiple of 90° and the sweep angle is 90°. No rocket science.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM