[Math] What does the 2nd degree derivative of a cubic Bezier curve actually represent

3dbezier-curvederivativesorientation

I have a $3D$ Bezier curve. Each co-ordinate along its path is defined by the equation:
$$
f(t) = t^3 \bigl(a_2+3(c_1-c_2)-a_1\bigr) + 3t^2 (a_1-2c_1+c_2) + 3t(c_1-a_1) + a_1
$$
where $a_1, a_2$ are the anchor points and $c_1, c_2$ the control points (a.k.a. tangents at $a_1,a_2$).

I want a $3D$ car model to move along this path. In order to orient the car, I use the 1st degree derivative which happens to be the curve's tangent (a.k.a. the function for the curve's direction) :
$$
f'(t) = 3t^2 \bigl(a_2+3(c_1-c_2)-a_1\bigr) + 6t(a_1-2c_1+c_2) + 3(c_1-a_1)
$$
I orient the car using this function's output as direction – considering (0,1,0) as the "up" vector. It works a treat.

Now, I wanted to make the car's front wheels turn left & right according to the car turning left & right. I thought I should use the 2nd degree derivative and use its output to orient the wheels.

$$
f''(t) = 6t \bigl(a_2+3(c_1-c_2)-a_1\bigr) + 6(a_1-2c_1+c_2)
$$

It turns out to be a nightmare, thus my concept must be wrong.

My biggest query is that $f''(t)$ is non-zero even when the Bezier is degenerated to a straight line (all 4 points belonging to a straight line)! Since, in the case of a straight line, the direction $f'(t)$ is constant, shouldn't its derivative be always zero?

For example, for $a_1,a_2,c_1,c_2$ respectively:

Vector3D(-4.01,0.00,-1.90) Vector3D(4.01,0.00,-1.90)
Vector3D(-2.01,0.00,-1.90) Vector3D(2.01,0.00,-1.90)

I get a constant $f'(t)$ and a variable $f''(t)$ !!

f'(0.08)=Vector3D(-1.00,0.00,0.00) f''(0.08)=Vector3D(10.14,0.00,0.00)
f'(0.11)=Vector3D(-1.00,0.00,0.00) f''(0.11)=Vector3D(9.42,0.00,0.00)
f'(0.15)=Vector3D(-1.00,0.00,0.00) f''(0.15)=Vector3D(8.44,0.00,0.00)
f'(0.18)=Vector3D(-1.00,0.00,0.00) f''(0.18)=Vector3D(7.69,0.00,0.00)
f'(0.21)=Vector3D(-1.00,0.00,0.00) f''(0.21)=Vector3D(6.87,0.00,0.00)
f'(0.24)=Vector3D(-1.00,0.00,0.00) f''(0.24)=Vector3D(6.16,0.00,0.00)
f'(0.27)=Vector3D(-1.00,0.00,0.00) f''(0.27)=Vector3D(5.47,0.00,0.00)
f'(0.30)=Vector3D(-1.00,0.00,0.00) f''(0.30)=Vector3D(4.70,0.00,0.00)
f'(0.33)=Vector3D(-1.00,0.00,0.00) f''(0.33)=Vector3D(4.03,0.00,0.00)
f'(0.36)=Vector3D(-1.00,0.00,0.00) f''(0.36)=Vector3D(3.37,0.00,0.00)
f'(0.39)=Vector3D(-1.00,0.00,0.00) f''(0.39)=Vector3D(2.63,0.00,0.00)
f'(0.42)=Vector3D(-1.00,0.00,0.00) f''(0.42)=Vector3D(1.99,0.00,0.00)
f'(0.44)=Vector3D(-1.00,0.00,0.00) f''(0.44)=Vector3D(1.34,0.00,0.00)
f'(0.47)=Vector3D(-1.00,0.00,0.00) f''(0.47)=Vector3D(0.62,0.00,0.00)
f'(0.50)=Vector3D(-1.00,0.00,0.00) f''(0.50)=Vector3D(-0.02,0.00,0.00)
f'(0.53)=Vector3D(-1.00,0.00,0.00) f''(0.53)=Vector3D(-0.74,0.00,0.00)
f'(0.56)=Vector3D(-1.00,0.00,0.00) f''(0.56)=Vector3D(-1.38,0.00,0.00)
f'(0.58)=Vector3D(-1.00,0.00,0.00) f''(0.58)=Vector3D(-2.03,0.00,0.00)
f'(0.61)=Vector3D(-1.00,0.00,0.00) f''(0.61)=Vector3D(-2.67,0.00,0.00)
f'(0.64)=Vector3D(-1.00,0.00,0.00) f''(0.64)=Vector3D(-3.41,0.00,0.00)
f'(0.67)=Vector3D(-1.00,0.00,0.00) f''(0.67)=Vector3D(-4.07,0.00,0.00)
f'(0.70)=Vector3D(-1.00,0.00,0.00) f''(0.70)=Vector3D(-4.74,0.00,0.00)
f'(0.73)=Vector3D(-1.00,0.00,0.00) f''(0.73)=Vector3D(-5.51,0.00,0.00)
f'(0.76)=Vector3D(-1.00,0.00,0.00) f''(0.76)=Vector3D(-6.20,0.00,0.00)
f'(0.79)=Vector3D(-1.00,0.00,0.00) f''(0.79)=Vector3D(-6.91,0.00,0.00)
f'(0.82)=Vector3D(-1.00,0.00,0.00) f''(0.82)=Vector3D(-7.74,0.00,0.00)
f'(0.85)=Vector3D(-1.00,0.00,0.00) f''(0.85)=Vector3D(-8.49,0.00,0.00)
f'(0.89)=Vector3D(-1.00,0.00,0.00) f''(0.89)=Vector3D(-9.27,0.00,0.00)
f'(0.92)=Vector3D(-1.00,0.00,0.00) f''(0.92)=Vector3D(-10.19,0.00,0.00)
f'(0.96)=Vector3D(-1.00,0.00,0.00) f''(0.96)=Vector3D(-11.06,0.00,0.00)
f'(1.00)=Vector3D(-1.00,0.00,0.00) f''(1.00)=Vector3D(-11.98,0.00,0.00)

