Algorithm Search⌘K

Algorithmcore

Dubins path

Also called Dubins curves.

The shortest path of a forward-only car with bounded curvature, one of six words of arcs and lines, CSC or CCC.

Time
O(1) worst
Space
O(1) extra
Where
w = the number of candidate words, six
Properties
deterministicexactofflinenot randomized
Origin
Lester E. Dubins, 1957

A Dubins path is a shortest path between two poses of a car that drives only forward and cannot turn tighter than a radius ρ\rho. A pose is (x,y,θ)(x, y, \theta): a position in the plane and a heading. Dubins proved in 1957 that such a shortest path always exists and is made of at most three pieces, each an arc of radius exactly ρ\rho (written L for a left turn and R for a right turn) or a straight segment (S). Only six words can be shortest: LSL, RSR, LSR, RSL, RLR and LRL. The algorithm computes the three segment lengths of each word in closed form and returns the shortest word, in constant time. It is the steering function of many car planners, for example hybrid A*, and the exact cost-to-go that their heuristics approximate.

In plain words

A car drives on an empty parking lot and must stop at a given spot, facing a given way. It cannot back up, and the steering wheel has a stop. The shortest way is always simple: turn with the wheel at the stop, drive straight, and turn with the wheel at the stop again. When the target is very close, a straight piece does not help, and the shortest way is three hard turns: one way, the other way, then the first way again.

There are only six such patterns. For each one, a little trigonometry gives the length of the three pieces. You compute all six and take the shortest.

The problem

The model. The car is the unicycle model with a forward speed v=1v = 1 and a turn rate ∣ω∣≤1/ρ|\omega| \le 1/\rho, so its path has curvature at most 1/ρ1/\rho. In the units of the code, x′=cos⁡θx' = \cos\theta, y′=sin⁡θy' = \sin\theta, θ′=u/ρ\theta' = u/\rho with u∈[−1,1]u \in [-1, 1], and time equals arc length. The same paths serve the rear axle of the kinematic bicycle model with wheelbase LL and steering limit δmax\delta_{max}, with ρ=L/tan⁡δmax\rho = L / \tan \delta_{max}. There are no obstacles. Numbers are reals and each arithmetic operation, square root and trigonometric function costs one step, as in the real RAM.

Input. A start pose q0=(x0,y0,θ0)q_0 = (x_0, y_0, \theta_0), a goal pose q1=(x1,y1,θ1)q_1 = (x_1, y_1, \theta_1), both in meters and radians, and the minimum turning radius ρ>0\rho > 0 in meters.

Output. A word ww from the six and three lengths (ℓ1,ℓ2,ℓ3)(\ell_1, \ell_2, \ell_3), all at least 0, such that driving the three segments of ww from q0q_0 ends at q1q_1, and ℓ1+ℓ2+ℓ3\ell_1 + \ell_2 + \ell_3 is the least length of any forward path with curvature at most 1/ρ1/\rho.

How it differs from close pages. The Reeds-Shepp path solves the same problem for a car that may also reverse; its shortest path is never longer and has up to five segments. Kinodynamic planning is the general problem with obstacles and dynamics, where a Dubins path is only a local connection between two states. The Euclidean shortest path ignores the heading and the curvature. A search such as A* or hybrid A* handles the obstacles and calls the Dubins solver as a heuristic or as a final shot to the goal.

The algorithm

Move to a frame where the start is at the origin and the goal lies on the positive xx axis, and scale all lengths by 1/ρ1/\rho. Then the problem has three numbers: the scaled distance dd, the start heading α\alpha and the goal heading β\beta, both measured from the line from start to goal. Write tt, pp, qq for the three scaled segment lengths. An arc of scaled length tt turns the heading by tt radians. All angles are taken modulo 2π2\pi into [0,2π)[0, 2\pi), written mod2π\mathrm{mod}_{2\pi}.

  1. DUBINS(q0, q1, ρ)
  2. 1d ← |p1 - p0| / ρ; φ ← the direction of p1 - p0
  3. 2α ← mod2π(θ0 - φ); β ← mod2π(θ1 - φ)
  4. 3best ← none
  5. 4for each word w in LSL, RSR, LSR, RSL, RLR, LRL do
  6. 5if the closed form of w gives (t, p, q) for (d, α, β) then ℓ ← ρ (t + p + q)
  7. 6if best is none or ℓ < the length of best then best ← (w, ρ t, ρ p, ρ q)
  8. 7return best

Line L5 uses the closed forms below, with sα=sin⁡αs_\alpha = \sin\alpha, cα=cos⁡αc_\alpha = \cos\alpha and the same for β\beta. A word does not exist when its p2p^2 is negative or its ∣c∣|c| is above 1.

