public AddPie ( float x, float y, float width, float height, float startAngle, float sweepAngle ) : void | ||
x | float | |
y | float | |
width | float | |
height | float | |
startAngle | float | |
sweepAngle | float | |
return | void |
public void AddPie(float x, float y, float width, float height, float startAngle, float sweepAngle)
{
float sin_alpha, cos_alpha;
float rx = width / 2;
float ry = height / 2;
/* center */
float cx = x + rx;
float cy = y + ry;
/* angles in radians */
float alpha = (float)(startAngle * Math.PI / 180);
/* adjust angle for ellipses */
alpha = (float) Math.Atan2 (rx * Math.Sin (alpha), ry * Math.Cos (alpha));
sin_alpha = (float)Math.Sin (alpha);
cos_alpha = (float)Math.Cos (alpha);
/* move to center */
Append (cx, cy, PathPointType.Start, false);
/* draw pie edge */
if (Math.Abs (sweepAngle) < 360)
Append (cx + rx * cos_alpha, cy + ry * sin_alpha, PathPointType.Line, false);
/* draw the arcs */
AppendArcs (x, y, width, height, startAngle, sweepAngle);
/* draw pie edge */
if (Math.Abs (sweepAngle) < 360)
Append (cx, cy, PathPointType.Line, false);
CloseFigure ();
}
public override GraphicsPath getGraphicsPathNoOffsetRoute() { GraphicsPath path = new GraphicsPath(); RectangleF rect = getRect(); try { path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, StartAngle, EndAngle); } catch (Exception ex) { rect.X = _X + _XAdd; rect.Y = _Y + _YAdd; rect.Width = 10; rect.Height = 10; path.AddPie(rect.X, rect.Y, rect.Width, rect.Height, StartAngle, EndAngle); ////ClsErrorFile.WriteLine("这里是一个扇形出现参数错误,异常处理是构造一个默认宽和高都是10,角度为0和90的扇形", ex); //throw; //throw; } return path; //return base.getGraphicsPath(); }