How to make Dubins Paths in Unity with C# code

1. Introduction

In this tutorial you will learn how to make Dubins paths in Unity with C# code. This is how Wikipedia defines Dubins paths:

In geometry, the term Dubins path typically refers to the shortest curve that connects two points in the two-dimensional Euclidean plane (i.e. x-y plane) with a constraint on the curvature of the path and with prescribed initial and terminal tangents to the path, and an assumption that the vehicle traveling the path can only travel forward. If the vehicle can also travel in reverse, then the path follows the Reeds-Shepp curve.

But why would anyone need a Dubins path? One application is self-driving cars. I've made a self-driving car in Unity and I used Dubins paths to improve the pathfinding algorithm Hybrid A*. The problem with Hybrid A* is that Hybrid A* doesn't care about the final orientation of the car, which is what Dubins paths care about. This is how it looks like:

Self driving car using Dubins paths

The white line is the shortest Dubins path and the gray line is a modified Dubins path because it can also reverse. As the Wikipedia article said, you can modify the Dubins paths and you will end up with the so-called Reeds–Shepp curves. But we will here focus on the original Dubins paths, which can only drive forward.