Word Condition pp tt and qq
LSL p2=2+d2−2cos⁡(α−β)+2d(sα−sβ)≥0p^2 = 2 + d^2 - 2\cos(\alpha - \beta) + 2d(s_\alpha - s_\beta) \ge 0 p2\sqrt{p^2} γ=atan2(cβ−cα,d+sα−sβ)\gamma = \mathrm{atan2}(c_\beta - c_\alpha, d + s_\alpha - s_\beta), t=γ−αt = \gamma - \alpha, q=β−γq = \beta - \gamma
RSR p2=2+d2−2cos⁡(α−β)+2d(sβ−sα)≥0p^2 = 2 + d^2 - 2\cos(\alpha - \beta) + 2d(s_\beta - s_\alpha) \ge 0 p2\sqrt{p^2} γ=atan2(cα−cβ,d−sα+sβ)\gamma = \mathrm{atan2}(c_\alpha - c_\beta, d - s_\alpha + s_\beta), t=α−γt = \alpha - \gamma, q=γ−βq = \gamma - \beta
LSR p2=−2+d2+2cos⁡(α−β)+2d(sα+sβ)≥0p^2 = -2 + d^2 + 2\cos(\alpha - \beta) + 2d(s_\alpha + s_\beta) \ge 0 p2\sqrt{p^2} γ=atan2(−cα−cβ,d+sα+sβ)−atan2(−2,p)\gamma = \mathrm{atan2}(-c_\alpha - c_\beta, d + s_\alpha + s_\beta) - \mathrm{atan2}(-2, p), t=γ−αt = \gamma - \alpha, q=γ−βq = \gamma - \beta
RSL p2=−2+d2+2cos⁡(α−β)−2d(sα+sβ)≥0p^2 = -2 + d^2 + 2\cos(\alpha - \beta) - 2d(s_\alpha + s_\beta) \ge 0 p2\sqrt{p^2} γ=atan2(cα+cβ,d−sα−sβ)−atan2(2,p)\gamma = \mathrm{atan2}(c_\alpha + c_\beta, d - s_\alpha - s_\beta) - \mathrm{atan2}(2, p), t=α−γt = \alpha - \gamma, q=β−γq = \beta - \gamma
RLR c=(6−d2+2cos⁡(α−β)+2d(sα−sβ))/8∈[−1,1]c = (6 - d^2 + 2\cos(\alpha - \beta) + 2d(s_\alpha - s_\beta))/8 \in [-1, 1] 2π−arccos⁡c2\pi - \arccos c t=α−atan2(cα−cβ,d−sα+sβ)+p/2t = \alpha - \mathrm{atan2}(c_\alpha - c_\beta, d - s_\alpha + s_\beta) + p/2, q=α−β−t+pq = \alpha - \beta - t + p
LRL c=(6−d2+2cos⁡(α−β)+2d(sβ−sα))/8∈[−1,1]c = (6 - d^2 + 2\cos(\alpha - \beta) + 2d(s_\beta - s_\alpha))/8 \in [-1, 1] 2π−arccos⁡c2\pi - \arccos c t=−α−atan2(cα−cβ,d+sα−sβ)+p/2t = -\alpha - \mathrm{atan2}(c_\alpha - c_\beta, d + s_\alpha - s_\beta) + p/2, q=β−α−t+pq = \beta - \alpha - t + p

The values of tt and qq are reduced with mod2π\mathrm{mod}_{2\pi}. These are the forms of Shkel and Lumelsky (2001), which LaValle also gives in Section 15.3.1. Each one comes from the circles of radius 1 that the car follows at the start and at the goal. For LSL, the left circles have centers (−sα,cα)(-s_\alpha, c_\alpha) and (d−sβ,cβ)(d - s_\beta, c_\beta), the straight part is their outer common tangent, and its length is the distance between the centers, which is the pp of the table. For LSR, the straight part is an inner common tangent, so p2p^2 is the squared distance of the centers minus 4. For RLR and LRL, the middle circle touches both end circles, so its center is at distance 2 from both, and cc is the cosine that the law of cosines gives in the triangle of the three centers.

Example

Let ρ=1\rho = 1 m, the start q0=(0,0,0)q_0 = (0, 0, 0) and the goal q1=(3,4,π/2)q_1 = (3, 4, \pi/2), with lengths in meters. Line L1 gives d=5d = 5 and φ=atan2(4,3)=0.9273\varphi = \mathrm{atan2}(4, 3) = 0.9273 rad. Line L2 gives α=2π−0.9273=5.3559\alpha = 2\pi - 0.9273 = 5.3559 and β=π/2−0.9273=0.6435\beta = \pi/2 - 0.9273 = 0.6435. The loop of lines L4 to L6 finds five words. RLR does not exist, because c<−1c < -1: the two right circles are more than 4 m apart.

Word ℓ1\ell_1 (m) ℓ2\ell_2 (m) ℓ3\ell_3 (m) Length (m)
LSL 0.9828 3.6056 0.5880 5.1763
LRL 3.0014 4.0373 2.6066 9.6453
RSL 5.4734 5.0000 0.7610 11.2344
LSR 1.0550 4.5826 5.7674 11.4050
RSR 5.3871 6.4031 5.6084 17.3987

The answer is LSL. You can check it by hand. The left circle at the start has center (0,1)(0, 1) and the left circle at the goal has center (2,4)(2, 4). The line between the centers has direction atan2(3,2)=0.9828\mathrm{atan2}(3, 2) = 0.9828 rad, so the car first turns left by 0.9828 rad, drives 22+32=13=3.6056\sqrt{2^2 + 3^2} = \sqrt{13} = 3.6056 m, and turns left by π/2−0.9828=0.5880\pi/2 - 0.9828 = 0.5880 rad.

A second case shows a CCC word. For the U-turn on the spot from (0,0,0)(0, 0, 0) to (0,0,π)(0, 0, \pi) with ρ=1\rho = 1 m, the CSC words LSL and RSR have length 11.4248 m, and LSR and RSL do not exist. RLR and LRL both give arcs of π/3\pi/3, 5π/35\pi/3 and π/3\pi/3 rad, a total of 7π/3=7.33047\pi/3 = 7.3304 m. The middle arc is longer than π\pi, as Dubins' theorem says it must be.

Correctness

The proof has two parts. The first is a check of the closed forms: for each word, the three segments of line L5 start at q0q_0 and end at q1q_1, because the straight part is a common tangent of the two end circles, or the middle arc lies on a circle that touches both. The second part is Dubins' theorem, which the page uses and does not prove: a shortest path exists, has one of the six words, and has a middle arc longer than πρ\pi\rho when it is CCC. For each word, the path with arcs in [0,2π)[0, 2\pi) (and a middle arc in [π,2π][\pi, 2\pi] for CCC) is unique, so the candidate set contains the shortest path, and lines L3 to L7 return it.

