gpt4 book ai didi

c# - GraphicsPath.AddArc 如何使用 startAngle 和 sweepAngle 参数?

转载 作者:太空狗 更新时间:2023-10-29 23:04:40 24 4
gpt4 key购买 nike

我正在尝试使用 System.Drawing.Drawing2D.GraphicsPath.AddArc 绘制从 0 度开始并扫描到 135 度的椭圆弧。

我遇到的问题是,对于椭圆,绘制的圆弧与我的预期不符。

例如,下面的代码生成下图。绿色圆圈是我希望圆弧的终点使用椭圆上的点的公式的地方。我的公式适用于圆但不适用于椭圆。

这与极坐标与笛卡尔坐标有关吗?

    private PointF GetPointOnEllipse(RectangleF bounds, float angleInDegrees)
{
float a = bounds.Width / 2.0F;
float b = bounds.Height / 2.0F;

float angleInRadians = (float)(Math.PI * angleInDegrees / 180.0F);

float x = (float)(( bounds.X + a ) + a * Math.Cos(angleInRadians));
float y = (float)(( bounds.Y + b ) + b * Math.Sin(angleInRadians));

return new PointF(x, y);
}

private void Form1_Paint(object sender, PaintEventArgs e)
{
Rectangle circleBounds = new Rectangle(250, 100, 500, 500);
e.Graphics.DrawRectangle(Pens.Red, circleBounds);

System.Drawing.Drawing2D.GraphicsPath circularPath = new System.Drawing.Drawing2D.GraphicsPath();
circularPath.AddArc(circleBounds, 0.0F, 135.0F);
e.Graphics.DrawPath(Pens.Red, circularPath);

PointF circlePoint = GetPointOnEllipse(circleBounds, 135.0F);
e.Graphics.DrawEllipse(Pens.Green, new RectangleF(circlePoint.X - 5, circlePoint.Y - 5, 10, 10));

Rectangle ellipseBounds = new Rectangle(50, 100, 900, 500);
e.Graphics.DrawRectangle(Pens.Blue, ellipseBounds);

System.Drawing.Drawing2D.GraphicsPath ellipticalPath = new System.Drawing.Drawing2D.GraphicsPath();
ellipticalPath.AddArc(ellipseBounds, 0.0F, 135.0F);
e.Graphics.DrawPath(Pens.Blue, ellipticalPath);

PointF ellipsePoint = GetPointOnEllipse(ellipseBounds, 135.0F);
e.Graphics.DrawEllipse(Pens.Green, new RectangleF(ellipsePoint.X - 5, ellipsePoint.Y - 5, 10, 10));
}

alt text

最佳答案

enter image description here我对 GraphicsPath.AddArc 的工作原理感到困惑,我找不到任何像样的图表,所以我画了一个。以防其他人遭受同样的痛苦! http://imgur.com/lNBewKZ

关于c# - GraphicsPath.AddArc 如何使用 startAngle 和 sweepAngle 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1309071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com