# Bezier curve and deceleration

I have a question regarding calculation of a cubic Bezier curve. I'm programming an app where in there's continuous straight line motion of a vehicle at a constant speed. (Let's call it $u$). When the user taps a button, the vehicle decelerates at a constant rate and finally stops after a time period $t$ and moving a certain distance $d$.

However, due to restrictions of the system I'm coding in, I'm supposed to model this deceleration using a Bezier curve. The $y$ axis of the Bezier curve would be distance moved, while the $x$ axis is time. The system only lets me modify the 2 control points (or guide points) of the curve. The initial point is set to $(0,0)$ and the final point is set to $(1,1)$.

At this point, I already know the value of $t$, the value of $d$, and also the value of $u$. Final velocity $v = 0$. Using this I can even calculate the deceleration rate as $a = (v-u)/t$ since deceleration is linear. However, the system only takes the two middle points of the Bezier curve to model this deceleration.

Could I have some help in using the values I have to get the Bezier points?

Note: The bezier curve is normalized. the initial point is set to (0,0) and the final to (1,1). So it assumes that the deceleration animation starts at x = 0 (time = 0) and ends at x = 1 (time = t), and y = 0 when distance moved = 0, and y = 1 when distance moved = d

• By "the two middle points of the curve" do you mean a point that shows the direction of the curve at the start and another point that shows the direction of the curve at the end? That is the usual interactive way to define a Bezier curve (besides the start and end points). Those two "middle points" I stated (actually "guide points") are not actually on the curve. – Rory Daulton Jun 12 '15 at 15:02
• Your final point is set to $(1,1)$ no matter what the time interval, initial velocity, acceleration, and hence total distance moved, are? Does that mean the graph is scaled so the the time interval and total distance moved are $1$? – Rory Daulton Jun 12 '15 at 15:04
• Yes, you're right. they're not actually on the curve. I'm very new to this, and I'm not entirely sure what they're called. You're welcome to edit the question to make that more clear. @RoryDaulton – sosale151 Jun 12 '15 at 15:05
• You're also right that the the bezier curve is normalized. the initial point is set to (0,0) and the final to (1,1). So it assumes that the deceleration animation starts at x = 0 (time = 0) and ends at x = 1 (time = t), and the animation progress y = 0 when (distance moved = 0), and y = 1 when (distance moved = d) @RoryDaulton – sosale151 Jun 12 '15 at 15:08

I'll keep using your notation $t$ for time, $d$ for distance, $u$ for initial velocity, $v$ for final velocity, and $a$ for acceleration. Note that $a$ will be a negative constant.

The vehicle stops when $v=u+at=0$, i.e. at $t_f=-\frac ua$. The distance covered is $d=ut+\frac 12at^2$, which at the stopping point will be $d_f=-\frac{u^2}{2a}$. If we then scale these onto a $x$-$y$ graph from $(0,0)$ to $(1,1)$ by letting $x=\frac t{t_f}$ and $y=\frac d{d_f}$ the equation $d=ut+\frac 12at^2$ becomes

$$y=2x-x^2$$

Note that you get the same equation in $x$ and $y$ after scaling, no matter what the values of $t$, $d$, and $u$ are. That makes your job simpler but more boring: you need to approximate the parabola $y=2x-x^2$ for $0\le x\le 1$ by a Bezier curve.

(I made a mistake in my first analysis, corrected brilliantly by @fang in a comment. The following is my corrected analysis.)

You get that curve by using the cubic Bezier curve with starting point $P_0(0,0)$, first control point $P_1(\frac 13,\frac 23)$, second control point $P_2(\frac 23,1)$, and endpoint $P_3(1,1)$. This reproduces the desired parabola exactly. In fact, if you slow down the drawing by increasing the Bezier curve's parameter at a constant rate, the moving point will be at each correct place on the graph at the correct time.

• The statement saying $y=2x-x^2$ cannot be represented by a cubic Bezier curve is not correct. You can represent it by a cubic Bezier curve with control points as P0=(0,0), P1=(1/3, 2/3), P2=(2/3, 1) and P3=(1,1). – fang Jun 12 '15 at 23:39
• @fang: You're probably right, since my analysis of that point was rushed. I'll check you properly tomorrow. Why don't you add that as an answer? – Rory Daulton Jun 13 '15 at 0:21
• you did derive that quadratic equation. I should not take your credit. – fang Jun 13 '15 at 1:28
• @fang: I now see that your analysis was completely correct, and if the drawing is slowed down the "moving point" is in exactly the correct spot at all times. Brilliant! Thanks for your correction. I'll upvote some of your answers to other questions in thanks. – Rory Daulton Jun 13 '15 at 13:35
• That is an unexpected but pleasant surprise. Thanks. – fang Jun 13 '15 at 19:52