Proof: The Dubins algorithm returns a shortest forward path of bounded curvaturefull

Line numbers refer to the pseudocode on the Dubins path page. We work in the frame of lines L1 and L2: the start is at the origin with heading α\alpha, the goal is at (d,0)(d, 0) with heading β\beta, and all lengths are divided by ρ\rho, so every arc has radius 1. A rigid motion of the plane and a scaling map paths of curvature at most 1/ρ1/\rho to paths of curvature at most 1 and multiply lengths by 1/ρ1/\rho, so a shortest path in this frame is a shortest path in the original one. We write u(ψ)=(cos⁡ψ,sin⁡ψ)u(\psi) = (\cos\psi, \sin\psi) and n(ψ)=(−sin⁡ψ,cos⁡ψ)n(\psi) = (-\sin\psi, \cos\psi), the unit vector to the left of the heading ψ\psi.

Lemma 1 (motion on one segment). A car at position zz with heading ψ\psi that drives a left arc of angle a≥0a \ge 0 ends at z+n(ψ)−n(ψ+a)z + n(\psi) - n(\psi + a) with heading ψ+a\psi + a. A right arc of angle aa ends at z−n(ψ)+n(ψ−a)z - n(\psi) + n(\psi - a) with heading ψ−a\psi - a. A straight segment of length ss ends at z+s u(ψ)z + s\,u(\psi) with heading ψ\psi.

Proof. A left arc of radius 1 has its center at c=z+n(ψ)c = z + n(\psi), and the car stays at c−n(⋅)c - n(\cdot) of its current heading. After turning by aa it is at c−n(ψ+a)c - n(\psi + a). The right arc is the mirror image with c=z−n(ψ)c = z - n(\psi). The straight segment is clear. □\square

Lemma 2 (CSC words end at the goal). If line L5 accepts LSL, RSR, LSR or RSL, the path with segments (t,p,q)(t, p, q) from (0,0,α)(0, 0, \alpha) ends at (d,0,β)(d, 0, \beta).

Proof. LSL. The start circle has center c0=n(α)=(−sα,cα)c_0 = n(\alpha) = (-s_\alpha, c_\alpha) and the goal circle, the left circle through the goal, has center c1=(d,0)+n(β)=(d−sβ,cβ)c_1 = (d, 0) + n(\beta) = (d - s_\beta, c_\beta). Their difference is c1−c0=(d+sα−sβ,cβ−cα)c_1 - c_0 = (d + s_\alpha - s_\beta, c_\beta - c_\alpha), whose squared norm is d2+2d(sα−sβ)+(sα−sβ)2+(cβ−cα)2=2+d2−2cos⁡(α−β)+2d(sα−sβ)=p2d^2 + 2d(s_\alpha - s_\beta) + (s_\alpha - s_\beta)^2 + (c_\beta - c_\alpha)^2 = 2 + d^2 - 2\cos(\alpha - \beta) + 2d(s_\alpha - s_\beta) = p^2. So c1−c0=p u(γ)c_1 - c_0 = p\,u(\gamma) with the γ\gamma of the table. By Lemma 1, after the left arc of angle t≡γ−αt \equiv \gamma - \alpha the car is at c0−n(γ)c_0 - n(\gamma) with heading γ\gamma. After the straight segment of length pp it is at c0−n(γ)+p u(γ)=c1−n(γ)c_0 - n(\gamma) + p\,u(\gamma) = c_1 - n(\gamma), still with heading γ\gamma. That point lies on the goal circle, and the car turns about c1c_1. After the left arc of angle q≡β−γq \equiv \beta - \gamma it is at c1−n(β)=(d,0)c_1 - n(\beta) = (d, 0) with heading β\beta. Angles are used only through uu and nn, so reducing tt and qq modulo 2π2\pi does not change the end point.

RSR is the mirror image of LSL in the xx axis: the substitution α→−α\alpha \to -\alpha, β→−β\beta \to -\beta maps the LSL formulas to the RSR formulas, and the mirror maps left arcs to right arcs.

LSR. Now c0=n(α)c_0 = n(\alpha) and c1=(d,0)−n(β)=(d+sβ,−cβ)c_1 = (d, 0) - n(\beta) = (d + s_\beta, -c_\beta). Their difference is D=(d+sα+sβ,−cα−cβ)D = (d + s_\alpha + s_\beta, -c_\alpha - c_\beta) with ∣D∣2=d2+2d(sα+sβ)+2+2cos⁡(α−β)=p2+4|D|^2 = d^2 + 2d(s_\alpha + s_\beta) + 2 + 2\cos(\alpha - \beta) = p^2 + 4. After the left arc of angle t≡γ−αt \equiv \gamma - \alpha, the car is at c0−n(γ)c_0 - n(\gamma). After the straight segment, it is at c0−n(γ)+p u(γ)c_0 - n(\gamma) + p\,u(\gamma). For this point to be c1+n(γ)c_1 + n(\gamma), the point of the right circle where the heading is γ\gamma, we need D=p u(γ)−2n(γ)D = p\,u(\gamma) - 2n(\gamma). The vector p u(γ)−2n(γ)p\,u(\gamma) - 2n(\gamma) has norm p2+4=∣D∣\sqrt{p^2 + 4} = |D| and direction γ+atan2(−2,p)\gamma + \mathrm{atan2}(-2, p). So the choice γ=atan2(Dy,Dx)−atan2(−2,p)\gamma = \mathrm{atan2}(D_y, D_x) - \mathrm{atan2}(-2, p) of the table makes them equal. The right arc of angle q≡γ−βq \equiv \gamma - \beta then ends at c1+n(β)=(d,0)c_1 + n(\beta) = (d, 0) with heading β\beta. RSL is the mirror image of LSR. □\square

