2
$\begingroup$

I know from this question on SO that it is possible to get the stationary point of a bezier curve given the control points, but I want to know wether the opposite is true:

If I have the start and end points of a Parabola, and I have the maximum point, is it possible to express this a quadratic bezier curve?

I have seen this answer explaining that you usually would need 6 points on a cubic to effectively describe a bezier curve, but looking at the question itself, it describes a few special cases where you can find the control points on a cubic, and I am curious on wether a quadratic bezier curve has such points, and wether a stationary point is one of them

The variable t of the stationary point is not avalible

I am coming from a computer science background, and although im not too weak in math, any answers/articles that don't use complicated maths and keep it simple would be appreciated

If this is not possible, would it help of the stationary point is always a maximum point and the x coordinate if the max point is the mean of the x coordinates of the start and end points?

By maximum point I mean the point with the maximum value for its y coordinate and by stationary I meant the point with the maximum or minimum value for y

$\endgroup$
9
  • 1
    $\begingroup$ You are defining "stationary point" as the location of the parabola vertex, right? $\endgroup$ Jan 9 at 7:53
  • $\begingroup$ Yes, the maximum point or the minimum point. $\endgroup$
    – Kingteena
    Jan 9 at 10:16
  • $\begingroup$ It's still not clear to me what you think a "maximum" point is. Maximum $y$ coordinate? Maximum curvature? The vertex has a maximum or minimum $y$ coordinate only if the axis of the parabola is parallel to the $y$ axis, which I think is generally not true for Bezier curves. In Finding min/max of quadratic bezier with CoreGraphics the min/max for $x$ occurs at different points than the min/max for $y$, and neither is the vertex in the general case. $\endgroup$
    – David K
    Jan 9 at 16:50
  • $\begingroup$ If you have in mind a quadratic Bezier curve with the control points in general position, and the point you refer to as a maximum point or stationary point is one where either $x$ or $y$ is maximized or minimized, that is, if what you really want is to reverse the process of Finding min/max of quadratic bezier with CoreGraphics, then neither of the answers so far is the one you want. $\endgroup$
    – David K
    Jan 9 at 16:59
  • $\begingroup$ @DavidK See my answer. $\endgroup$ Jan 10 at 4:24
6
$\begingroup$

Define the following:

  • The quadratic Bézier has control points $(x_0,y_0)$ (start), $(x,y)$, $(x_2,y_2)$ (end)
  • The third known point is at $(x_1,y_1)$ with parameter $t$ (in this part of the answer, this is the point with extremal $y$-coordinate)

The curve's equation is then $$x(t)=(1-t)^2x_0+2t(1-t)x+t^2x_2\tag1$$ $$y(t)=(1-t)^2y_0+2t(1-t)y+t^2y_2\tag2$$ and the constraints are $x(t)=x_1$, $y(t)=y_1$ and $y'(t)=0$. Eliminating $y$ in the last two equations gives $$\Delta y_2t^2-2\Delta y_1t+\Delta y_1=0\qquad(\Delta c_i=c_0-c_i)$$ $$t=a\pm\sqrt{a(a-1)},a=\frac{\Delta y_1}{\Delta y_2}\qquad(\Delta y_2\ne0)$$ $$\Delta y_2=0\implies t=\frac12$$ There is a solution in general iff $a\not\in(0,1)$ and only one choice of sign will give $t\in[0,1]$. Once $t$ has been found, it may be substituted back into $(1)$ and $(2)$ to find $x$ and $y$ respectively.


If $(x_1,y_1)$ is the parabola's vertex, the third equation may be obtained from this diagram:

The curve's tangent at the vertex is perpendicular to the line passing between the midpoint of the curve endpoints and the third control point, i.e. $$\begin{bmatrix}\frac{x_0+x_2}2-x\\\frac{y_0+y_2}2-y\end{bmatrix}\cdot\begin{bmatrix}x'(t)\\y'(t)\end{bmatrix}=0$$

A resultant computation followed by factoring out bogus solutions then shows that $t$ solves the cubic $$\begin{align} (\Delta x_2^2+\Delta y_2^2)&t^3\\ -3(\Delta x_1\Delta x_2+\Delta y_1\Delta y_2)&t^2\\ +(\Delta x_1(2\Delta x_1+\Delta x_2)+\Delta y_1(2\Delta y_1+\Delta y_2))&t\\ -(\Delta x_1^2+\Delta y_1^2)&=0 \end{align}$$

