Computing Clothoid Curves in five lines of Python

Alejandro Blumentals
2 min readOct 20, 2019
Photo by John Lockwood on Unsplash

Clothoids are commonly used geometric primitives in road design. Anybody working with HD Maps for Autonomous Driving, for example, will come across these curves and face the problem of how to evaluate them. Unlike circular arcs or polynomial splines, they don’t have a simple-to-write-down closed form solution. The method suggested by OpenDrive, for example, involves over 200 lines of code, Fresnel integrals and way too many ifs. In this post I’ll go over how to evaluate clothoids in five lines of python.

A clothoid is the generalization of a circular arc, instead of having constant curvature it has a linear curvature profile. This of course comes in handy in road design as then several road pieces can be joined together without any curvature discontinuities, in contrast to joining straight lines and circular arcs, which would result in very uncomfortable driving.

To evaluate a clothoid we basically need to figure out what the shape of the curve is given only its inital conditions and the curvature profile. To do so we need to solve the differential equation given below, called the “reconstruction equation”.

To numerically solve the reconstruction equation we can make use of scipy’s odeint method, leading to a very lean implementation.

We can then make use of the eval_clothoid method to solve for a clothoid and plot the solution as follows.

That’s it, that’s all there is to it. Computing a clothoid curve may not be as straight forward as computing splines or circular arcs but as we’ve seen the code is still pretty simple. Just don’t be afraid of differential equations and you’ve got it.

--

--