基于数组绘制地图,并应用运行时更改
我正在编写一个程序来控制移动机器人。它要做的事情之一是在机器人感知到“世界”时绘制一张地图,并在感知到地图时应用变化。 它还必须以某种方式突出显示机器人的位置以及(理想情况下)它指向的方向。
我目前有一个表示地图的自动更新数组(100 x150),使用以下表示:0 表示畅通的路径,1 表示障碍物。 我还有一个包含机器人位置和下一个位置的变量。
我需要的是可视化它。我想过使用标签,但使用它们太乏味了,而且最终的结果也不是那么漂亮。我的另一种可能性是将所有数据写入 Excel 电子表格,但随后我将回到第一个:以有吸引力的方式可视化数据。是否有某种绘图包可以完成这项工作?
总结一下:
使用:
- int[] MapArray //100 x 150 array representing the robot's world, and the data there is changing.
- Point[] Locations //Locations[0] is the current location, Locations[1] is the next step.
我想在 Windows 窗体应用程序上绘制一张地图,该应用程序以良好的视觉方式更新自身。
我希望我的问题足够清楚,如果不清楚,请随时与我联系!
I am writing a program to control a mobile robot. One of the things it has to do is to draw a map of the "world" as the robot senses it and apply changes in the map as it senses them.
It also has to highlight in some way the location of the robot and (ideally) the direction it points to.
I currently have an auto-updating array (100 x150) representing the map, using the following representations: 0 represents a clear path, 1 represents an obstacle.
I also have a variable containing the robot's location and next location.
What I need is to visualize it. I thought about using labels, but it is way too tedious using them, and the end result is not so pretty. My other possibility is to write all that data into an Excel spreadsheet, but then I will be back to square one: visualizing the data in an attractive way. Is there a drawing package of some sort that can do the job?
To sum it up:
Using:
- int[] MapArray //100 x 150 array representing the robot's world, and the data there is changing.
- Point[] Locations //Locations[0] is the current location, Locations[1] is the next step.
And I want to draw a map on a Windows Forms application that updates itself in a nice visual manner.
I hope my question is clear enough, don't hesitate to contact me if not!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试代码:在表单 (Visual C#) 或类似的东西。
图形编程示例主题
只需编写几个循环来访问数组的每个单元格并根据坐标在表单上绘制一个矩形 - 这是最简单的方法。
绘图位置也是如此。
Try Code: Drawing a Filled Rectangle on a Form (Visual C#) or something similar.
Graphics Programming Example Topics
Just write a couple of cycles which accesses every cell of an array and draws a rectangle on a form according to coords - that's the simplest way.
The same for the drawing location.
如果您找不到任何好的控件,您始终可以使用列宽=行高的 DataGridView,以便它始终显示方形单元格。之后,只需更改障碍物的背景颜色即可。
您还可以查看地图数组的可观察集合,以便网格根据事件而不是计时器进行更新。确保覆盖可观察集合以发送 CollectionChanged 事件,即使单元格更改其值时也是如此,而不仅仅是在添加/删除单元格时。
If you don't find any nice controls, you can always use a DataGridView with the column width = row height so that it always displays square cells. After that, just change the background color of the obstacles.
You could also look into observable collections for the map array so that the grid updates based on events rather than on timers. Make sure that you overwrite the observable collection to send the CollectionChanged event even when a cell changes its value, not only when adding/removing cells.