Lemma 3 (CCC words end at the goal). If line L5 accepts RLR or LRL, the path from (0,0,α)(0, 0, \alpha) ends at (d,0,β)(d, 0, \beta).

Proof. RLR. A car on a right circle with center cc and heading ψ\psi is at c+n(ψ)c + n(\psi). The right circles at the start and at the goal have centers c0=−n(α)=(sα,−cα)c_0 = -n(\alpha) = (s_\alpha, -c_\alpha) and c1=(d,0)−n(β)=(d+sβ,−cβ)c_1 = (d, 0) - n(\beta) = (d + s_\beta, -c_\beta), so D=c1−c0=(d−sα+sβ,cα−cβ)D = c_1 - c_0 = (d - s_\alpha + s_\beta, c_\alpha - c_\beta) and ∣D∣2=2+d2−2cos⁡(α−β)+2d(sβ−sα)|D|^2 = 2 + d^2 - 2\cos(\alpha - \beta) + 2d(s_\beta - s_\alpha).

Follow the path. The first right arc ends at heading ψ1=α−t\psi_1 = \alpha - t at the point c0+n(ψ1)c_0 + n(\psi_1). The middle left circle has center m=c0+2n(ψ1)m = c_0 + 2n(\psi_1). After the left arc of angle pp, the car has heading ψ1+p\psi_1 + p and is at m−n(ψ1+p)m - n(\psi_1 + p), and the right circle it turns on next has center m−2n(ψ1+p)m - 2n(\psi_1 + p). So the path ends on the goal circle exactly when c1=c0+2n(ψ1)−2n(ψ1+p)c_1 = c_0 + 2n(\psi_1) - 2n(\psi_1 + p). The identity n(a)−n(a+p)=2sin⁡(p/2) u(a+p/2)n(a) - n(a + p) = 2\sin(p/2)\,u(a + p/2) turns this into D=4sin⁡(p/2) u(ψ1+p/2)D = 4\sin(p/2)\,u(\psi_1 + p/2).

Taking norms, ∣D∣2=16sin⁡2(p/2)=8−8cos⁡p|D|^2 = 16\sin^2(p/2) = 8 - 8\cos p, so cos⁡p=(8−∣D∣2)/8=(6−d2+2cos⁡(α−β)+2d(sα−sβ))/8=c\cos p = (8 - |D|^2)/8 = (6 - d^2 + 2\cos(\alpha - \beta) + 2d(s_\alpha - s_\beta))/8 = c. A solution exists exactly when ∣c∣≤1|c| \le 1, the test of line L5, and then p=arccos⁡cp = \arccos c or p=2π−arccos⁡cp = 2\pi - \arccos c; the table takes the second. For p∈(0,2π)p \in (0, 2\pi), sin⁡(p/2)>0\sin(p/2) > 0, so the direction of DD is ψ1+p/2\psi_1 + p/2, and ψ1=atan2(cα−cβ,d−sα+sβ)−p/2\psi_1 = \mathrm{atan2}(c_\alpha - c_\beta, d - s_\alpha + s_\beta) - p/2. This gives t=α−ψ1t = \alpha - \psi_1 as in the table. The heading changes by −t-t, then +p+p, then −q-q, so the end heading is α−t+p−q\alpha - t + p - q, and q=α−β−t+pq = \alpha - \beta - t + p makes it β\beta. The car is then on the right circle with center c1c_1 with heading β\beta, at c1+n(β)=(d,0)c_1 + n(\beta) = (d, 0). LRL is the mirror image of RLR in the xx axis. □\square

Lemma 4 (uniqueness per word). For each CSC word, there is at most one path with arcs in [0,2π)[0, 2\pi) and a straight part of length at least 0. For each CCC word, there is at most one path with arcs in [0,2π)[0, 2\pi) and a middle arc in (π,2π)(\pi, 2\pi).

Proof. The end circles are fixed by the poses and the turn directions. For LSL, the proof of Lemma 2 shows that a path of the word with straight heading γ\gamma must satisfy c1−c0=p u(γ)c_1 - c_0 = p\,u(\gamma) with p≥0p \ge 0. If c1≠c0c_1 \ne c_0, this fixes pp and γ\gamma, and then tt and qq modulo 2π2\pi. If c1=c0c_1 = c_0, then p=0p = 0 and the path is one arc of angle t+qt + q; any split with t+q≥2πt + q \ge 2\pi contains a full loop, and the implementation takes γ=α\gamma = \alpha, so t=0t = 0 and the arc is the shortest one. For LSR, a path must satisfy D=p u(γ)−2n(γ)D = p\,u(\gamma) - 2n(\gamma), which fixes p=∣D∣2−4p = \sqrt{|D|^2 - 4} and then γ\gamma. RSR and RSL are the mirror images. For a CCC word, the proof of Lemma 3 shows that a path of the word must have cos⁡p=c\cos p = c, so p=arccos⁡c≤πp = \arccos c \le \pi or p=2π−arccos⁡c≥πp = 2\pi - \arccos c \ge \pi, and that pp fixes ψ1\psi_1, the middle center and the last arc. Only the second value of pp is in (π,2π)(\pi, 2\pi). □\square

Theorem (Dubins 1957). Between any two poses there is a forward path of curvature at most 1/ρ1/\rho of least length. Every such shortest path is of the form CSC or CCC, where C is an arc of radius ρ\rho of angle in [0,2π)[0, 2\pi) and S a segment, and some pieces can have length 0. In a CCC shortest path, the middle arc has angle greater than π\pi.

This theorem is quoted from Dubins (1957); Boissonnat, Cérézo and Leblond (1994) give a proof with the minimum principle. We do not reprove it.

Theorem (correctness). DUBINS returns a word and lengths whose path ends at q1q_1 and has the least length among all forward paths of curvature at most 1/ρ1/\rho.

