3
$\begingroup$

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

$\endgroup$
  • $\begingroup$ I get different values for the derivatives than you.Can you please confirm these values: $$a1 = (-4.01, 0.00, -1.90), a2 = (4.01, 0.00, -1.90), \\ c1 = (-2.01, 0.00, -1.90), c2 = (2.01, 0.00, -1.90)$$ $\endgroup$ – mvw Apr 24 '15 at 22:03
  • $\begingroup$ Note to future readers: mvw is right. The direction is NOT (-1,0,0). This is its NORMALIZED value I was getting back (don't ask). The correct values are mvw's. $\endgroup$ – Bill Kotsias May 28 '15 at 15:19
4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Hmm, I use the 1st degree derivative to align the whole car body, and it seems to look right. If I use it for the wheels too, then the wheels will never turn as they will always be parallel to the car body. Maybe I need another function to align the body? $\endgroup$ – Bill Kotsias Apr 24 '15 at 18:25
  • $\begingroup$ You put the car on a straight line. Why should it turn wheels? $\endgroup$ – mvw Apr 24 '15 at 18:33
  • $\begingroup$ I used an extreme example to note that f''(t) shouldn't be used for the wheels rotation. As in the image I uploaded, I want the car to move along any Bezier path and the wheels turn "realistically" according to the car's body turning... $\endgroup$ – Bill Kotsias Apr 24 '15 at 18:36
  • $\begingroup$ @BillKotsias don't align the body. Start with your wheels: your rear wheels don't turn, and so the front wheels are length L away from the rear wheels, along the tangent at the rear wheels. Your front wheels, then, are turned so that they're oriented along the tangent of the curve at the point where your front axle intersects the curve (and note that the front wheels may not even be on the curve, due to where the rear wheels dictate they need to exist!). The body's orientation is along the tangent at the rear wheels, since they're fixed. $\endgroup$ – Mike 'Pomax' Kamermans Apr 24 '15 at 18:45
  • $\begingroup$ @Mike'Pomax'Kamermans Aha, so the body's orientation IS the 1st derivative ("along the tangent at the rear wheels" - since the rear wheels' axle is also ON the curve). BUT you say the front wheels are "oriented along the tangent of the curve at the point where your front axle intersects the curve". Whoa, I need to visualize this to grasp it! AFAIU I need to find the intersection point on the curve with the front wheels' axle the get the value of the 1st derivative of the curve at THAT point, right?! $\endgroup$ – Bill Kotsias Apr 24 '15 at 18:56
1
$\begingroup$

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

$\dot{r}(t)$ and $\ddot{r}(t)$ are the changes of the curve $r(t)$ regarding the curve parameter $t$.

$t$ here is a parameter, not necessarily the time which you would have in a physical model, nor the geometrical interesting parameter of curve lenght $s$.

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

The curve is $$ r(t) = t^3 (a_2+3(c_1-c_2)-a_1) + 3t^2 (a_1-2c_1+c_2) + 3t(c_1-a_1) + a_1 \\ $$ and its first two derivatives \begin{align} \dot{r}(t) &= 3t^2 (a_2+3(c_1-c_2)-a_1) + 6t (a_1-2c_1+c_2) + 3(c_1-a_1)\\ \ddot{r}(t) &= 6t (a_2+3(c_1-c_2)-a_1) + 6 (a_1-2c_1+c_2) \end{align} While $\dot{r}$ might be constant for the particular values of the $a_i$ and $c_i$, it is clearly not a constant function for all possible values of the $a_i$ and $c_i$. So we can not expect $\ddot r$ to vanish in general.

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

Second derivative $\ddot{r}$ is good, but not enough.

curvature

(Source)

Assume you are on a circular track. Then your tangential vector $T(t)$ would be straight ahead your nose, so if you would use this for your wheels the wheels would be not turned. So first derivative $\dot{r}$ is not enough here.

However the reason for the ciruclar track is a force sideways to the left or right. Force is related to the second derivative of your movement or the curvature of the track.

\begin{align} T(t) &= \frac{dr}{ds} = \frac{\dot{r}(t)}{\lVert \dot{r}(t) \rVert} \\ N(t) &= \frac{\dot{T}(t)}{\lVert \dot{T}(t) \rVert} \quad \kappa N(t) = \frac{\dot{T}(t)}{\lVert \dot{r}(t) \rVert} \\ \kappa(t) &= \left\lVert \frac{d{T}(t)}{ds}\right\rVert = \frac{\lVert \dot{r}(t) \times \ddot{r}(t) \rVert}{\lVert \dot{r} \rVert^3} \end{align}

So to calculate the curvature $\kappa(t)$ one needs both first and second derivatives $\dot{r}, \ddot{r}$ and to combine them properly using the vector product and lenght or scalar product.

Applying the Above

I implemented the above in Ruby (source here) and got these values:

