Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Draw Circle with GraphicsPath of which part is cut out

I'm trying draw something like following shapes with 3 parameters

  • radius
  • center
  • cutOutLen

the cut out part is bottom of the circle.

enter image description here

I figured out that I can use

var path = new GraphicsPath();
path.AddEllipse(new RectangleF(center.X - radius, center.Y - radius, radius*2, radius*2))
// ....
g.DrawPath(path);

but, how can I draw such thing?

BTW, What is the name of that shape? I could't search previous questions or something due to lack of terminology.

Thanks.

like image 882
Joonhwan Avatar asked Jul 18 '14 08:07

Joonhwan


1 Answers

Here you go, place this in some paint event:

// set up your values
float radius = 50;
PointF center = new Point( 60,60);
float cutOutLen = 20;

RectangleF circleRect = 
           new RectangleF(center.X - radius, center.Y - radius, radius * 2, radius * 2);

// the angle
float alpha = (float) (Math.Asin(1f * (radius - cutOutLen) / radius) / Math.PI * 180);

var path = new GraphicsPath();
path.AddArc(circleRect, 180 - alpha, 180 + 2 * alpha);
path.CloseFigure();

e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.FillPath(Brushes.Yellow, path);
e.Graphics.DrawPath(Pens.Red, path);

path.Dispose();

Here is the result:

cut circle.

I'm not sure about the term of a cut circle; in effect it is a Thales Cirlce.

like image 70
TaW Avatar answered Sep 21 '22 22:09

TaW