Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# GraphicsPath.AddArc()连接到错误的弧侧_C#_Winforms_System.drawing - Fatal编程技术网

C# GraphicsPath.AddArc()连接到错误的弧侧

C# GraphicsPath.AddArc()连接到错误的弧侧,c#,winforms,system.drawing,C#,Winforms,System.drawing,我有一个道路布局(在WinForms中派生的面板,道路存储为图像,并在创建时设置为面板的背景图像),我想让汽车沿着道路行驶。为了实现这一点,我希望使用GraphicsPath,然后沿着GraphicsPath移动图像。不幸的是,我无法正确生成GraphicsPath。我可以通过选取两点和所需角度来创建我想要的圆弧,如下所示: private void CreateArc( GraphicsPath path ) { Point source = new Point( road.Locatio

我有一个道路布局(在WinForms中派生的
面板
,道路存储为图像,并在创建时设置为
面板
背景图像
),我想让汽车沿着道路行驶。为了实现这一点,我希望使用
GraphicsPath
,然后沿着
GraphicsPath
移动图像。不幸的是,我无法正确生成
GraphicsPath
。我可以通过选取两点和所需角度来创建我想要的圆弧,如下所示:

private void CreateArc( GraphicsPath path )
{
  Point source = new Point( road.Location.X + SmallVerticalOffset, road.Location.Y );
  Point destination = new Point( road.Location.X + TileLength, road.Location.Y + LargeHorizontalOffset );
  Rectangle boundingBox = CreateRectangle( source, destination );
  int startingAngle = -270; //Same result with 90 for both angles
  int sweepingAngle = 0;

  path.AddArc( boundingBox, startingAngle, sweepingAngle );
}

private Rectangle CreateRectangle( Point source, Point destination )
{
  return new Rectangle( Math.Min( source.X, destination.X ),
    Math.Min( source.Y, destination.Y ),
    Math.Abs( source.X - destination.X ),
    Math.Abs( source.Y - destination.Y ) );
}
在其他地方添加直线后,这就是结果

相反,我希望这条线是连续的,通过连接到弧的顶部,并在弧后继续。这也是我所期待的,但唉。我想使用
WinForms
解决这个问题,如果可能的话,不需要任何额外的库

编辑
我花了比我想承认的时间长得多的时间,但我终于明白了。如果有其他人在为此挣扎,也许这个简短的解释会对你有所帮助


上一个
GraphicsPath
段连接到蓝色箭头处的圆弧,指向x轴和右侧圆的交点。要创建一条连续线,您需要以这样的方式拾取角度,即起点沿圆移动到希望圆弧开始的点。假设您想要圆的左半边,从顶部开始,到底部结束。在这种情况下,您的
启动角度将为270,因为角度是从x轴逆时针计算的。扫掠角度的情况正好相反,我们现在从起始角度指定的点开始,而不是从x轴开始。因为我们想要圆的左半边,我们的
扫掠角将是-180,因为我们从用
起始角计算的点开始向后移动。为了得到这个圆的左半边,我们将这样写
path.AddArc(boundingbox,270,-180)

我将把图形放入一个面板(位于win表单上),因此原点是面板的左上角。我不完全确定你的意思。这已经在位于表单上的
面板上。您需要在不同方向上绘制圆弧,这取决于您在圆弧周围移动的方向。从
0
扫掠到
90
与从
90
扫掠到
0
不同。我目前使用-270作为起始角度,0作为扫掠角度。与此相反的方向是什么?因为简单地交换它们并不能得到相同的弧度,两个角度都使用90可以得到相同的结果。你确定你要从
-270
扫出
0
度吗?那根本不应该扫过。
path.AddArc(rect,0,90)
的反面应该是
path.AddArc(rect,90,-90)