Comments (8)
Hi Arun,
The returned path is a list of coordinates in a 2D-Array representing a map. If you like to visualize that as SVG-path you have to calculate the positions based on your cell size. I think easiest would be to use a SVG-Polyline to represent it as line. If you like to use SVG M
and L
you could copy from the buildSvgPath-Function in visual/js/view.js
: https://github.com/qiao/PathFinding.js/blob/master/visual/js/view.js#L254:L265
Andreas
from pathfinding.js.
Instead of poly line which which makes the attribute lengthy, I was thinking it's better to indentify the bends in the path aray and convert them into a few H
and V
commands of svg path.
from pathfinding.js.
Hi Arun,
yes, it will be twice as long but why is that a problem?
If you really want you can calculate the difference between one points position and the next and then see if y or x changed and then create your string accordingly. Note that you are not able to display diagonal movement with only H and V.
from pathfinding.js.
If I serialize and save It might need more memory. Also I created small circles using the path array. But it created a random path as opposed to smoother horizontal and vertical lines.
Here is the configuration:
grid = new pathfinding.Grid(1000, 1000);
finder = new pathfinding.AStarFinder({
allowDiagonal: false,
heuristic: pathfinding.Heuristic.manhattan,
weight: 1,
});
and code to create the circles to trace the path
path.forEach(function (item, index) {
return s.circle(item[0], item[1], 1).attr("fill", "#ff0000");
});
from pathfinding.js.
@arunkumar413 you can research how it's implemented in react-flow. In the past I created my own react-flow edge implementation which use PathFinding.js to calculate the path
from pathfinding.js.
@killmenot I'd like to create my own as well but I'm not understanding why it created a random path instead of a Manhattan path.
Here what does the cell size refer to? I'm using svg and dimensions are in pixels only.
from pathfinding.js.
I have isolated the issue for you here: https://stackblitz.com/edit/react-febp9q?file=src%2FApp.js
I also used the buildSVGPath
function but it didn't create a manhattan path
from pathfinding.js.
It's working as expected if I apply the weight other than 1
weight: 2
from pathfinding.js.
Related Issues (20)
- The PF.Grid(matrix) didn't worked for me HOT 1
- unexpected route HOT 1
- Allow Diagonal set to false HOT 1
- Show algorithm analytics before visualization is completed
- smoothenPath ignores dontCrossCorners
- Error: TypeError: Cannot set properties of undefined (setting 'g') HOT 1
- TypeError: Cannot read properties of undefined (reading 'x') HOT 2
- Solve maze produced by https://github.com/bestguy/generate-maze HOT 2
- Adding water blocks HOT 1
- Path going straight through Towers (11111)
- two or more end tiles
- Problem 7 HOT 1
- Using Grid with - coordinates HOT 1
- Obtain the matrix from the pathfind grid
- 3D Pathfinding Demos or Documentations? HOT 3
- Unable to find multiple paths with same startNode
- TypeError: Cannot read properties of undefined (reading '6') HOT 1
- Solve on every pointerup
- All the docs images are broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pathfinding.js.