java中drawArc参数的含义,为什么DrawArc / DrawPie角点与实际弧点的角度相同?

当我使用C#DrawArc / DrawEllipse或DrawPie GDI函数绘制椭圆或圆弧时,我相信它绘制的是我给出的精确角度 . 但是,当我通过编写一个小程序对它进行测试时,我发现DrawArc中的225度扫描角度实际上不是225度 . 我的测试程序每秒绘制一条从0度到360度的线(如时钟秒针)并且使用DrawArc函数并行绘制弧线以获得相同的角度 .

下面的函数用于获得给定起点/终点和角度的角度点 . 有人可以解释为什么这种差异?我试图通过DrawArc()找到绘制弧的终点 . 我可以用不同的方式实现它 . 但是,我不明白为什么DrawArc函数以这种方式工作? DrawArc可以使用0,90,180,270,360个角度 .

public static Point PointOnEllipseFromAngle(Point center, int radiusX, int radiusY, int angle)

{

double x = center.X + radiusX * Math.Cos(angle * (Math.PI / 180.0));

double y = center.Y + radiusY * Math.Sin(angle * (Math.PI / 180.0));

return new Point((int)x, (int)y);

}

Form Paint就是这样的

private void Form1_Paint(object sender, PaintEventArgs e)

{

Rectangle rect = Bounds;

rect.Inflate(-50, -50);

// Mid point

Point mid = new Point(rect.Left+(rect.Width / 2), rect.Top+(rect.Height / 2));

// Arc point for the given angle (angle is incremented in timer every second)

Point p1 = PointOnEllipseFromAngle(new Point(rect.Left+(rect.Width / 2), rect.Top+(rect.Height / 2)), rect.Width / 2, rect.Height / 2, angle);

// Line between mid and arc point

e.Graphics.DrawLine(new Pen(Color.Blue, 2), mid, p1);

e.Graphics.DrawString(angle.ToString(), new Font("Arial", 18), new SolidBrush(Color.Red), p1);

e.Graphics.FillEllipse(new SolidBrush(Color.Red), new Rectangle(p1.X - 5, p1.Y - 5, 10, 10)); // red circle at edge of the line

// DrawArc for the same angle

e.Graphics.DrawArc(new Pen(Color.Green,2), rect, 0, angle);

// Just Drawing axis lines (horizontal, vertical, diagonal)

e.Graphics.DrawLine(new Pen(Color.Black, 2), mid, new Point(rect.Left+rect.Width,rect.Top+(rect.Height/2)));

e.Graphics.DrawLine(new Pen(Color.Black, 2), mid, new Point(rect.Left, rect.Top + (rect.Height / 2)));

e.Graphics.DrawLine(new Pen(Color.Black, 2), mid, new Point(rect.Left + (rect.Width/2), rect.Top + rect.Height));

e.Graphics.DrawLine(new Pen(Color.Black, 2), mid, new Point(rect.Left + (rect.Width / 2), rect.Top));

e.Graphics.DrawLine(new Pen(Color.Black, 2), rect.Left,rect.Top,rect.Right,rect.Bottom);

e.Graphics.DrawLine(new Pen(Color.Black, 2), rect.Left, rect.Bottom, rect.Right, rect.Top);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值