You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-6Lines changed: 37 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,9 +8,10 @@ This library is meant to provide pathfinding algorithms which are easily to use
8
8
9
9
This library is created in typescript and provides types.
10
10
11
-
There is a [demo project](https://casper64.github.io/pathfinding-js) ([repository](https://github.com/Casper64/Casper64.github.io/blob/master/pathfinding-js/src/index.ts)) to show how you could implement the library in a sort of visualisation.
11
+
I made a visualisation with this library for square grids [here](https://casper64.github.io/pathfinding-js) ([code](https://github.com/Casper64/Casper64.github.io/blob/master/pathfinding-js/src/index.ts)).
12
+
And another visualisation how the algorithms generate a navigation mesh (non square 2d plane) based on the shapes you place in the 2d grid [here](https://casper64.github.io/pathfinding-js/navmesh) ([code](https://github.com/Casper64/Casper64.github.io/blob/master/pathfinding-js/navmesh/src/index.ts)) (working on implementing this in 3D!).
12
13
13
-
Note: you can only use this library for 2d grids!
14
+
Note: This library is still in early stages of development so function and class names could change in the future!
14
15
15
16
Installation
16
17
------------
@@ -38,8 +39,8 @@ var grid = new pf.Grid(10, 8);
38
39
</script></script>
39
40
```
40
41
41
-
Basic usage
42
-
-----------
42
+
Basic usage 2d square grids
43
+
---------------------------
43
44
Create a grid of width 10 and height 8:
44
45
```javascript
45
46
let grid =newpf.Grid(10, 8);
@@ -70,8 +71,8 @@ For the `grid` defined previously `result.path` will be:
Options can be passed in the constructor of the finder:
76
77
```javascript
77
78
let finder =newpf.AStar({
@@ -82,3 +83,33 @@ let finder = new pf.AStar({
82
83
});
83
84
```
84
85
In this example the A* algorithm searches from the start and from the end (bidirectional search), is allowed to go diagonal and smoothens the path and also uses the Eucledian heuristic function.
Next instantiate some object that should be in the map. They could be any polygon, but the algorithm Bowyer-Watson algorithm used in this library works best for convex polygons. Meaning that the shapes don't have large indents and they cannot overlap. For example:
95
+
```javascript
96
+
let object1Vertices = [newpf.Point(10, 10), newpf.Point(30, 5), newpf.Point(20, 20)];
let grid =newpf.MeshGrid([object1, object2, object3, object4], outlay.vertices);
106
+
grid.generateMap();
107
+
```
108
+
The generation of the map takes a bit of time (around 500ms on a normal computer with 40 objects with 4 vertices), depending on how many objects you put in the grid. But when the map is generated the very fast A* algorithm saves you time and finds the path faster than with 2d square grids!. You have to use the A* algorithm in the following way:
109
+
```javascript
110
+
let finder =newpf.Astar(); // no options needed
111
+
let result =finder.findPathMesh(newpf.Point(2, 4), newpf.Point(95, 95), grid);
112
+
// result.path is the same path of points as with 'Astar.findPath'
113
+
```
114
+
The path given by 'Astar.findPathMesh' is not perfect, but close to perfect. In this case speed outweighs precision.
115
+
Funny: The algorithms works better if you put more object into the map!
0 commit comments