- Home /

# Controlling the curvature of a Bézier curve

Hey guys,

I've been working on a curve generator for my game. I'm using it to plot a course for a ship.

First a little background; our ships have a maximum rotation of x and can move a maximum range of y per turn. They apply this range and rotation over a number of time segments, using either, neither or both types of transformation in each time segment.

While they can turn on their centre, it is optimal if they move and rotate at the same time where ever possible, however moving and rotating enforces a turning circle. With that in mind, I would like to control the curvature of my Bézier curve in order to find the optimal route from A to B while maintaining a specfic heading at both the start and end of the route.

I realised that the vector between the first point and the second point represents the starting heading and that the vector between the penultimate point and the last point control the end heading. I've also noticed that the distance between P0/P1 and P2/P3 controls the curvature (the closer the distance, the tighter the turn).

Taking into account all of the above, I have created a generator which creates a path between two points forcing a specified start and end heading and which (by use of colour) tells me if the curvature is to steep for a particular ship's turn ratio.

*In this case, both the start and end heading are 315 (or -45).*

I've been experimenting with changing the curve by adding in extra control points in between P1 and p2. This allows me to manually widen the curve reducing the tightness of the turn but I need to find some formula/algorithm for placing these extra control points which allows these curves be loosened/tightened automatically.

I was hoping someone could point me in the direction of some maths that might help?

Thanks in advance.

**Answer** by telcom_un
·
Jul 24, 2014 at 08:11 AM

In general it is not an easy task to control the curvature of a Bezier curve. If you look into the Bezier curvature formula you get, `k(t) = (px_d py_dd - py_d px_dd)/(px_d^2 + py_d^2)3/2.`

As you see you need second derivative to control the curvature. It means without acceleration constrains you don't have meaningful control over the curvature. So at least 4th order Bezier is necessary for your task. I don't know any a-z approach to give you Bezier though. If you got it by now please share it with me.

**Answer** by CHPedersen
·
Jul 24, 2014 at 08:22 AM

As telcom_un mentioned, Bezier curves at their simplest aren't the easiest to control. But thankfully, you're in an area of math which has a very rich toolkit of other curve functions you can use which might make it easier for you to control the curve. :)

Bezier curves are actually just a special case of the more general "Non-Uniform Rational Basis Spline", or NURBS curves for short. NURBS curves allow you to specify weights for the control points which, in layman's terms, behaves like gravity in that they pull the curve further towards them the higher the weight. If a point's weight is infinite, the curve passes through that point, regardless of where it is.

There is also another type of curve function called "Cubic Hermite Splines", which has a variant known as "Catmull-Rom Splines". These curves naturally pass through all the control points, and bend nicely in between.

Catmull-Rom splines is what Eric5h5 implemented for his Vectrosity Library, which can draw this type of curve in Unity, and which I've used extensively. :)

(Don't take that last part as an ad, I don't work for Eric or am affiliated with him in any way, I just like his library and can recommend it.)

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Distribute terrain in zones 3 Answers

How to get lateral normals of a bezier curve 1 Answer

Subdivide Bezier Curves 3 Answers

Multiple Cars not working 1 Answer

An OS design issue: File types associated with their appropriate programs 1 Answer