3

I have two quadratic bezier curves and I want to find whether they have a common tangent, and if so where it is.

If the first bezier is defined by points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$, then the points on the curve have coordinates:

$x = (x_1 - 2x_2 + x_3)t^2 + (2x_2 - 2x_1)t + x_1 \\ y = (y_1 - 2y_2 + y_3)t^2 + (2y_2 - 2y_1)t + y_1$

Or to simplify things:

$x = A_xt^2 + B_xt + C_x \\ y = A_yt^2 + B_yt + C_y$

Likewise, I can get an equation for the second bezier:

$x = D_xs^2 + E_xs + F_x \\ y = D_ys^2 + E_ys + F_y$

The gradient of the tangent, $m$, to the first curve at $t$ is $\dfrac{2A_yt + B_y}{2A_xt + B_x}$,

which must be equal to the tangent to the second curve at $s$, $\dfrac{2D_ys + E_y}{2D_xs + E_x}$.

So $m = \dfrac{2A_yt + B_y}{2A_xt + B_x} = \dfrac{2D_ys + E_y}{2D_xs + E_x}$

Which I rearranged to get:

$t = \dfrac{2(B_yD_x - D_yB_x)s + B_yE_x - B_xE_y}{4(A_xD_y - A_yD_x)s + 2(A_xE_y - A_yE_x)}$

The gradient of the tangent is also equal to the difference in the y-coordinates over the difference in x-coordinates:

$m = \dfrac{D_ys^2 + E_ys + F_y - (A_yt^2 + B_yt + C_y)}{D_xs^2 + E_xs + F_x - (A_xt^2 + B_xt + C_x)}$

But that's as far as I got. The algebra looks too messy from here. Can anyone solve this, or is there a better approach?

  • 1
    Quadratic Bézier curves are always segments of parabolas. Have you tried “un-parameterizing” them into general Cartesian conic equations? – amd Feb 17 '17 at 19:48
  • @amd I tried (after you mentioned it), but it seems to create a very complex equation. I don't know if it can be simplified. – Peter Collingridge Feb 20 '17 at 18:29
  • If you’re looking for a single closed-form formula of some sort, it’s going to be unavoidably messy. – amd Feb 20 '17 at 19:23

2 Answers2

2

A single, closed-form solution to this is going to be unavoidably messy. If you take it in steps, however, it’s manageable.

Let $P_1$, $P_2$, $P_3$ be the control points of the first quadratic Bézier and $Q_1$, $Q_2$, $Q_3$ be the control points of the second, so that we have the parameterizations $B_1:t\mapsto(1-t)^2P_1+2t(1-t)P_2+t^2P_3$ and $B_2:s\mapsto(1-s)^2Q_1+2s(1-s)Q_2+s^2Q_3$, respectively. Quadratic Bézier curves have a nice property: the tangent line at $B_1(t)$ passes through the points $(1-t)P_1+tP_2$ and $(1-t)P_2+tP_3$. So, if there is a common tangent, then there is some value for $s$ and $t$ such that these two points and the points $(1-s)Q_1+sQ_2$ and $(1-s)Q_2+sQ_3$ are colinear. A direct approach from here will give you a quadratic equation in $s$ and $t$ that you can try to solve. Another possible approach is to compute the intersections $R_1$ and $R_2$ of this tangent line to $B_1$ with the lines $\overline{Q_1Q_2}$ and $\overline{Q_2Q_3}$, respectively, and then see if ${\|P_1-Q_1\|\over\|Q_2-Q_1\|}={\|P_2-Q_2\|\over\|Q_3-Q_2\|}$, using signed distances, i.e., see if the two intersection points correspond to the same value of $s$.

amd
  • 53,693
  • Thanks, I'd not realised those points would be on the tangent and that's very helpful. This looks like a promising approach. It's still pretty messy, but looks slightly easier than my approach. – Peter Collingridge Feb 21 '17 at 11:41
  • OK, I worked through the algebra based on your approach and got a cubic which give the right value(s). Thanks! – Peter Collingridge Feb 21 '17 at 14:30
  • @PeterCollingridge This property holds in general. An $n$th-degree Bézier curve $B^n$ can be constructed from two $(n-1)$-degree Bézier curves $B_1^{n-1}$ and $B_2^{n-1}$ as $B^n[t]=(1-t)B_1^{n-1}[t]+tB_2^{n-1}[t]$. The line through $B_1^{n-1}[t]$ and $B_2^{n-1}[t]$ is tangent to the constructed curve. – amd Feb 21 '17 at 18:19
1

Here is an outline of an approach.

Take the point with parameter value $t$ on the first parabola. Let's say the position of this point is $\mathbf{P}(t)$ and the first derivative vector there is $\mathbf{P}'(t)$. Then the tangent line at this point can be described by the parametric equation $\mathbf{L}(u) = \mathbf{P}(t) + u \mathbf{P}'(t)$.

Next, we can eliminate the parameter $s$ from the equation of the second parabola, and get an equation of the form $ax^2 + by^2 +cxy +dx + ey + f = 0$. Or, in matrix form, $\mathbf{X}^T\mathbf{M}\mathbf{X} = 0$. Actually, any conic section curve can be written in this implicit form, not just parabolas. For an easy approach to implicitizing a quadratic curve in Bezier form, see section 17.6 in these notes by Tom Sederberg.

Now let's look at the points where the tangent line intersects this second parabola. This happens for values of $u$ that satisfy $\mathbf{L}(u)^T\mathbf{M}\mathbf{L}(u) = 0$. This is a quadratic equation in $u$. To get tangency to the second parabola, we need this quadratic to have equal roots. Write down the condition for equal roots. This condition will say that some function of $t$ is equal to zero. Solve for $t$.

It might still be pretty messy, but I think that's unavoidable.

bubba
  • 43,483
  • 3
  • 61
  • 122
  • This seems like a good approach. The part I'm stuck with is eliminating the parameter s. The implicitization of a bezier seems to give a large function with lots of square roots. A Google search doesn't seem to give any good solutions. – Peter Collingridge Feb 20 '17 at 18:27
  • Implicitizing a quadratic is very easy. I added a link to a document that tells you how. Just a 2x2 determinant. No square roots. Not even any divisions. – bubba Feb 21 '17 at 12:10
  • The link is broken – JulienD Jun 16 '20 at 20:24
  • New links: https://scholarsarchive.byu.edu/facpub/1/ or http://hdl.lib.byu.edu/1877/2822 – bubba Jun 17 '20 at 10:56