Proof. By Lemmas 2 and 3, every word accepted in line L5 gives a path from q0q_0 to q1q_1 of length ℓ\ell, so the returned path is feasible. By Dubins' theorem a shortest path P∗P^* exists and has one of the six words, with arcs in [0,2π)[0, 2\pi), and with a middle arc above π\pi if it is CCC. By Lemma 4 it is the only path of its word with these properties. The closed form of that word exists (its p2≥0p^2 \ge 0 or ∣c∣≤1|c| \le 1, since P∗P^* is a path with this geometry), and by Lemmas 2 and 3 it describes such a path, so it is P∗P^*. So line L5 meets P∗P^*, and line L6 keeps the least length seen, which is at most the length of P∗P^*. As every candidate is feasible, it is at least that length too, so it is equal. Line L7 returns it. A non-empty word set is guaranteed, because P∗P^* exists. □\square

What the tests add. The tests compare the result with an independent construction that finds the common tangents by bisection and both middle circles by intersecting circles, on 150 random pairs, within 10−710^{-7}. They check that no random forward path of up to five segments is shorter, on 3000 cases, and that each of the six words is the answer for some pair.

Complexity

  • Time. Six words, each with a fixed number of operations, so O(1)O(1) in the real RAM. Measured: in the implementation, one call with all six words takes about 15 microseconds in CPython on a laptop. Shkel and Lumelsky give a rule that picks the shortest word from (α,β)(\alpha, \beta) when dd is large, without computing the others; it saves a constant factor.
  • Space. O(1)O(1).
  • Sampling. Drawing the path or checking it against obstacles needs points along it. With a spacing Δs\Delta s, that costs O(ℓ/Δs)O(\ell / \Delta s) for a path of length ℓ\ell, and this is usually the larger cost.

Properties

  • Exact. The result is the true optimum, not an approximation, up to rounding.
  • Not symmetric in the poses. The path from q0q_0 to q1q_1 differs from the path from q1q_1 to q0q_0. Its length equals the length from (x1,y1,θ1+π)(x_1, y_1, \theta_1 + \pi) to (x0,y0,θ0+π)(x_0, y_0, \theta_0 + \pi), because that is the same curve driven in the other direction. The Dubins length is a quasi-metric, not a metric.
  • Not continuous. A small change of the goal can switch the best word and make the path jump. For example, a goal just behind the car needs a loop, and a goal just in front does not. The length is also discontinuous where the goal is very close to the start.
  • Scale. Lengths scale with ρ\rho: the path for ρ\rho and goal (x,y)(x, y) is ρ\rho times the path for radius 1 and goal (x/ρ,y/ρ)(x/\rho, y/\rho).
  • Curvature jumps. The path is C1C^1, with a continuous heading, but its curvature jumps between 00 and ±1/ρ\pm 1/\rho at the joints. A real car cannot steer that fast; see Pitfalls.

Variants and improvements

  • Reeds-Shepp paths. Allow reverse motion; see the Reeds-Shepp path page.
  • Fast word choice. Shkel and Lumelsky (2001) split the (α,β)(\alpha, \beta) square into regions and give the shortest word in each region when dd is large enough. It avoids computing all six words.
  • Dubins paths in planners. Hybrid A* uses Dubins or Reeds-Shepp lengths in an empty map as an admissible heuristic, and a Dubins or Reeds-Shepp path as a last shot to the goal. RRT and RRT* for cars use the Dubins path as the steering function and the Dubins length as the distance; see kinodynamic planning.
  • Curvature-continuous paths. Replace the jumps of curvature by clothoid pieces of bounded curvature rate. The result is no longer the shortest path of the original problem.
  • Three dimensions. The Dubins airplane adds an altitude with a bounded climb rate. It is a different problem with more cases.

When to use it

Use it as the local path of a car-like robot that cannot or should not reverse: fixed-wing aircraft at constant altitude, boats, cars on a road. Use it as a lower bound on the length of any forward path between two poses, for example as the heuristic of a search. Do not use it as a trajectory to track without smoothing, because the curvature jumps. If the robot can reverse, the Reeds-Shepp path is shorter and also costs constant time.

Pitfalls

  • Rounding near zero segments. When a straight part has length 0 (the two circles touch, or are the same circle), pp is the square root of a rounded p2p^2 near 0. A rounding error of 10−1610^{-16} in p2p^2 gives p≈10−8p \approx 10^{-8}, and an angle that should be 0 can come out just below 2π2\pi, which adds a full loop. The implementation clamps small negative p2p^2 to 0, snaps angles within 10−1010^{-10} of 2π2\pi to 0, and treats two equal circles as a single arc.
  • The direction of the angles. mod2π\mathrm{mod}_{2\pi} must return a value in [0,2π)[0, 2\pi). Python's math.fmod returns a negative value for a negative input, and the C fmod does too.
  • CCC middle arc. Of the two middle circles that touch both end circles, only the one with a middle arc longer than π\pi can be optimal. The formula p=2π−arccos⁡cp = 2\pi - \arccos c picks it. Taking arccos⁡c\arccos c instead gives a valid but longer path.
  • Not every word exists. CCC words need d<4d < 4 after scaling. Code that does not test the conditions takes the square root of a negative number.
  • Ties. LSR and RSL, or RLR and LRL, can tie, as in the U-turn above. Then the word chosen depends on the order of the loop.
  • Radius and steering. For a car, ρ=L/tan⁡δmax\rho = L/\tan\delta_{max} holds for the rear axle in the kinematic bicycle model. Tire slip makes the true radius larger at speed.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

dubins_path.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dubins-path/. The authors are listed in prov/4DQ75R.jsonl.

