Dibujar un mapa basado en una matriz y aplicar cambios en el tiempo de ejecución

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?

En resumen:

Uso:

 - 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!

preguntado el 08 de enero de 11 a las 17:01

Hey all again, In the end I have used semyon's suggestion, and I have found a graphing package called ZedGraph, which I now use. Thanks for the help! -

2 Respuestas

Trata Code: Drawing a Filled Rectangle on a Form (Visual C#) o algo 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.

for(int i=0; i<100; i++)
{
    for(int j=0;j<150;j++)
    {
        <access[i,j] and draw a rectangle with color accordingly to your contents.>
    }
}

The same for the drawing location.

Respondido 31 Jul 11, 17:07

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.

Respondido el 08 de enero de 11 a las 20:01

Hey, Thanks! I have never worked with observable collection before, How would you implement one for this case? - Yarok

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.