# Module 3.3: Sampling-Based Planners for High Dimensions

- Course: [Course 3: Motion Planning & Navigation](https://roboticsconcepts.dev/courses/motion-planning-navigation.md)
- HTML Page: https://roboticsconcepts.dev/courses/motion-planning-navigation/sampling-based-planners/
- Key Concepts: Curse of dimensionality, Probabilistic Roadmaps (PRM), RRT & asymptotically optimal RRT*

Grid search feels almost unstoppable in 2D — until you try running A* on a 7-joint robot arm. The first time I computed how much RAM a naive 7D grid takes, I thought I had misplaced a decimal point.

## The grid explosion in 6 and 7 dimensions

Suppose you discretize each joint of a robot arm into just 50 bins — roughly 7 degrees per step, which isn't even very fine. For a 2-link arm, 50 × 50 is 2,500 cells. Easy.

Now try a standard 6-DOF industrial arm: 50⁶ is 15.6 billion cells. On a 7-DOF arm like a Franka Panda, 50⁷ is 781 billion cells. You cannot store that grid in memory, let alone run A* over it before the battery dies. That exponential blowup is the curse of dimensionality.

## Throwing random darts instead of painting every square

Instead of visiting every grid cell in order, sampling-based planners toss random configurations into C-space and check whether they are collision-free. Two families dominate real robotics libraries:

- Probabilistic Roadmaps (PRM): scatter random valid points across the whole space, connect nearby points with collision-free straight lines to build a reusable highway network, then run graph search on that sparse roadmap.
- Rapidly-Exploring Random Trees (RRT): grow a single branching tree outward from the start pose. Each step picks a random target point in space, finds the nearest existing tree node, and extends one small step toward it — naturally pulling branches into unexplored rooms.
- RRT*: keeps the fast exploration of RRT, then rewires nearby branches whenever a new sample offers a shorter route back to the start, gradually straightening jagged random paths toward optimal ones.

## Interactive Sandbox: BFS, Dijkstra, A*, and RRT Pathfinding Visualizer

Select RRT in the pathfinding sandbox below and test it on the Narrow Gap map. Notice how the tree reaches across open regions quickly, why its first path zigzags, and why squeezing through a tiny doorway takes many samples.

## Probabilistic completeness and the narrow-passage headache

Because RRT never builds a uniform grid, it works just as easily in 7 or 14 dimensions as it does in 2D. If a valid path exists, the odds of finding one approach 100% as you add more samples — a property called probabilistic completeness.

The catch is narrow doorways. Random darts mostly land in big open rooms, so threading through a keyhole takes patience (or goal-biasing and bidirectional RRT-Connect, which grows two trees toward each other from both start and goal at once). And raw RRT paths look jittery and circuitous, which is why we always smooth them afterward.

## Why grids fail while trees scale

```text
Grid cells = N^d   vs.   RRT step: q_new = q_near + ε · (q_rand − q_near) / ‖q_rand − q_near‖
```

Grid size grows exponentially with dimension d, making N^d hopeless past 3–4 DOF. RRT only stores sampled vertices and straight local segments, scaling to 7+ DOF arms and multi-robot teams.

## Check Your Intuition

**Question:** Why does standard RRT almost always produce a jagged, longer-than-necessary path on its first solution, whereas RRT* improves it over time?

- [ ] RRT forbids straight lines between nodes
- [✓] RRT stops as soon as any branch touches the goal and never rewires existing parent edges when a better shortcut appears
- [ ] RRT uses Manhattan distance instead of Euclidean distance

**Explanation:** Vanilla RRT only connects each new sample to its single nearest neighbor and never revisits older edges. RRT* checks a neighborhood radius and rewires parent links whenever a shorter path through the new node is collision-free.

## Where You'll See This in Modern Robotics

Bidirectional RRT-Connect (inside OMPL and MoveIt) is still one of the most common default arm planners in factories and research labs, often paired with trajectory optimization or GPU-parallelized rollouts like cuRobo.

## Companion Python Notebook: 03 · Sampling-Based Planners: PRM, RRT & RRT*

Grow an RRT and rewiring RRT* tree through narrow passages and compare path length improvement over iterations.

- Open in molab (WASM): https://molab.marimo.io/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/course-3/03_sampling_based_planners_rrt.py/wasm
- Open in Google Colab: https://colab.research.google.com/github/alchemicduncan/robotics-concepts-dev/blob/main/notebooks/colab/course-3/03_sampling_based_planners_rrt.ipynb
- Download .py: https://roboticsconcepts.dev/downloads/notebooks/course-3/03_sampling_based_planners_rrt.py
- Download .ipynb: https://roboticsconcepts.dev/downloads/notebooks/colab/course-3/03_sampling_based_planners_rrt.ipynb
- Run locally: `uvx marimo edit --sandbox notebooks/course-3/03_sampling_based_planners_rrt.py`
