cyks.in

RRT

Draw a world. Give the robot a shape. Find a way through.

~/interactive/rrt motion planning / 001
Map & robot

Collision preview: dashed sweep, solid robot.

The cross marks the latest sample.

Cell boundaries use a 10 px grid.

Drag A or B to move it. Drag on the map to draw a wall.

Edits reset the search. Press Run when your map is ready.

The canvas shows a search tree navigating obstacles. Use the controls and live status below to follow the run.
PROCEDURAL TERRAIN
Exploring
START TREE GOAL TREE BEST ROUTE
SAMPLES0
PATH LENGTH—
How it works

What is RRT?

RRT means Rapidly-exploring Random Tree. It searches for a route by growing a tree of reachable robot positions from A toward B.

  1. Choose a random :sample.
  2. Find the nearest position already in the tree.
  3. Take a short step toward the sample.
  4. Keep the branch if a :collision check says the whole move is clear.

Repeat until the tree connects to B or runs out of samples. Select RRT and press One sample to watch this loop.

Why it spreads outward

Each node owns a :Voronoi cell: the region nearest to it. Uniform samples land in larger cells more often, giving those nodes more chances to grow.

In Informed RRT*, Largest-cell bias adds an explicit preference before the first route. At 0%, non-goal samples are uniform; at 50%, half come from the largest estimated cell; at 100%, all do. Cell areas are estimated on a 10 px grid; samples within the chosen cell use its exact clipped boundary. RRT-Connect shows the tree taking the next turn.

Sometimes aim at the goal

By default, 7% of samples target the destination. Informed RRT* lets you adjust this :goal bias. Try 100% behind a wall: always aiming at the goal leaves no samples to explore a detour.

Try another planner

RRT stops at its first route, which need not be shortest. :RRT-Connect grows from both ends. RRT* chooses cheaper parents and improves routes through :rewiring.

After finding a route, :Informed RRT* draws non-goal samples from an ellipse containing points that could shorten it. This replaces largest-cell sampling.

Give the robot a shape

Choose or draw a convex robot, then change its size and fixed angle. A gap that fits a point may block the robot; A and B must fit too. After finding a route, use Robot along route to inspect it.

Every extension, connection, and rewired branch checks the whole :swept shape, catching walls between its endpoints. The dashed outline is that area; the solid footprint is your robot. Red marks a rejected attempt, and previews clear when the run finishes. The robot does not rotate along its route.

How collision detection works

The :Minkowski difference contains every vector r − o between points in two shapes. If they overlap or touch, some r equals o, so their difference is zero. Collision becomes a test of whether the difference contains the origin. Open the definition for the picture.

:GJK tests this without building the entire difference. It searches extreme points and keeps a small :simplex near the origin. Here, the two shapes are the robot's swept area and a nearby wall.

Run the planner to inspect a GJK branch check.

Cyan is the full difference; green is GJK's :simplex. Containing the origin means contact.

What a run can guarantee

Finding nothing after 5,000 samples does not prove that no route exists. Standard RRT variants are :probabilistically complete under their usual assumptions, without a finite-time :completeness guarantee. The 100% bias settings do not inherit that guarantee.

RRT* has :asymptotic optimality under suitable conditions. A finite run can still return a longer route.

:x Swept shape

For a convex robot moving along a straight segment without rotating, the convex hull of its two endpoint footprints is exactly the region it sweeps through. GJK tests that region against each nearby wall. Contact and unresolved numerical results both reject the branch. This covers the entire translation without sampling gaps between poses.

:x Voronoi cell

A node's Voronoi cell contains every point closer to it than to another node. With uniform samples in this bounded 2D map, its selection probability equals its cell area divided by the map area. Ties on cell boundaries have zero area. Obstacles can still reject the attempted extension.

Six tree nodes divide a map into nearest-node regions. The rightmost node owns the largest region, so it receives the most uniform samples.
Every sample in a colored region chooses that region's node. The largest region gets the most chances, not every chance.

:x Informed sampling

Let c be the best route length so far. A point x can improve it only if distance(A, x) + distance(x, B) < c. In 2D, those points lie inside an ellipse with A and B as its foci. Straight-line distance is a lower bound; walls may still make a point useless.

This demo keeps RRT*'s rewiring and samples that ellipse after its first solution. It rejects samples outside the map. The dashed boundary shrinks as the route improves. It does not implement tree pruning or claim a certified shortest path at the 5,000-sample limit.

:x Minkowski difference

R − O is the set of all vectors r − o, with r in the robot and o in the obstacle. If they share a point, r = o and their difference is zero. That is why the origin lies in R − O exactly when the shapes overlap or touch. This is a geometric set operation, not a subtraction of areas.

A robot overlaps an obstacle in workspace. Their convex Minkowski difference surrounds the origin, showing the same collision in difference space.
The same contact appears as overlap on the left and origin containment on the right.

:x GJK

Gilbert–Johnson–Keerthi uses support points to test convex shapes. In direction d, it subtracts the obstacle's farthest point along −d from the robot's farthest point along d. This gives an extreme point of R − O without constructing the whole difference.

The collision test repeatedly moves a simplex toward the origin. Enclosing the origin establishes contact; a support point that cannot reach past it establishes separation. The demo uses a small numerical tolerance and reports an unresolved result if its iteration limit is reached.

:x Simplex

In this 2D test, a simplex is a point, line segment, or triangle built from support points. GJK keeps the part closest to the origin, then searches toward the origin again. A triangle surrounding the origin proves contact. Touching an edge or vertex also counts.

:x Sample

A sample is a point picked at random. The planner finds a nearby tree node and tries to grow toward the point. A rejected sample still counts toward the 5,000-sample limit.

:x Collision check

Every new branch moves the robot along a straight segment. The demo checks the whole swept footprint against nearby walls using GJK. A gap must fit the robot at its chosen size and angle. The A and B circles mark the start and goal positions.

:x RRT Connect

RRT-Connect grows trees from both ends. After one tree extends, the other repeatedly reaches toward its new branch, until they connect or hit an obstacle.

:x Rewiring

RRT* checks whether a new node offers a shorter route to nearby nodes. If it does, it changes their parent and updates the path lengths of their descendants. A later route can improve without moving any nodes.

:x Goal bias

By default, 7% of samples target the destination. RRT-Connect targets the opposite root when it switches trees. The slider in Informed RRT* changes that probability for that algorithm. Before a route, remaining samples mix uniform and largest-cell sampling according to the largest-cell bias. After a route, they come from the informed ellipse. Sampling the goal can help the tree reach it, but the tree still needs other samples to get around walls. At 100% goal bias, the usual probabilistic-completeness guarantee no longer applies.

:x Completeness

A complete planner is guaranteed to find a path in finite time whenever one exists within its model. That guarantee alone says nothing about how short the path is or how long the search takes.

:x Probabilistic completeness

If a feasible path exists, the probability of finding one approaches 1 as the number of samples grows without bound. The usual assumptions include a path with positive clearance, a sampler that can reach every open part of free space, and valid collision checks.

This gives no fixed deadline. Missing a route after 5,000 samples does not prove the map is impossible. Replay uses the same random sequence, so it repeats the same search on an unchanged map.

:x Asymptotic optimality

With continued sampling and suitable sampling and connection rules, RRT*'s best path cost converges to the optimum with probability 1. Ordinary RRT and RRT-Connect have no such guarantee. A finite run can still return a longer route.

Further reading

Inspired by ncase.