Python Shortest Walk 3D: Interpolate grid of points with start & end point to get shortest curve thorough points of grid

python
(STUDENT_F) #1

Hi,

simplified 2D logic:


what you can see in my drawing ist a grid of points. I want to interpolate from A to B and A to C for example. (Route 1: A start point, B endpoint), (Route 2: A start point, C end point).

I want to interpolate through one point in every single x column (diagonal is also okay for me) but at the end, I need the shortest possible curve from A to B.

Here is my file where I define start and endpoint at the end of the script.
Tester.gh (43.8 KB)

Maybe someone can help with with the script or just the logic as well.
Thanks a lot for your help!

(IVELIN PEYCHEV) #2

Google “A* python algorithm” or “A-star python algorithm”

1 Like
(Graham) #3

Hi, in terms of the logic you just need to step each coordinate(x,y,z) by 1 until each matches your target coordinate

(STUDENT_F) #4

Is it the same like the Dijkstra’s algorithm?

(IVELIN PEYCHEV) #5

I don’t think so, because in A-star you don’t check every possible coordinate you mark the ones with increasing parameter values as DON’T GO THERE and you quickly find the path.

At least this is what I see on a prima vista.

A-star

Dijkstra

Gifs are from Wikipedia

Pretty descriptive :smiley:

(STUDENT_F) #6

Searching algorithms are a hole new field to me.
I suspect that the Dijkstra algorithm has a negative consequence for performance, beacuse in complex contexts there are many “actors” that has to be analysed by the algorithm.

I will study A* the next hours, so hopefully it works for me. Maybe I will come back to you later.

Until now, thanks a lot for your help.
One more question. Without being a computer scientist, where did you learn that kind of stuff? Is there anywhere a offical Python “Algorithm Library of different kinds (Searching Algorithms, etc.)” . I am new to Python, so I am not really shure where to sort this in the topic of rhino, grasshopper, python.

(IVELIN PEYCHEV) #7

If you don’t know what you’re doing start with Dijkstra, with a single actor, the most basic one.

Hell, I haven’t yet implemented A-star myself. Mostly because I don’t have time for that. And because I’m stubborn and I wanna do it myself :smiley:

#8

You could also implement a graph library, I like to use networkx in GHPython, uploaded a simple example of computing shortest paths on a RhinoCommon mesh here:

1 Like
(Graham) #9

I personally learned by doing project Euler challenges and reading other people’s solutions. Also see here for a bunch of Python algorithms.
https://pygorithm.readthedocs.io/en/latest/

2 Likes
(STUDENT_F) #10

Thanks a lot. I will study that!
Please check you mails!

Fabian

1 Like
(STUDENT_F) #11

Thanks a lot for that hint!

(Adam Mounsey) #12

Chris Hanleychanley also posted some useful tips/resources here: Handy Tips for GHPython Editor/Component (Rhino 6)

(Seghier khaled) #13

maybe you need first to draw a box between the two points : start & end, that make it easier to find the shortest line

(STUDENT_F) #14

why do you thank that the box helps? The points that are stored inside have an similiar array like mine in the script I posted.

(STUDENT_F) #15

Interesting information! Thanks a lot!

(Seghier khaled) #16

you want the short way between A and B so you need to reduce the possibilities and the number of points ,you can’t use all points

(Tim Stark) #18

This is no generic rule. Image a bigger box between the start and end point as obstacle and you won‘t find the Route.


About learning resources: I really enjoyed „the coding train“ YouTube channel by Daniel Shiffman and his book „the nature of code“. It‘s mostly written in processing, but it‘s easy to translate. He also has some path finding tutorials. The guy is super funny in my opinion :slight_smile:

2 Likes
(Seghier khaled) #19

Do you understand the idea? 2 points in 3d space the shortest route is inside the box between them

(Tim Stark) #20

I know what you mean. As I said, not if you have obstacles…

(STUDENT_F) #21

Guys, I am not able to implement the pseudocode example “A Star” into my script. Maybe someone can help me with the script. You can find the important part at the bottom of the script. Thanks a lot. Here is my new file: Tester.gh (47.0 KB)