简体   繁体   English

如何使用 x 和 y 坐标数组绘制矩形轮廓?

[英]How to draw rectangular profiles using x and y coordinate array?

To handle collision prevention, for example, I set the program to issue a warning when near to obstacles.例如,为了防止碰撞,我将程序设置为在靠近障碍物时发出警告。 The x and y coordinates of obstacles are put into array.障碍物的 x 和 y 坐标被放入数组中。

Now I would like to draw a smooth profile that is like blocks of rectangles.现在我想绘制一个平滑的轮廓,就像矩形块一样。 However, I get slanted lines whenever there is change in y-coordinate.但是,每当 y 坐标发生变化时,我都会得到倾斜的线条。

A small part of the code I used are as followed, assuming the coordinates of x and y arrays should give rectangular shaped profile with rises and falls as x changes, maybe like building a castle with some variation in height y.我使用的一小部分代码如下,假设 x 和 y 数组的坐标应该给出矩形轮廓,随着 x 的变化而上升和下降,也许就像建造一座高度 y 有一些变化的城堡。

for (int i = 0; i < Copy_length; i++)
        {
            chart1.Series["Series1"].Points.AddXY(X[i],Y[i]);

        }
        chart1.Series["Series1"].Color = Color.FromArgb(100, Color.Olive);

        chart1.Series["Series1"].Points.DataBindXY(X, Y1, Y2);

Other suggestions for handling of collision prevention are welcome too.也欢迎其他有关处理碰撞预防的建议。

You could add some data points to create the steps you seem to want:您可以添加一些数据点来创建您想要的步骤:

在此处输入图片说明在此处输入图片说明

void makeSteps(Series S)
{
    List<DataPoint> points = S.Points.ToList();
    S.Points.Clear();
    for(int i = 0; i < points.Count - 1; i++)
    {
        S.Points.Add(points[i]);
        S.Points.AddXY(points[i + 1].XValue, points[i].YValues[0]);
    }

}

This should answer what the title asks.这应该回答标题所问的问题。 No idea how that relates to or could help with collision detection..不知道这与碰撞检测有什么关系或可能有助于碰撞检测..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM