-3

I have a question. I would like to calculate the minimum path from a point. These points are inside a building. The problem is that the place where these points are present is indoors, so I don't know how to do it.

enter image description here

I have attached a photo. The photo shows the floor plan of a building. I wish I could draw a path from A to B.

Thanks!!

My only solution is to divide the plant with squares and give coordinates to the squares. The problem is that I would not know how to draw the path, and precisely how to calculate it.

Thanks!

1 Answers1

0

How is your data modelled? The solution depends on that.

One way to model your data (floor plan) is via a 2-dimensional grid such as:

{{0, 0, 0, 0, 0},
 {0, 1, 0, 1, 0},
 {1, 0, 1, 0, 0},
 {0, 0, 0, 0, 0},
 {1, 0, 0, 0, 0}}

Where 0 implies that it's a walking area and 1 implies that the cell is blocked and you can't walk there.

You can create a mapping of your floor plan to such a mxn two dimensional array.

And then, you know which cell is your starting place (point A) and which cell is your ending place (point B).

With this much info, you can use DFS (Depth first search) algorithm to find the shortest route between point A and point B.

In your algorithm, you have to detect and avoid loops.

Hope that helps. If you are able to model your data this way, and need help with the actual algorithm, leave a comment and I'll try to explain that part as well.

  • can you say me more about that? – Francesco Mar 25 '22 at 20:57
  • For example, for the above mentioned example of data model, let say, you want to find the minimum path algorithm to go from top left to bottom right cell. This is how your pseudo code will look like: 1. `Initialize a queue with the starting cell` 2. `For each cell in the queue, add all the other cells that you haven't seen before in the queue` 3. `Keep a track of level` 3. `If the cell is the target cell, the level is the minimum length path`. You can modify to keep track the actual path as well. – Pratik Panchal Mar 27 '22 at 04:43