关于图形路径的问题? [英] Question about Graphics Pathing?

查看:65
本文介绍了关于图形路径的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





嗨Code工程,



我一直在使用图形路径它是一个非常有用的课程,但是我遇到了一个问题。



我使用随机生成的cooardinates使用另一个图形部分绘制几个矩形。在这些矩形之间(想象一个9乘9场,位置(3,3)在其间)我想绘制另一个矩形或三角形,这取决于环境而不影响其他矩形。



矩形与变形矩形完全分开,但可以通过我制作的点列表获得。





Hey Codeproject,

I have been using the Graphics Path it's a really helpful class, however I am facing a problem.

I am drawing several rectangles using another graphics part using cooardinates that are randomly generated. Inbetween those rectangles(Imagine a 9 by 9 field, and the position(3,3) being inbetween) I want to draw another rectangle, or a triangle, depending on the environment without affecting the other rectangles.

The rectangles are completely seperated from the "morphing" rectangle, but can be aquired by the list of points I've made.

List<Point> Rectangles = new List<Point>();
int RectangleSize = 32;
for(int i =0; i<3; i++)
{
 for(int j =0; j<3; j++)
  {
    Rectangles.Add(i * RectangleSize, j * RectangleSize); 
    Rectangles.Add(i * RectangleSize + RectangleSize, j * RectangleSize); 
    Rectangles.Add(i * RectangleSize + RectangleSize, j * RectangleSize + RectangleSize); 
    Rectangles.Add(i * RectangleSize, j * RectangleSize + RectangleSize); 
  }
}





我要做的是找出相邻的矩形,并创建一个多边形连接到相邻的矩形。我到目前为止只设法使用三角形,并手动添加它们,到目前为止还没有提出任何类型的算法来确定点。



这是一个我正在寻找的方法的样本,在图片中你可以看到Hitpoints我需要能够递归地在它们之间制作点,以使线条变得更加曲线:



What I am attempting to do is find out the neighbouring rectangles, and create a polygon to connect to neighbouring rectangles. I've only so far managed to use triangles, and add them manually and have so far not come up with any type of algorithm to determine the points.

Here's a sample of the method I am looking for, also in the picture you can see "Hitpoints" I need to be able to recursively make points inbetween those to smoothen the lines to something more curvy:

public void Polygonize(List<Point> Neighbours, int Range)
{
 List<Point> Polygon = new List<Point>();

  // Create a polygon in the middle of all the points, by adding points closest to the middle, and not any further than the range(Which would be the rectangle size

 Neighbours = Polygon;
}





图片中的列表如下所示:



The list as from the picture would look like this:

{
new Point(0, 0),
new Point(32, 32),
new Point(0, 32)
};





哪个会产生三角形。我希望能够添加更多积分(递归) ,使它更加曲线。



这是图片:

链接



这可能吗?



Which would result as a triangle. I'm hoping to be able to add more points(recursively), to make it more curvy.

Here's the picture:
Link

Is this possible?

推荐答案



GraphicsPath只是一个行和曲线的集合,可以通过GraphicsPath而不是单独访问。


A GraphicsPath is merely a collection of lines and curves that can be accessed through the GraphicsPath rather than individually.



以下代码是Paint事件的事件处理程序。可以将此处理程序放入任何WinForm表单应用程序中。当事件被引发时,处理程序执行两个主要操作。


The following code is the event handler for the Paint event. This handler can be dropped into any WinForm Form application. When the event is raised, the handler performs two major actions.



  1. 矩形是宣布,绘制和填充;声明,绘制和填充三角形。绘图和填充本身就是形状。

  2. 声明了GraphicsPath;声明一个矩形并将其添加到GraphicsPath;声明一个三角形并将其添加到GraphicsPath中(矩形和三角形都向下偏移150个像素);绘制并填充GraphicsPath。




// *************************************************** OnPaint

protected override void OnPaint ( PaintEventArgs e )
    {
    GraphicsPath    graphics_path;
    Rectangle       rectangle;
    Point [ ]       triangle = new Point [ 4 ];

    base.OnPaint ( e );

    this.Width = 200;
    this.Height = 300;

    rectangle = new Rectangle ( 10, 10, 100, 100 );
    e.Graphics.DrawRectangle ( Pens.Red, rectangle );
    e.Graphics.FillRectangle ( Brushes.Red, rectangle );

    triangle [ 0 ] = new Point ( 120,  60 );
    triangle [ 1 ] = new Point ( 180,  10 );
    triangle [ 2 ] = new Point ( 180, 110 );
    triangle [ 3 ] = new Point ( 120,  60 );
    e.Graphics.DrawLines ( Pens.Red,triangle );
    e.Graphics.FillPolygon ( Brushes.Red, triangle );

    graphics_path = new GraphicsPath ( );
                                // offset eveything down 150
    rectangle = new Rectangle ( 10, 160, 100, 100 );
    graphics_path.AddRectangle ( rectangle );

    triangle [ 0 ] = new Point ( 120, 210 );
    triangle [ 1 ] = new Point ( 180, 160 );
    triangle [ 2 ] = new Point ( 180, 260 );
    triangle [ 3 ] = new Point ( 120, 210 );
    graphics_path.AddLines ( triangle );

    e.Graphics.DrawPath ( Pens.Blue, graphics_path );
    e.Graphics.FillPath ( Brushes.Blue, graphics_path );

    graphics_path.Dispose ( );
    }



GraphicsPaths比Regions更容易使用。完成后请记得处理GraphicsPath。


GraphicsPaths are somewhat easier to use than Regions. Remember to Dispose of the GraphicsPath when done with it.



希望有所帮助。


Hope that helps.


这篇关于关于图形路径的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