"""Shortest path of a forward-only car with a minimum turning radius rho (Dubins 1957).

A pose is (x, y, theta) in meters and radians. The car moves forward, and its curvature
is at most 1 / rho. Dubins proved that a shortest path is one of six words: LSL, RSR,
LSR, RSL, RLR, LRL, where L is a left arc of radius rho, R a right arc of radius rho and
S a straight segment. Some segments can have length zero.

The algorithm puts the start at the origin of a frame whose x axis points to the goal,
scales lengths by 1 / rho, computes the three segment lengths (t, p, q) of each word in
closed form (Shkel and Lumelsky 2001; LaValle 2006, Section 15.3.1), and keeps the
shortest word.
"""

import math

TWO_PI = 2.0 * math.pi
EPS = 1e-10
WORDS = ("LSL", "RSR", "LSR", "RSL", "RLR", "LRL")


def mod2pi(a):
    """Angle in [0, 2 pi). A value within EPS below 2 pi is rounding noise of 0."""
    r = math.fmod(a, TWO_PI)
    if r < 0.0:
        r += TWO_PI
    if r > TWO_PI - EPS:
        r = 0.0
    return r


def wrap(a):
    """Angle in [-pi, pi)."""
    return (a + math.pi) % TWO_PI - math.pi


def word_lengths(word, d, alpha, beta):
    """Normalized segment lengths (t, p, q) of one word, or None if the word does not exist.

    d is the distance between the positions divided by rho. alpha and beta are the start
    and goal headings, measured from the direction of the line from start to goal.
    """
    sa, ca, sb, cb = math.sin(alpha), math.cos(alpha), math.sin(beta), math.cos(beta)
    c_ab = math.cos(alpha - beta)
    if word in ("LSL", "RSR"):
        sign = 1.0 if word == "LSL" else -1.0
        p2 = 2.0 + d * d - 2.0 * c_ab + 2.0 * d * sign * (sa - sb)
        if p2 < -EPS:
            return None
        p = math.sqrt(max(p2, 0.0))
        vx, vy = (d + sa - sb, cb - ca) if word == "LSL" else (d - sa + sb, ca - cb)
        # (vx, vy) joins the two circle centers and has length p. When the two circles are
        # the same, its direction is rounding noise, and the path is a single arc.
        g = math.atan2(vy, vx) if math.hypot(vx, vy) > EPS else alpha
        if word == "LSL":
            return mod2pi(g - alpha), p, mod2pi(beta - g)
        return mod2pi(alpha - g), p, mod2pi(g - beta)
    if word == "LSR":
        p2 = -2.0 + d * d + 2.0 * c_ab + 2.0 * d * (sa + sb)
        if p2 < -EPS:
            return None
        p = math.sqrt(max(p2, 0.0))
        g = math.atan2(-ca - cb, d + sa + sb) - math.atan2(-2.0, p)
        return mod2pi(g - alpha), p, mod2pi(g - beta)
    if word == "RSL":
        p2 = -2.0 + d * d + 2.0 * c_ab - 2.0 * d * (sa + sb)
        if p2 < -EPS:
            return None
        p = math.sqrt(max(p2, 0.0))
        g = math.atan2(ca + cb, d - sa - sb) - math.atan2(2.0, p)
        return mod2pi(alpha - g), p, mod2pi(beta - g)
    if word in ("RLR", "LRL"):
        if word == "RLR":
            c = (6.0 - d * d + 2.0 * c_ab + 2.0 * d * (sa - sb)) / 8.0
        else:
            c = (6.0 - d * d + 2.0 * c_ab + 2.0 * d * (sb - sa)) / 8.0
        if abs(c) > 1.0 + EPS:
            return None
        p = TWO_PI - math.acos(max(-1.0, min(1.0, c)))
        if word == "RLR":
            t = mod2pi(alpha - math.atan2(ca - cb, d - sa + sb) + p / 2.0)
            return t, p, mod2pi(alpha - beta - t + p)
        t = mod2pi(-alpha - math.atan2(ca - cb, d + sa - sb) + p / 2.0)
        return t, p, mod2pi(beta - alpha - t + p)
    raise ValueError(word)


def dubins_candidates(q0, q1, rho):
    """Every word that exists, as (length, word, (l1, l2, l3)) with lengths in meters."""
    dx, dy = q1[0] - q0[0], q1[1] - q0[1]  # @line L1
    d = math.hypot(dx, dy) / rho  # @line L1
    phi = math.atan2(dy, dx) if d > 0.0 else 0.0  # @line L1
    alpha, beta = mod2pi(q0[2] - phi), mod2pi(q1[2] - phi)  # @line L2
    out = []
    for w in WORDS:  # @line L4
        tpq = word_lengths(w, d, alpha, beta)  # @line L5
        if tpq is not None:  # @line L5
            seg = tuple(rho * s for s in tpq)  # @line L5
            out.append((sum(seg), w, seg))  # @line L5
    return out


def dubins_path(q0, q1, rho):
    """Shortest Dubins path: (length, word, (l1, l2, l3)) with segment lengths in meters."""
    best = None  # @line L3
    for cand in dubins_candidates(q0, q1, rho):  # @line L4
        if best is None or cand[0] < best[0]:  # @line L6
            best = cand  # @line L6
    return best  # @line L7


def step(q, kind, s, rho):
    """Exact pose after a signed arc length s on one segment (kind is 'L', 'R' or 'S')."""
    x, y, th = q
    if kind == "S":
        return x + s * math.cos(th), y + s * math.sin(th), th
    if kind == "L":
        nth = th + s / rho
        return x + rho * (math.sin(nth) - math.sin(th)), y - rho * (math.cos(nth) - math.cos(th)), nth
    if kind == "R":
        nth = th - s / rho
        return x - rho * (math.sin(nth) - math.sin(th)), y + rho * (math.cos(nth) - math.cos(th)), nth
    raise ValueError(kind)


