# Finding the parameter of a quadratic Bézier curve for which the tangent passes through a point

I am currently working on a program that requires me to deal with quadratic Bézier curves (basically, I have to take a curve and draw it with a specified thickness). In order to do so, I create two bounding curves from the given curve (from there on called respectively $A$ and $B$), and split its area into triangles. Using a fancy shader and de Casteljau's algorithm, I should then be able to restitute the curve through those triangles alone.

I had a reasonably simple plan to help me find the minimal amount of required triangles to represent any given curve with any given thickness, but it involves solving the derivative of the quadratic Bézier curve:

$$\frac{dBézier(t)}{dt} = 2(t(P_0 - 2P_1 + P_2) + P_1 - P_0)$$

Where $P_0$, $P_1$ and $P_2$ are the three control points of the Bézier curve.

In my case, I know the result of $\frac{dBézier(t)}{dt}$, and I need to find out $t$ from it.

$$R = 2(t(P_0 - 2P_1 + P_2) + P_1 - P_0)$$

At first it looked easy to find $t$ from it (since all $P$ are known, $t$ is the only unknown), but my deficient vector algebra didn't warn me about the wall I'd hit just a few lines of simplification later:

$$\frac{R}{2} + P_0 - P_1 = t(P_0 - 2P_1 + P_2)$$

Isolating $t$ from this requires vector division:

$$t = \frac{\frac{R}{2} + P_0 - P_1}{P_0 - 2P_1 + P_2}$$

Which, apparently, is not an operation with a well-defined output.

That's a pretty sad conclusion because the result feels so much "reachable". There are only constants on the right-hand side fraction, and yet I don't know how to get the $t$ real number from it.

How can I find $t$ from $R = 2(t(P_0 - 2P_1 + P_2) + P_1 - P_0)$?

I know that in certain circumstances, there can be no real solution to this equation (for instance, if $R$ happened to be below the convex part of the curve). However, in my context, I know for sure that there's a solution.

-
You say you know $dB/dt$, but from what you say later, it sounds to me like you really only know its direction, not necessarily its magnitude. You just want to find the point at which the curve's tangent points in a specified direction, right? Otherwise, there will almost always be no solution to your equation, not just in certain circumstances. –  Rahul Apr 11 '11 at 5:25
@Rahul Narain Yes, I just want to find the $t$ parameter at which the curve's tangent crosses a specified point. I'm not looking for the magnitude of the curve. –  zneak Apr 11 '11 at 15:16
Your $R$ should be a vector, not a scalar. In that case, your equation $R = 2(t(P_0 - 2P_1 + P_2) + P_1 - P_0)$ is really two equations, one in $x$ and one in $y$. You can solve either for $t$ (they better agree). So in your equation $t = \frac{\frac{R}{2} + P_0 - P_1}{P_0 - 2P_1 + P_2}$ just take either the $x$ or $y$ components, which should be well-defined unless the points are equally spaced in $x$ (in which case the denominator goes to $0$ and your original equation gives no information about $t$ due to the $0$ coefficient).