pathfinding3d.core.util module

pathfinding3d.core.util.backtrace(node)[source]

Backtrace according to the parent records and return the path. (including both start and end nodes)

Parameters:

node (GridNode) – node to backtrace from

Returns:

path

Return type:

List[GridNode]

pathfinding3d.core.util.bi_backtrace(node_a, node_b)[source]

Backtrace from start and end node, returns the path for bi-directional A* (including both start and end nodes)

Parameters:
Returns:

path

Return type:

List[GridNode]

pathfinding3d.core.util.raytrace(coords_a, coords_b)[source]

Given the start and end coordinates, return all the coordinates lying on the line formed by these coordinates, based on ray tracing.

Parameters:
  • coords_a (Coords) – start coordinates

  • coords_b (Coords) – end coordinates

Returns:

list of coordinates

Return type:

List[List[float]]

pathfinding3d.core.util.bresenham(coords_a, coords_b)[source]

Given the start and end coordinates, return all the coordinates lying on the line formed by these coordinates, based on Bresenham’s algorithm.

Parameters:
  • coords_a (Coords) – start coordinates

  • coords_b (Coords) – end coordinates

Returns:

list of coordinates

Return type:

List[List[float]]

pathfinding3d.core.util.expand_path(path)[source]

Given a compressed path, return a new path that has all the segments in it interpolated.

Parameters:

path (List[Coords]) – path to expand

Returns:

expanded path

Return type:

List[Coords]

pathfinding3d.core.util.smoothen_path(grid, path, use_raytrace=False)[source]

Given an uncompressed path, return a new path that has less turnings and looks more natural.

Parameters:
  • grid (Grid) – grid

  • path (List[Coords]) – path to smoothen

  • use_raytrace (bool, optional) – whether to use raytrace, by default False

Returns:

smoothened path

Return type:

List[List[float]]

pathfinding3d.core.util.line_of_sight(grid, node1, node2)[source]

Check if there is a line of sight between two nodes using Bresenham’s algorithm

Parameters:
  • grid (Grid) – The grid on which the nodes exist

  • node1 (GridNode) – The first node

  • node2 (GridNode) – The second node

Returns:

True if there is a line of sight between the two nodes, False otherwise

Return type:

bool