def endpoint(q0, word, lengths, rho):
    """Pose at the end of a path given by its word and segment lengths, heading in [-pi, pi)."""
    q = q0
    for kind, s in zip(word, lengths):
        q = step(q, kind, s, rho)
    return q[0], q[1], wrap(q[2])


def sample(q0, word, lengths, rho, ds):
    """Poses along the path, at most ds apart in arc length, for drawing or collision checks."""
    pts = [q0]
    q = q0
    for kind, s in zip(word, lengths):
        n = max(1, int(math.ceil(abs(s) / ds)))
        for i in range(1, n + 1):
            pts.append(step(q, kind, s * i / n, rho))
        q = pts[-1]
    return pts
test_dubins_path.py 200 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/dubins-path/. The authors are listed in prov/4DQ75R.jsonl.

import math
import random

from dubins_path import WORDS, dubins_candidates, dubins_path, endpoint, sample, step, wrap

TWO_PI = 2.0 * math.pi


def pose_error(a, b):
    return max(abs(a[0] - b[0]), abs(a[1] - b[1]), abs(wrap(a[2] - b[2])))


def random_pose(rng, size=5.0):
    return (rng.uniform(-size, size), rng.uniform(-size, size), rng.uniform(-math.pi, math.pi))


# An independent solver: build the turning circles and find the tangent lines and the
# middle circles numerically, without the closed forms of the module.

def arc(theta_from, theta_to, kind):
    a = (theta_to - theta_from) % TWO_PI if kind == "L" else (theta_from - theta_to) % TWO_PI
    return 0.0 if a > TWO_PI - 1e-7 else a


def center(q, kind, rho):
    x, y, th = q
    if kind == "L":
        return x - rho * math.sin(th), y + rho * math.cos(th)
    return x + rho * math.sin(th), y - rho * math.cos(th)


def point_on(c, kind, psi, rho):
    """Point of the circle with center c where a car turning in direction kind has heading psi."""
    if kind == "L":
        return c[0] + rho * math.sin(psi), c[1] - rho * math.cos(psi)
    return c[0] - rho * math.sin(psi), c[1] + rho * math.cos(psi)


def heading_at(c, kind, p):
    ang = math.atan2(p[1] - c[1], p[0] - c[0])
    return ang + math.pi / 2.0 if kind == "L" else ang - math.pi / 2.0


def geometric_csc(q0, q1, rho, a, b):
    ca, cb = center(q0, a, rho), center(q1, b, rho)

    def f(psi):
        pa, pb = point_on(ca, a, psi, rho), point_on(cb, b, psi, rho)
        return math.cos(psi) * (pb[1] - pa[1]) - math.sin(psi) * (pb[0] - pa[0])

    best = math.inf
    n = 720
    grid = [(-math.pi + TWO_PI * i / n) for i in range(n + 1)]
    vals = [f(p) for p in grid]
    for i in range(n):
        lo, hi, flo = grid[i], grid[i + 1], vals[i]
        if flo == 0.0:
            hi = lo
        elif flo * vals[i + 1] > 0.0:
            continue
        for _ in range(80):
            if hi - lo < 1e-15:
                break
            mid = 0.5 * (lo + hi)
            fm = f(mid)
            if (fm < 0.0) == (flo < 0.0):
                lo, flo = mid, fm
            else:
                hi = mid
        psi = 0.5 * (lo + hi)
        pa, pb = point_on(ca, a, psi, rho), point_on(cb, b, psi, rho)
        s = math.cos(psi) * (pb[0] - pa[0]) + math.sin(psi) * (pb[1] - pa[1])
        if s < -1e-9:
            continue
        total = rho * arc(q0[2], psi, a) + max(s, 0.0) + rho * arc(psi, q1[2], b)
        best = min(best, total)
    return best


def geometric_ccc(q0, q1, rho, a):
    m = "R" if a == "L" else "L"
    c0, c1 = center(q0, a, rho), center(q1, a, rho)
    dx, dy = c1[0] - c0[0], c1[1] - c0[1]
    dist = math.hypot(dx, dy)
    if dist > 4.0 * rho or dist < 1e-12:
        return math.inf
    h = math.sqrt(max(4.0 * rho * rho - dist * dist / 4.0, 0.0))
    mx, my = c0[0] + dx / 2.0, c0[1] + dy / 2.0
    best = math.inf
    for sgn in (1.0, -1.0):
        cm = (mx - sgn * h * dy / dist, my + sgn * h * dx / dist)
        t1 = ((c0[0] + cm[0]) / 2.0, (c0[1] + cm[1]) / 2.0)
        t2 = ((c1[0] + cm[0]) / 2.0, (c1[1] + cm[1]) / 2.0)
        psi1, psi2 = heading_at(c0, a, t1), heading_at(c1, a, t2)
        mid = (psi2 - psi1) % TWO_PI if m == "L" else (psi1 - psi2) % TWO_PI
        total = rho * (arc(q0[2], psi1, a) + mid + arc(psi2, q1[2], a))
        best = min(best, total)
    return best


def geometric_min(q0, q1, rho):
    best = math.inf
    for a in "LR":
        for b in "LR":
            best = min(best, geometric_csc(q0, q1, rho, a, b))
        best = min(best, geometric_ccc(q0, q1, rho, a))
    return best


def test_every_candidate_ends_at_the_goal():
    rng = random.Random(11)
    for _ in range(2000):
        q0, q1 = random_pose(rng), random_pose(rng)
        rho = rng.uniform(0.3, 2.0)
        cands = dubins_candidates(q0, q1, rho)
        assert len(cands) >= 4
        for length, word, seg in cands:
            assert min(seg) >= 0.0
            assert abs(length - sum(seg)) < 1e-12
            assert pose_error(endpoint(q0, word, seg, rho), q1) < 1e-9


