r/AskProgramming • u/darklighthitomi • Apr 13 '26
Is my new pathfinding algorithm any good?
Could not find a better reddit, so I'll turn this into a question asking for opinions.
had an idea for an algorithm to pathfind. It is not about finding the literal shortest nor cheapest path but makes the assumption that a straight line is the best option.
The algorithm starts off with a line of sight check (pick your favorite) but clear space is of course about traversability.
An overly simplistic case for demonstration. Imagine a short wall between the source and destination. The algorithm follows a straight line to the destination. When this line hits a wall, it start follows the wall in both directions until a corner is found. The algorithm then makes two line of sight checks. One to check line of sight from the source to the corner, and another from the corner to the destination. If both are clear, it is kept as a valid path. Otherwise, the algorithm is performed recursively, this time on two paths, from the source to the corner, and from the corner to the destination.
Once one valid path is found, any others in progress will be checked periodically and those of longer distance cancelled and ignored, keep checking until all paths either reach completion or get culled, leaving one shortest path.
Obviously a few details need to be taken care of, such as adding a little padding around the corners to make sure the object to follow the path can actually fit (proper handling of the padding can treat bars as a straight flat barrier) as well as not flowing through two obstacles that only meet at a point, and also covering a case where the source is completely surrounded or otherwise unable to find a valid path.
Is this algorithm any good? Does it exist already?
17
u/[deleted] Apr 13 '26
Kind of a meaningless (and oddly vague) question considering you haven't clarified whether this is operating in two dimensions or three, whether this would be operating on a planar surface or not, nor the desired angular precision of the resulting vector... I'll be honest, your post really does sound like the result of a psychotic ChatGPT waffle session, no offense.
3
u/throwaway8u3sH0 Apr 13 '26
A similar algorithm already exists. It's called A* ("A star"). It uses the straight line distance as a hueristic to estimate "cost," exploring paths with the lowest cost until it finds the shortest path.
You can implement it quite easily with just a text file map. Great for learning.
6
u/andarmanik Apr 13 '26
You’re actually close to a real algorithm for path finding. Look up visibility graph path finding.
The process that you speak of where you slide up or down edges to vertices is the right intuition, accept all that can be precomputed as the visibility graph itself.
Basically your problem with a visibility graph is:
1: find all vertices in the obstacles that are visible to source.
2: find all vertices in the obstacles that are visible to target.
3: take the base visibility graph and add two notes for the source and target.
4: add edges to source and target node from (1) and (2)
5: Perform graph based path finding (dijkstra or A*)
I have an example of this type of pathing in my game Scope Node
2
u/BackAware6850 Apr 13 '26
Sounds like Soukup"s algorithm. DAC 1978
Fast maze router | Proceedings of the 15th Design Automation Conference https://dl.acm.org/doi/10.5555/800095.803072
7
u/mxldevs Apr 13 '26
I think you will need to define what a "corner" and a "wall" means in terms of how it will be represented in the algorithm because at this point it's not very clear how you are actually going to implement the algorithm.
Is this graph traversal or something else?
For example, this animation sounds a lot like what you're describing
1
u/Successful_Yam_9023 Apr 13 '26
It bears some similarity (which does not mean it's the same, there is just some similar element to it) to jump point search.
0
u/[deleted] Apr 13 '26
[deleted] — view deleted comment
0
u/[deleted] Apr 13 '26
[deleted] — view deleted comment