$\endgroup$
3
  • $\begingroup$ Thanks a lot for the quick response, however I dont understand how you derived the cubic equation from what I believe is the multiplication of two matrices. And sorry if this seems a stupid, but I sort of need help understanding how the matrices were derived from the diagram. If you could expound on this it would be appreciated. Thanks a lot! $\endgroup$
    – Kingteena
    Jan 9 at 10:55
  • 1
    $\begingroup$ @Kingteena Since this is a general problem, I used SymPy to solve the equations for $t$. The "resultant computation" I mentioned is essentially eliminating variables, but for higher-degree equations. The dot product expresses that two vectors are perpendicular, the vectors here being the result of a little calculus from the known points. $\endgroup$ Jan 9 at 12:00
  • $\begingroup$ That's a very thorough treatment of a somewhat ambiguous question! $\endgroup$
    – David K
    Jan 10 at 5:04
3
$\begingroup$

Let $P_0$ and $P_2$ be startpoint and endpoint of a quadratic Bézier curve. If by "maximum point" you mean that point $Q$ on the curve which is at the maximum distance from line $AB$ (this is not the same as the vertex of the parabola, in general), then finding the control point $P_1$ is easy, because $Q$ is the midpoint between $P_1$ and the midpoint $M$ of $AB$.

Note that the tangent to the curve at $Q$ is parallel to $AB$ and $Q$ is obtained by substituting $t=1/2$ in the equation of the curve: $$ B(t)=(1-t)^{{2}}P_{0}+2t(1-t)P_{1}+t^{{2}}P_{2}. $$

enter image description here

EDIT.

After the given clarifications by the OP, let's assume that the stationary point $P=(x,y)$ of the curve (having $dy/dt=0$) is also known, in addition to $P_0$ and $P_2$. We can simplify a bit the computation shifting all points with a translation so that $P_0=(0,0)$ (this can of course be undone at the end with the opposite translation). In this case we have then: $$ (x,y)=2t(1-t)(x_1,y_1)+t^2(x_2,y_2). $$ The condition $dy/dt=0$ gives $ty_2+(1-2t)y_1=0$, which can be solved for $y_1$: $$ y_1={t\over2t-1}y_2. $$ We can insert this into the equation for $y$, which becomes then $t^2y_2=y(2t-1)$ and can be solved for $t$: $$ t={y\pm\sqrt{y^2-y_2y}\over y_2}. $$ Note that the sign must be chosen so that $0<t<1$, and this can happen only if $\min(0,y2)<y<\max(0,y2)$, as it was to be expected, and $y_2\ne0$ (but see below for this case).

We can substitute this into the equations for $y_1$ given above and into $$ x_1={x-t^2x_2\over2t(1-t)} $$ to obtain the coordinates of control point $P_1$.

Finally, if $y_2=0$ the above solution is singular, but only apparently, because that is exactly the case discussed in the first part of my answer. Hence we can find at once the solution if $y_2=0$: $$ y_1=2y,\quad x_1=2x-{1\over2}x_2. $$

$\endgroup$
4
  • $\begingroup$ Thank you for the answer, but it seems that I have unknowingly become a bit ambiguous in my question. I meant the maximum point as in the point with the extrema in y. Sorry for the mistake on my end, but it would be appreciated if you could edit your answer to include what I meant. Thanks! $\endgroup$
    – Kingteena
    Jan 10 at 16:21
  • $\begingroup$ @Kingteena Note that "the point with the extrema in y" might well be one of the endpoint of your curve (just rotate my sketch above by 90°, for example). In that case what you ask is impossible. $\endgroup$ Jan 10 at 19:17
  • $\begingroup$ In that case, would it help that for my use case, the point with the extrema in y is always going to be such that it's x coordinate is the average of the two endpoints' x cordintate, as stated in my question? $\endgroup$
    – Kingteena
    Jan 11 at 4:20
  • $\begingroup$ @Kingteena I added the solution for the case you specified. Note however that a solution exists only if the $y$ coordinate of the extremum doesn't lie between the $y$ coordinates of the endpoints. $\endgroup$ Jan 11 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.