a1 = (-4.01, 0.00, -1.90)
a2 = (4.01, 0.00, -1.90)
c1 = (-2.01, 0.00, -1.90)
c2 = (2.01, 0.00, -1.90)
dr(0.00) = (6.00, 0.00, 0.00), d2r(0.00) = (12.12, 0.00, 0.00), kappa(0.00) = 0.00
dr(0.04) = (6.47, 0.00, 0.00), d2r(0.04) = (11.15, 0.00, 0.00), kappa(0.04) = 0.00
dr(0.08) = (6.89, 0.00, 0.00), d2r(0.08) = (10.18, 0.00, 0.00), kappa(0.08) = 0.00
dr(0.12) = (7.28, 0.00, 0.00), d2r(0.12) = (9.21, 0.00, 0.00), kappa(0.12) = 0.00
dr(0.16) = (7.63, 0.00, 0.00), d2r(0.16) = (8.24, 0.00, 0.00), kappa(0.16) = 0.00
dr(0.20) = (7.94, 0.00, 0.00), d2r(0.20) = (7.27, 0.00, 0.00), kappa(0.20) = 0.00
dr(0.24) = (8.21, 0.00, 0.00), d2r(0.24) = (6.30, 0.00, 0.00), kappa(0.24) = 0.00
dr(0.28) = (8.44, 0.00, 0.00), d2r(0.28) = (5.33, 0.00, 0.00), kappa(0.28) = 0.00
dr(0.32) = (8.64, 0.00, 0.00), d2r(0.32) = (4.36, 0.00, 0.00), kappa(0.32) = 0.00
dr(0.36) = (8.79, 0.00, 0.00), d2r(0.36) = (3.39, 0.00, 0.00), kappa(0.36) = 0.00
dr(0.40) = (8.91, 0.00, 0.00), d2r(0.40) = (2.42, 0.00, 0.00), kappa(0.40) = 0.00
dr(0.44) = (8.99, 0.00, 0.00), d2r(0.44) = (1.45, 0.00, 0.00), kappa(0.44) = 0.00
dr(0.48) = (9.03, 0.00, 0.00), d2r(0.48) = (0.48, 0.00, 0.00), kappa(0.48) = 0.00
dr(0.52) = (9.03, 0.00, 0.00), d2r(0.52) = (-0.48, 0.00, 0.00), kappa(0.52) = 0.00
dr(0.56) = (8.99, 0.00, 0.00), d2r(0.56) = (-1.45, 0.00, 0.00), kappa(0.56) = 0.00
dr(0.60) = (8.91, 0.00, 0.00), d2r(0.60) = (-2.42, 0.00, 0.00), kappa(0.60) = 0.00
dr(0.64) = (8.79, 0.00, 0.00), d2r(0.64) = (-3.39, 0.00, 0.00), kappa(0.64) = 0.00
dr(0.68) = (8.64, 0.00, 0.00), d2r(0.68) = (-4.36, 0.00, 0.00), kappa(0.68) = 0.00
dr(0.72) = (8.44, 0.00, 0.00), d2r(0.72) = (-5.33, 0.00, 0.00), kappa(0.72) = 0.00
dr(0.76) = (8.21, 0.00, 0.00), d2r(0.76) = (-6.30, 0.00, 0.00), kappa(0.76) = 0.00
dr(0.80) = (7.94, 0.00, 0.00), d2r(0.80) = (-7.27, 0.00, 0.00), kappa(0.80) = 0.00
dr(0.84) = (7.63, 0.00, 0.00), d2r(0.84) = (-8.24, 0.00, 0.00), kappa(0.84) = 0.00
dr(0.88) = (7.28, 0.00, 0.00), d2r(0.88) = (-9.21, 0.00, 0.00), kappa(0.88) = 0.00
dr(0.92) = (6.89, 0.00, 0.00), d2r(0.92) = (-10.18, 0.00, 0.00), kappa(0.92) = 0.00
dr(0.96) = (6.47, 0.00, 0.00), d2r(0.96) = (-11.15, 0.00, 0.00), kappa(0.96) = 0.00
dr(1.00) = (6.00, 0.00, 0.00), d2r(1.00) = (-12.12, 0.00, 0.00), kappa(1.00) = 0.00

These values differ from the OP's values. I see no constant $\dot r$ and get a nice flat curvature, as the image below confirms.

Addendum

Here is a plot of the curve using $t$ intervals of $0.1$ length.

t spacing on spline

$\endgroup$
1
$\begingroup$

You use the first derivative to get the direction of the car. That makes sense, the derivative describes how the next section of the road (point on the curve) is different from being a straight road with the former one.

How do you drive on a straight road? Do you have to steer? (assuming a sober driver) Now what if the road is different to a straight line? You would use the steering wheel to stay on track. the more the road is different from being a straight line, the more you'd use the steering wheel.

I hope this makes it clear that steering is indeed the first derivative and not the second one or any other.


The source of your problem is an improper mathematical model of the car. You say when you apply the first derivative to the steering, the wheels have the same orientation as the car:

Hmm, I use the 1st degree derivative to align the whole car body, and it seems to look right. If I use it for the wheels too, then the wheels will never turn as they will always be parallel to the car body.

This happens if you apply the derivative from the same part of the curve. But real world cars have a length that's different from 0.

You should create a different model of the car:

  1. The first coordinate space is the one of the front wheels, that are used for steering. It's origin is located between the front wheels and is always on the curve. It's rotation is based on the first derivative of the curve. The degree of freedom left to choose is at what position it is on the curve.
  2. The second coordinate space is that of the rest of the car. It's origin is located between the rear wheels and is always on the curve. The last rule is that the origin of this coordinate space is a constant distance away from the origin of the first coordinate space and is always pointing towards it. There is no degree of freedom left for this.

I hope you see how this makes a difference. You are not evaluating the first derivative at one point on the curve, but at two different points. That's how you get different angles/orientations for the wheels and the car.


Maybe you should try driving a car, the curvier the road the better. You will quickly realise that steering is something that you do based on what's ahead of you, not based on your current position. You do not steer according to the tangent at your current position because tangents are straight lines and the whole point of steering a car is not to drive in a straight line. The model of a car that I proposed above takes this into consideration by evaluating the first derivative at different points of the curve.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.