PathFinding.js icon indicating copy to clipboard operation
PathFinding.js copied to clipboard

Grid matrix setup on browser pixels

Open YaswanthAkula opened this issue 4 years ago • 4 comments

Hi, I am using this library to draw path on HTML canvas.

I am facing performance issue when I create grid matrix with pixel number. Any idea how I can create grid matrix to overcome this performance hit?

YaswanthAkula avatar May 05 '20 05:05 YaswanthAkula

That's the limitation of the a* algorithm, its fast but if you throw a lot of nodes at it it can become slow. I suggest instead of using pixel you define areas or zones and feed that as nodes into the algorithm. For example something like this: https://youtu.be/CattLrDZt3o?t=594 (start at 9:54) you need a weighted pre-calculated graph for that, which this lib does not do but someone already implemented in a fork (see https://github.com/qiao/PathFinding.js/pull/151 )

brean avatar May 05 '20 10:05 brean

@brean can u pls help me how to divide a 1000 x1000 pixels into zones/areas?

YaswanthAkula avatar May 06 '20 10:05 YaswanthAkula

@yaswanthakula that highly depends on your scenario and what exactly you want to do. For a general solution you could do something like every 100th pixel and create 10x10 zones or you can create something based on an existing road network (like the guy in the youtube video i posted did).

brean avatar May 06 '20 11:05 brean

Exactly there I got stuck @brean Can you please help me with a piece of code how to create a zone each with 100 pixels and feed it as a node to grid. I checked that video but I didn't get how he created those zones for the grid.

Kindly help me with this.

YaswanthAkula avatar May 06 '20 12:05 YaswanthAkula