Skip to main content

raygeo.geo.algo.astar

A* pathfinding in an open rectangle — the shortest path is a straight line from start to goal

A pathfinding in an open rectangle — the shortest path is a straight line from start to goal*

AStarPath

length

length: float

visited

visited: int

waypoints

waypoints: list[tuple[float, float]]

Functions

find_path()

find_path(
from_: tuple[float, float],
to: tuple[float, float],
free_space: Sequence[Sequence[tuple[float, float]]],
obstacles: Sequence[Sequence[tuple[float, float]]] = [],
obstacle_margin: float = 0,
cell_size: float = 1,
) -> AStarPath | None

Find a path from from_ to to inside free_space, avoiding obstacles.

The walkable area is rasterised at cell_size resolution. Obstacles are dilated by obstacle_margin before pathfinding.

ParameterTypeDescription
from_tuple[float, float]Start point (x, y).
totuple[float, float]Goal point (x, y).
free_spaceSequence[Sequence[tuple[float, float]]]Polygons defining the walkable region.
obstaclesSequence[Sequence[tuple[float, float]]] = []Polygons defining forbidden zones (default []).
obstacle_marginfloat = 0Radius by which obstacles are expanded (default 0).
cell_sizefloat = 1Raster grid resolution (default 1.0).
ReturnsAStarPath | NoneAStarPath with waypoints, visited count, and length, or None.

A* finds a path around a central obstacle when the direct route is blocked

A finds a path around a central obstacle when the direct route is blocked*

A* threading a path between multiple disconnected obstacles — the algorithm explores the free cells and finds an optimal route

A threading a path between multiple disconnected obstacles — the algorithm explores the free cells and finds an optimal route*