Module visibility

Module visibility 

Source
Expand description

Visibility graph implementation for pathfinding with polygon obstacles

This module provides an implementation of the visibility graph algorithm for pathfinding in 2D environments with polygon obstacles. The algorithm works by connecting mutually visible points (start, goal, and obstacle vertices) and then finding the shortest path through this graph.

§Examples

use scirs2_core::ndarray::array;
use scirs2_spatial::pathplanning::VisibilityGraphPlanner;

// Create some polygon obstacles
let obstacles = vec![
    array![[1.0, 1.0], [2.0, 1.0], [2.0, 2.0], [1.0, 2.0]],  // Square obstacle
    array![[3.0, 3.0], [4.0, 3.0], [3.5, 4.0]],              // Triangle obstacle
];

// Create a visibility graph planner
let mut planner = VisibilityGraphPlanner::new(obstacles);

// Find a path from start to goal
let start = [0.0, 0.0];
let goal = [5.0, 5.0];
let path = planner.find_path(start, goal).expect("Operation failed").unwrap();

// The path contains waypoints around the obstacles
assert!(path.len() > 2); // More than just start and goal
assert_eq!(path.nodes[0], start);
assert_eq!(*path.nodes.last().expect("Operation failed"), goal);
// Note: This test is currently ignored due to implementation issues with visibility checking

Structs§

Point2D
A 2D point used in the visibility graph
VisibilityGraph
A visibility graph for pathfinding with polygon obstacles
VisibilityGraphPlanner
A pathplanning planner that uses visibility graphs to find paths