How to calculate the value of “t” for the highest point in a quadratic bezier curve

bezier-curvecurves

I need to find a the value of t exactly at the point where the curve stops going up an start going down, But I have no idea how to get this value I have the 3 control points values, the blue dot on the left is the control point 1, the big red dot is the control point 2 and the blue dot on the right is the control point 3…

control points view

the black dot is the control point for t = 0.5

and the difference in t for each colored dot is 0.1

is the first image it's possible to notice that the highest point are exactly or very close to the yellow dot or in other words t = 0.4, in the center image the black dot is on the top (t = 0.5) and the last image the top is very close to the cyan dot (t = 0.6)…

to find the position for each of these colored dots I'm using the formula..

curvePoint = A *(1-t)^2 + B * 2t(1-t) + C * t^2

where A = center of the first blue dot, B = center of the big red dot, C = last blue dot and and t goes from 0 to 1 in increments of 0.1…

my question is, how to find out t mathematically? when I drag the big red dot the curve follows the control point but I have no idea what's the t value for the highest point in the given configuration…

Is there any formula to find this value?
I hope I was able to make myself clear

thank you in advance for the answers!

Best Answer

Sure. Let's call the curve point $P$ rather than "curvePoint"; we then want to know for what value of $t$ the $y$-coordinate of $P$ is largest. The good news is that the $y$-coord of $P$ depends only on the y-coords of $A, B,$ and $C$: $$ P_y(t) = A_y (1-t)^2 + B_y 2t (1-t) + C_y t^2 $$

The function $P_y$ is defined on the interval $0 \le t \le 1$, and the max might occur at an endpoint, so we compute, right away, $$ P_0 = A_y (1-0)^2 + B_y 2\cdot 0 (1-0) + C_y 0^2 = A_y\\ P_1 = \ldots = C_y $$ Now as for the middle point, it must happen where the derivative with respect to $t$ is zero, i.e. where $$ P_y'(t) = -2A_y (1-t) + 2B_y(1-t) + 2B_y t (-1) + 2C_y t = 0 \\ P_y'(t) = -2(1-t) (A_y - B_y) + 2t(C_y - B_y) \\ $$ which is a linear bezier curve with control points that are (proportional to) the difference of $A$ and $B$ and the difference of $B$ and $C$. (I mention this because you may find it useful later).

Setting to zero and simplifying to find the critical value of $t$, we can get rid of all the factors of 2 and combine terms to get $$ \newcommand{\tstar}{{t_{*}}} $$ \begin{align} -2 (A_y - B_y) +2\tstar (A_y - B_y) + 2\tstar(C_y - B_y) &= 0 \\ -2 (A_y - B_y) +2\tstar (A_y + C_y - 2B_y) &= 0 \\ \tstar (A_y + C_y - 2B_y) &= (A_y - B_y) \\ \tstar &= \frac{A_y - B_y}{A_y + C_y - 2B_y } \end{align} and we can use this value of $\tstar$ to compute $P_2$, the height of the curve at the critical time $t$. We compare this to $P_0$ and $P_1$, and pick as our $t$-value either $0, 1,$ or $\tstar$ accordingly.