sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Shortest path analysis in Sketchup?

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 5 Posters 876 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan RathbunD Offline
      Dan Rathbun
      last edited by

      It says that solution is incorrect and inefficient.

      It seems the best solution is the C++ one, so translating that to Ruby might be a good idea.

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • sdmitchS Offline
        sdmitch
        last edited by

        @jussivee said:

        Yes, point A to B.

        Theres algorithms to solve this alright (http://en.wikipedia.org/wiki/Dijkstra's_algorithm). I'm just trying to figure out how easy/difficult it would be to actually implement it in SketchUp using Ruby (through a 3d-polyline network drawn in SketchUp). The thing is I have no experience in Ruby yet (just some rather limited experience in Java), and I would like to form an idea of just how doable this is. But it seems you can do pretty much anything with the SketchUp/Ruby combination?

        The reason why I´d like to do this in Sketchup is that it would provide a decent platform for urban planning/design issues where this shortest path analysis would be relevant.

        Jussivee, I have written my own Ruby version of the Dijkstra algorithm and it has passed all test on the somewhat simple example you posted. Could you provide a more "real world" example to test own?

        Nothing is worthless, it can always be used as a bad example.

        http://sdmitch.blogspot.com/

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jussivee
          last edited by

          Great Sdmitch!

          I guess the answer to my question then is "yeah its easily doable".

          Well, for a more real world example the network could be made more complex ad infinity, and the points A and B could be dynamic in the sense that they´re not vertices of the network itself but points which could be moved around and which would snap to the nearest point along the network (a new dynamic line would be drawn from point A/B that would snap perpendicularly to the nearest edge of the network). I dont have any example files at hand at the moment, but if you can get your hands on some street data of some city for example that would be a nice playground. Essentially the kind of routing you get in google maps etc.

          What I'm most interested though is fine grained catchment areas, of a tram stop for example. Say you´re designing a new housing area, and you want the apartments to have as good accessibility to the tram stop as possible. Well, you can just place the housing volume approximately within some certain distance from the stop, but because numbers are cool and because you want to be able to accurately compare different design alternatives on the go (as youre doing the design in sketchup) you might want to do something that i´ve tried to illustrate in the attached photos.

          1. First you have the 3d-model of your design, the building volumes and the (pedestrian) street network. The circle represents the tram stop.

          1.jpg

          1. Then with this plugin by TheDro http://sketchucation.com/forums/viewtopic.php?f=323&t=36063 you voxelize your buildings to discrete volume units.

          2.jpg

          1. Now for each of those volume units you calculate the shortest possible route through the network to the tram stop.

          3.jpg

          With this data then you can do all sorts of analysis, see how much of the volume falls within a 300 meter radius from the stop for example, or what is the overall distribution of the building volume as a function of the distance to the stop. Or what is the most used section of the network.

          The network would need to include the staircases (so that the volume units would snap to realistic places in the network) and probably theres something else to fix in this too but you get the idea.

          How about that? 😄

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            Interesting topic.

            As for these places you talk about, in the SketchUp Ruby API you can assign attributes to geometry, so you can use that to define markers for your script as to processes the model.

            I'd also think you wouldn't need to actually create the voxel geometry, but it could be used just in memory. Maybe an overlay UI using a tool - which also let you place your points.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • sdmitchS Offline
              sdmitch
              last edited by

              So let me see if I understand the problem. We have a fixed point "B", the tram station, and we want to figure out where the nearest point "A" to each "unit" in the buildings would be on the "network" then how far it is from A to B.

              Nothing is worthless, it can always be used as a bad example.

              http://sdmitch.blogspot.com/

              1 Reply Last reply Reply Quote 0
              • J Offline
                Jussivee
                last edited by

                We have a point A (tram station) and a whole bunch of points B (the voxels, I guess some center point in each one of them).

                We also have a network.

                Then we just calculate the shortest path from A to each B1...Bn.

                The result is something like this:

                A->B1 : 241 meters
                A->B2 : 243 meters
                .
                .
                .
                A->B5202 : 764 meters

                And thats the actual raw data we get. Then we can analyse it in excel or possibly integrated into the plugin, for example what is the average/median distance, or how many of these B are under 300 meters from A. Because the voxels are volume units if we calculate (the number of B under 300 meters) / (the number of all B) the result will tell us how big percentage of the planned housing volume is under 300 meters from the tram station. Etc.

                I guess you could do this without voxelisation too but that would result in a lot more difficult math. And Thomthom, if I understood you correctly you suggest the voxelisation would be done for the calculation purpose but not shown on the screen? Yes that is also possible, but I thought the voxelisation would also provide a good form to visualise the results and thus give instant feedback to the designer. The voxels could be color coded based on their distance to the calculation point (the tram station in this example).

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  Sure, if they are useful as geometry then of course. Just aired the other option as generating geometry in SU are slow operations, slows down depending on how much you have in the context you add to.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • sdmitchS Offline
                    sdmitch
                    last edited by

                    The voxels are component instances with a .definition.name prefixed with "VoxBox" so it is no problem to find them and use the .bounds.center to define its location. Then it is a matter or projecting that point to each edge of the network to find the closest edge. But, unlike a vertex, the point isn't associated with the edge in anyway that would allow you to retreive the edge and traverse back to point A. The best results I have been able to achieve so far required dividing the edges then picking the vertex closest to the projected point and using that as point "B"


                    PathFinder.jpg

                    Nothing is worthless, it can always be used as a bad example.

                    http://sdmitch.blogspot.com/

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @sdmitch said:

                      The voxels are component instances with a .definition.name prefixed with "VoxBox" so ...

                      I knew someone would need that someday ... 😉

                      @sdmitch said:

                      Then it is a matter or projecting that point to each edge of the network to find the closest edge. But, unlike a vertex, the point isn't associated with the edge in anyway that would allow you to retreive the edge and traverse back to point A.

                      Fire a vector from the bounds.center using:

                      Geom::intersect_line_line

                      or Geom::intersect_line_plane

                      or use Model#raytest()

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • A Offline
                        arlibby
                        last edited by

                        I have been working on something similar and have had some success with Dijkstra's algorithm. This is my first project with SketchUp and Ruby so my plugin has been built by trial and error and isn't very pretty.

                        The Calculate Shortest Routes command in the Plugins menu writes the results to the Ruby Console window. There is another command that writes the results to a .csv file.


                        dijkstra.rb


                        dijkstra_example.skp

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement