Formula to get a control point closest for a given point what belongs to this quadratic curve

1,357

Solution 1

An addendum to Achille Hui's fine solution (which is too long for a comment):

Let $\vec{U}$ and $\vec{V}$ be unit vectors in the directions of $\vec{X} - \vec{A}$ and $\vec{X} - \vec{B}$ respectively. Also, let $h = \Vert{\vec{X} - \vec{A}}\Vert$ and $k = \Vert{\vec{X} - \vec{B}}\Vert$. My $h$ and $k$ are Achille's $R_A$ and $R_B$ respectively. Then we have $\vec{X} - \vec{A} = h\vec{U}$ and $\vec{X} - \vec{B} = k\vec{V}$.

Achille showed that $$ \vec{C} = \vec{X} + \frac12\sqrt{hk}(\vec{U} + \vec{V}) $$

But the vector $\vec{U} + \vec{V}$ is along the bisector of the lines $AX$ and $BX$, so, we get a nice geometric result: the middle control point $\vec{C}$ of the "optimal" curve lies on the bisector of the lines $AX$ and $BX$.

Also, the first derivative vector of the optimal curve at the point $\vec{X}$ is given by $$ \gamma'(t) = \sqrt{hk}(\vec{U} - \vec{V}) $$ The vector $\vec{U} - \vec{V}$ is along the other bisector of the lines $AX$ and $BX$, so, we get another nice geometric result: the tangent vector of the "optimal" curve is parallel to the bisector of the lines $AX$ and $BX$.

In aircraft lofting departments, there are people who construct parabolas (and other conic section curves) all day long. I wonder if they use this construction to get a "nice" parabola through three given points. I'll ask, next time I get a chance.

Here's a picture illustrating the geometry: curve

Solution 2

For simplicity of derivation, choose a coordinate system such that $\vec{X}$ is the origin. The quadratic curve between $\vec{A}$ and $\vec{B}$ has the parametrization:

$$[0,1] \ni s \quad\mapsto\quad \vec{\gamma}(s) = (1-s)^2 \vec{A} + s^2 \vec{B} + 2s(1-s)\vec{C}$$

Since $\vec{X}$ lies on the quadratic curve, for some $t \in [0,1]$, $\vec{\gamma}(t) = \vec{X} = \vec{0}$. This implies $$\vec{C} = -\frac12 \left( \lambda^{-1} \vec{A} + \lambda \vec{B} \right) \quad\text{ where }\quad \lambda = \frac{t}{1-t}.$$ So the problem of locating $\vec{C}$ reduces to the problem of figuring out the parametrization parameter $t$ for $\vec{X}$.

The tangent vector for the quadratic curve at $X$ is given by:

$$\gamma'(t) = \left.\frac{d\vec{\gamma}(s)}{ds}\right|_{s=t} = -2(1-t)\vec{A} + 2t\vec{B} + 2(1-2t)\vec{C} $$

Notice $$\lambda = \frac{t}{1-t} \implies t = \frac{\lambda}{1+\lambda},\;\;1 - t = \frac{1}{1+\lambda} \;\;\text{ and }\;\; 1 - 2t = \frac{1-\lambda}{1+\lambda}$$ We find

$$ \gamma'(t) = -\frac{2}{1+\lambda}\vec{A} + \frac{2\lambda}{1+\lambda} \vec{B} - \frac{1 - \lambda}{1+\lambda} \left( \lambda^{-1} \vec{A} + \lambda \vec{B} \right) = \lambda \vec{B} - \lambda^{-1}\vec{A} $$ The condition that $\vec{X}$ is the point on $\vec{\gamma}(s)$ closest to $\vec{C}$ can be expressed as:

$$\gamma'(t) \cdot \vec{C} = 0 \quad\iff\quad \left( \lambda^2 \vec{B} - \vec{A} \right) \cdot \left( \lambda^2 \vec{B} + \vec{A} \right) = \lambda^4 R_B^2 - R_A^2 = 0 $$ where $R_A = |\vec{A}| $ and $R_B = |\vec{B}|$. This give us

$$\lambda = \sqrt{R_A/R_B} \quad\implies\quad\vec{C} = -\frac{\sqrt{R_AR_B}}{2}\left( \frac{\vec{A}}{R_A} + \frac{\vec{B}}{R_B} \right)$$

Update

In the general case when $\vec{X}$ is not the origin, let

$$\vec{A} = (A_x,A_y),\;\;\vec{B} = (B_x,B_y),\;\;\vec{C} = (C_x,C_y),\quad\text{ and }\quad \vec{X} = (X_x,X_y).$$

The distances of $\vec{A}$, $\vec{B}$ from $\vec{X}$ become $$\begin{cases} R_A = & \sqrt{(A_x - X_x)^2 + (A_y - X_y)^2}\\ R_B = & \sqrt{(B_x-X_x)^2 + (B_y-X_y)^2}, \end{cases}$$

and the coordinates of $\vec{C}$ turns into:

$$\begin{cases} C_x = & X_x - \frac{\sqrt{R_A R_B}}{2}\left(\frac{A_x - X_x}{R_A} + \frac{B_x - X_x}{R_B}\right)\\ \\ C_y = & X_y - \frac{\sqrt{R_A R_B}}{2}\left(\frac{A_y - X_y}{R_A} + \frac{B_y - X_y}{R_B}\right) \end{cases}$$

Share:
1,357

Related videos on Youtube

bub
Author by

bub

Updated on March 11, 2021

Comments

  • bub
    bub over 2 years

    We have a quadratic bezier curve, with control point A (red start), control point B (red end), and yellow point X what belongs to the curve and what you actually "drag" - so it should be the closest point to the missing control point C (blue) what forms the curve. What is a formula getC(A,B,X) to calculate it?

    drawing http://www.freeimagehosting.net/newuploads/d89e6.gif

    A popular solution is when we think that X corresponds to t=1/2 for calculating C is not giving a nice result.

    The concept is explained on this thread. But still I can't figure out the final formula for calculating C from it - having difficulty to understand the "orthogonality relation"

    Thanks for any help!

    • bubba
      bubba about 10 years
      I'm surprised that using $t = 1/2$ doesn't give a good result. If you use $t = 1/2$, then $X$ will be the mid-point of the line from $C$ to $\tfrac12(A+B)$, and the tangent at $X$ will be parallel to the chord $AB$. So, you generally get "natural" behaviour that users like. What problems did you find?
    • bub
      bub about 10 years
      well I was implementing a "dragging" of the curve what has static start and the end. so if I drag the yellow point close to the end (right red X on the picture) - it corresponds to the t = 1/10 or so, and if we calculate the missing control point based on t = 1/2 we are getting a "not optimal" curve, smth like that !image - black curve is what we get, yellow is a desired curve. it looks nice only if you drag in the middle - that's why I was looking for a better solution
    • bubba
      bubba about 10 years
      OK. Thanks. Makes sense. My experience is that users tend to drag near the middle of the curve, so using t=1/2 has never been a problem for me. But, the new solution is certainly better. It was a good question, and I learned a lot by working on it.
  • bub
    bub about 10 years
    the problem is that the curve is unknown, we have only red points (start and end) and the yellow point X what belongs to it - we have to build a curve by figuring out the unknown blue point C (control point) - we know only that CX is orthogonal to the tangent line in the point X)
  • bub
    bub about 10 years
    it works like a charm!!! thank you a lot, you rock!
  • bubba
    bubba about 10 years
    Well, you did the hard work :-)