EDIT: Questions:

1) What does the 2nd degree derivative of a cubic Bezier curve actually represent? (found in the title)

2) How can the 2nd degree derivative be variable when the 1st degree derivative is constant?

OPTIONAL: 3) If my concept to use $f''(t)$ to orient the wheels is wrong, what is the theoretically correct way to orient them?

EDIT 2 : The curve function and 1st derivative work a treat:
enter image description here

Best Answer

Short version

you need to use the first derivative for aligning your wheels, not the second derivative.

Long version

If your curve represents position, then the derivative (geometrically, the curve's tangent) represents speed, the second derivative (geometrically, the curve's change in tangent) represents acceleration, and the third derivative (if it exists), represents jerk (i.e. the change in acceleration from moment to moment).

For a cubic curve as positional path, the velocity is a quadratic function for each dimension, and the acceleration a straight line for each dimension (With the third derivative being a scalar for each dimension. It exists, but is constant).

With your straight line coordinates, I get the following path:

cubic path

This has a velocity vector along the curve of

$\{6. (1 - t)^2 + 24.12 (1 - t) t + 6. t^2 , 0 , 0\}$

which maps to:

velocity curve

So there should be no sign changing along your curve.

The second derivative matches what you're showing:

the second derivative

but should be irrelevant when it comes to aligning your wheels to the curve, you'd use the first derivative for that. (or, you align the wheel axles to the curve normals).

Start with your wheels: your rear wheels don't turn, and the front wheels are some length L away from the rear wheels, along the tangent at the rear wheels. Your front wheels, then, turned so that they compensate for the curvature of your path. If you want to do this true to life, things get complicated, but if you just want things to "look good" we can use a simple model: orient the front along the tangent of the curve at the point where your front axle intersects it (and note that the front wheels may not even be on the curve, due to where the rear wheels dictate they need to exist!). As illustration:

enter image description here

So the body of the car is orientated along the tangent at the rear wheels, since they're fixed, and as your car drives along the path, you update the front wheels to reflect the curvature of the the path "up ahead". Note that this will cause hilarious problems when the curvature is very strong (for instance, a curvature radius that is smaller than the length of the car, as is illustrated here, will look fine as we go into the curve, but as the curvature increases in strength, the wheels should "lock" and ideally your simulation forces a path replot due to understeer), but the choice of whether to make use of those is mostly up to you.

Related Question