What is the formula for a quadratic curve with defined crossing and maxima points?

255 Views Asked by At

This is a problem that I've been wrestling with on and off in the process of creating quadratic splines for a game I'm building.

Given crossing points $x_0$ and $x_1$, and a maximum point $m$, how does one derive a quadratic function $y = f(x)$ which fulfils these constraints?

For example, what is the equation for y, when you have crossing points $(0,0)$ and $(5,0)$, and maximum point $(3,3)$?

2

There are 2 best solutions below

2
On BEST ANSWER

You are trying to construct a function $f$ that has four constraints, namely: \begin{align} f(0) &= 0 \\ f(5) &= 0 \\ f(3) &= 3 \\ f'(3) &=0 \end{align} To satisfy these four constraints, you need a function with four degrees of freedom. The easiest solution would be a single cubic, say $f(x) = ax^3 + bx^2 +cx + d$. Then the four constraints give you the equations: \begin{align} d &= 0 \\ 125a + 25b + 5c &= 0 \\ 27a + 9b + 3c &= 3 \\ 27a + 18b +c &=0 \end{align} You can solve these equations to get $a,b,c,d$.

Alternatively, you can use a quadratic spline with two segments, one on the interval $[0,3]$ and the other on $[3,5]$. Suppose we use $g(x) = px^2 + qx + r$ to denote the quadratic on the interval $[0,3]$. Then we have \begin{align} g(0) &= 0 \\ g(3) &= 3 \\ g'(3) &=0 \end{align} which gives us the equations \begin{align} r &= 0 \\ 9p + 3q + r &= 3 \\ 6p + q &=0 \end{align} You can solve these equations to get $p,q,r$, and you can do a similar construction of another quadratic on the interval $[3,5]$.

0
On

If you want to use smooth quadratic splines (order = 3), as you have 4 conditions (number = 4, three crossing points and one zero derivative at the maximum), your knot vector will have length 7 (number + order). For a clamped spline this would be, in your example, $[0,0,0,\alpha,5,5,5]$, with $\alpha$ not determined.

There are many possible values for $\alpha$ and you have to add another condition (derivative not lower than 0, ...)