def test_matches_independent_geometric_construction():
    rng = random.Random(12)
    for _ in range(150):
        q0, q1 = random_pose(rng, 3.0), random_pose(rng, 3.0)
        rho = rng.uniform(0.5, 1.5)
        length = dubins_path(q0, q1, rho)[0]
        assert abs(length - geometric_min(q0, q1, rho)) < 1e-7


def random_forward_path(rng, rho):
    word = "".join(rng.choice("LSR") for _ in range(rng.randint(1, 5)))
    seg = []
    for k in word:
        seg.append(rng.uniform(0.0, 4.0) if k == "S" else rho * rng.uniform(0.0, TWO_PI))
    return word, seg


def test_no_forward_path_is_shorter():
    rng = random.Random(13)
    for _ in range(3000):
        rho = rng.uniform(0.5, 1.5)
        q0 = random_pose(rng)
        word, seg = random_forward_path(rng, rho)
        q1 = endpoint(q0, word, seg, rho)
        # When a straight part has length 0, p is the square root of a rounded p^2 near 0,
        # so p can come out near 1e-8 instead of 0. That is the tolerance here.
        assert dubins_path(q0, q1, rho)[0] <= sum(seg) + 1e-7


def test_every_word_is_optimal_somewhere():
    rng = random.Random(14)
    seen = set()
    for _ in range(3000):
        q0, q1 = random_pose(rng, 2.0), random_pose(rng, 2.0)
        seen.add(dubins_path(q0, q1, 1.0)[1])
    assert seen == set(WORDS)


def test_hand_cases():
    # A straight line: length 4 m.
    length, word, seg = dubins_path((0.0, 0.0, 0.0), (4.0, 0.0, 0.0), 1.0)
    assert abs(length - 4.0) < 1e-12 and word in ("LSL", "RSR")
    # A quarter of a left circle of radius 1 m.
    length, word, seg = dubins_path((0.0, 0.0, 0.0), (1.0, 1.0, math.pi / 2.0), 1.0)
    assert abs(length - math.pi / 2.0) < 1e-9
    # A U-turn in place needs a CCC path of length 7 pi / 3 (radius 1 m).
    length, word, seg = dubins_path((0.0, 0.0, 0.0), (0.0, 0.0, -math.pi), 1.0)
    assert abs(length - 7.0 * math.pi / 3.0) < 1e-9 and word in ("RLR", "LRL")
    # Scaling: lengths scale with rho.
    a = dubins_path((0.0, 0.0, 0.3), (2.0, 1.0, -1.0), 1.0)[0]
    b = dubins_path((0.0, 0.0, 0.3), (6.0, 3.0, -1.0), 3.0)[0]
    assert abs(3.0 * a - b) < 1e-9


def test_symmetries():
    rng = random.Random(15)
    for _ in range(500):
        q0, q1 = random_pose(rng), random_pose(rng)
        length, word, seg = dubins_path(q0, q1, 1.0)
        # Mirror in the x axis swaps L and R.
        m = dubins_path((q0[0], -q0[1], -q0[2]), (q1[0], -q1[1], -q1[2]), 1.0)
        assert abs(m[0] - length) < 1e-9
        # Driving the path backward in time is a forward path from the reversed goal.
        r = dubins_path((q1[0], q1[1], q1[2] + math.pi), (q0[0], q0[1], q0[2] + math.pi), 1.0)
        assert abs(r[0] - length) < 1e-9


def test_samples_are_close_and_on_the_path():
    q0, q1 = (0.0, 0.0, 0.0), (3.0, -2.0, 2.0)
    length, word, seg = dubins_path(q0, q1, 1.0)
    pts = sample(q0, word, seg, 1.0, 0.05)
    assert pose_error(pts[-1], q1) < 1e-9
    for p, q in zip(pts, pts[1:]):
        assert math.hypot(q[0] - p[0], q[1] - p[1]) <= 0.05 + 1e-12
    assert pose_error(step(q0, "S", 0.0, 1.0), q0) == 0.0

History

Dubins (1957) proved the existence of shortest curves with an upper bound on average curvature, and showed that they are of type CSC or CCC, or parts of these. His proof is geometric. Reeds and Shepp (1990) solved the problem with reverse motion. Sussmann and Tang (1991) and Boissonnat, Cérézo and Leblond (1994) gave proofs of both results with the Pontryagin maximum principle. Shkel and Lumelsky (2001) gave the closed forms used here and the rule that picks the shortest word. LaValle's book of 2006 made the Dubins car a standard example of a nonholonomic system in motion planning.

References

  1. Lester E. Dubins, On curves of minimal length with a constraint on average curvature, and with prescribed initial and terminal positions and tangents, American Journal of Mathematics 79(3), 1957, pages 497 to 516 (the main theorem, the CSC and CCC types, and the middle arc of a CCC path longer than pi times the radius)
  2. Andrei M. Shkel and Vladimir J. Lumelsky, Classification of the Dubins set, Robotics and Autonomous Systems 34(4), 2001, pages 179 to 202 (closed forms of the six words after the change of frame, and a rule that picks the shortest word without computing all of them when the poses are far apart)
  3. Steven M. LaValle, Planning Algorithms, Cambridge University Press, 2006, Section 15.3.1 (Dubins curves, the six words and the Dubins car as a control system)
  4. James A. Reeds and Lawrence A. Shepp, Optimal paths for a car that goes both forwards and backwards, Pacific Journal of Mathematics 145(2), 1990, pages 367 to 393 (the extension with reverse motion, see the Reeds-Shepp path page)
  5. Jean-Daniel Boissonnat, André Cérézo and Juliette Leblond, Shortest paths of bounded curvature in the plane, Journal of Intelligent and Robotic Systems 11, 1994, pages 5 to 20 (a proof of the results of Dubins and of Reeds and Shepp with the Pontryagin minimum principle)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example