pathfind
Path finding on a 2D polygonal map
Go★ 62⑂ 6 forksBSD-3-Clauseupdated 1 year ago
git clone https://github.com/fzipp/pathfind.gitfzipp/pathfindREADME.mdfork it — it’s yours
pathfind
Package pathfind finds the shortest path between two points in a polygon set.
The algorithm works as follows:
- determine all concave polygon vertices
- add start and end points
- build a visibility graph
- use the A* search algorithm (package astar) on the visibility graph to find the shortest path
Demo
go run github.com/fzipp/pathfind/cmd/pathfinddemo@latest
pathfind.mp4
Example Code
package main
import (
"fmt"
"image"
"github.com/fzipp/pathfind"
)
func main() {
// (0,0) >---+ +-----------+ (50,0)
// | s | | >---+ |
// | +---+ | | d |
// | +---+ |
// (0,20) +-------------------+ (50,20)
//
// s = start, d = destination
polygons := [][]image.Point{
// Outer shape
{
image.Pt(0, 0),
image.Pt(10, 0),
image.Pt(10, 10),
image.Pt(20, 10),
image.Pt(20, 0),
image.Pt(50, 0),
image.Pt(50, 20),
image.Pt(0, 20),
},
// Inner rectangle ("hole")
{
image.Pt(30, 5),
image.Pt(40, 5),
image.Pt(40, 15),
image.Pt(30, 15),
},
}
start := image.Pt(5, 5)
destination := image.Pt(45, 10)
pathfinder := pathfind.NewPathfinder(polygons)
path := pathfinder.Path(start, destination)
fmt.Println(path)
}
Output:
[(5,5) (10,10) (30,15) (40,15) (45,10)]
License
This project is free and open source software licensed under the BSD 3-Clause License.
more like this
bit_gossip
Pathfinding library for calculating all node pairs' shortest paths in an unweighted undirected graph.
Rust★ 50
MapGridInUnity
C#★ 50
Unity-Pathfinding-Jobs-StressTest
Unity project showcasing A* pathfinding, fully jobified & burst compiled. It also contains examples of RaycastCommand a…
C#★ 50