# Bézier curves and splines # Bézier curves and splines

B

I’m not going to go over the mathemathics of what a Bézier curve is, there’s plenty of resources explaining that online including a lengthgy Wikipedia page that can be found here. Main thing you need to know is that there’s multiple types of Bézier curves, differentiated by the equations that give them.

For our needs we will use the Cubic Bézier curve, connecting them end to start to form a spline which we will later use as our road’s path.

#### The cubic curve

The cubic curve requires two anchors and two control points to define. Let’s call the anchor points Start and End and the control points SC (StartControl) and EC (EndControl). The positions of these points relative to one another define the curve’s path.
Moving the control points will result in a different curve between the same two anchor points. This exactly what we want, we need to be able to change the curve between the points without moving the anchors at all.
Now that we’ve been over what a single curve looks like let’s take a look at a spline.

#### Making a spline

For my purposes I only need open splines (no loops) and as such I won’t cover how to deal with closed splines but this content should put you in a better position to approach that issue if you wish to.

Besed on the image above a few things should become apparent:
First, S2 = E1. The end of the previous curve has to be the start of the current one to generate a continous spline.
Second, the start control of the current curve needs to be on the same line as the end control of the previous one and the start anchor. Failing to do this would result in a break in the curve at point S2.
Third, the distance between the current curve’s start control and the start anchor and the distance between the previous curve’s end control and end anchor needs to be the same. Not doing this means that the curve wouldn’t be centered on the anchor point and in extreme situations (control points very close to anchor) the spline will look broken.
Fourth, the distance between the control point and its related anchor point gives the “radius” of the curve around that point.
So let’s rename everything to make it easier.