In this exercise, we’ll leverage work from the automated room outlining script to find walking paths and distances between room without drawing a single line.
What, Why and How:
Every day we use GPS on our phones to navigate across the city, using real time traffic data to find the best way to our destination. Yet we don’t often give buildings, especially large complex ones, the same treatment outside of life safety plans. In software like ArcGIS, we can determine the optimal distribution of health centers throughout a city to ensure that no one has to drive more than 30 minutes to reach one. In buildings like hospitals, we can apply the same logic to ensure that nurses don’t have to walk more than 1 minute to reach a supply closet, or to ensure that resources are sufficiently close to the emergency department to respond to emergent cases.
The challenge of path finding, either in the city or inside a building, boils down to the shortest path problem. We give the computer a list of paths that we can take from one place to another, and the algorithm determines the best way to get from point A to point B.
In this exercise, we’ll look at how to find paths along one hallway. This scale provides a good basis for showing the concept, and we’ll scale up to analyze paths throughout buildings once we’ve laid the foundation for the analysis.
The Walk Through: Diving in to Grasshopper
Selecting Rooms: From Point A to Point B
We’ll start from the script we created in the automated room identification exercise. From the Area component in our script we have a list of center points for each room. Just like in your phone, the first step to finding a path is to choose which room we want to start in, and which room we want to end in.
To make the selection, we will pass the list of room centers into two list item components, one for the start point and one for the end point. Then, we’ll create a number slider for each so that we can adjust the rooms dynamically.
Since Grasshopper doesn’t show us which point is being chosen, we want to add indicators in Rhino to identify these points. First we’ll draw a line between the two selected room centers using the line component (this is necessary for the next step).Then, to further emphasize the rooms, we’ll draw a circle around the two selected points by passing both points into the circle component.
Find the Shortest Path on the Analysis Mesh
Given all the work we’ve done, you’d expect that finding the shortest path from one room to another is a complicated endeavor. However, the magic of Grasshopper packages the algorithm into a simple component.
To get the shortest path we need a few things. First, the C input is a list of curves that we are going to find a path along. This list of curves is a lot like the list of roads you can navigate through when traveling in the city. Since the analysis mesh connects all of the points the drawing, we can reuse its curves as our navigation mesh. To translate the mesh into a list we can use, we’ll take the output of the region intersection component, explode it, then pass the flattened list of curves into the shortest walk component.
Fun fact: this is how AI characters in some video games figure out how to move through the virtual environment.
Next, we need to tackle the L input, which is the lengths of all of the curves. To get the curve lengths, we’ll take the list of curves from the explode component, pass the list to the length component, and pass the flattened list into the L input.
Finally, we need the P input, which is a line from our starting point to our ending point. For this input, we can reuse the line we drew between the center points of the starting room and ending room.
Join the Shortest Path to the Room Center
You’ll notice that the resulting polyline from the shortest walk component only includes the mesh curves that we passed into it. The last step is to connect the shortest walk polyline to the room centers.
To create the final lines, we’ll need to do a little bit of extra work. First we’ll pass the shortest walk polyline into an endpoints component then combine the start and end points into a list using a point component. Next we’ll pass the start and end points into a line component along with the two room centers we selected using the list item components. With the polyline connected to the room centers we just need to combine all three curves using the join component. The result of joining the three curves is our shortest path between the two rooms.
Now you may be look at the shortest walk path and realize it takes some unnecessary detours. The path hugs the walls when more direct routes are available. This “wall hugging” feature is due to the Delaunay mesh we used to generate the curves we are navigating along. To make the walking path more natural we could refine the final polyline by manipulating the control points. Ultimately, however, the refinement process could fill an entire article, so we’ll save that process for another day.
Next Steps: Scaling Up From Hallways to Buildings
With the script complete, we’ve laid out the basic methodology of finding walking distances between rooms. Next we’ll expand on this line of thinking by scaling up from one hallway to an entire building. At the building scale, these paths become useful for studying and optimizing adjacencies.
Coming soon…