I need to draw parabola through two points, but also need to be able to change the width of the parabola. In more details let's say I have parabola:
$f ( x ) = - \frac { ( x - 1 ) ^ { 2 } } { W } + 1$
And no matter what $W$ I define I want my parabola goes through points (0,0) and (1,1) which for that case happens only if $W=1$.
I suppose I need to rotate the parabola or move whole parabola in some way. But don't know how to do that.
My aim is to increase $W$ to infinity until I get straight line (infinity almost straight) through mentioned points. And in the future of course I want to be able to manipulate those points.
For any help thanks in advance.
You can simply set up a system of equations in the quadratic form:
$$y=ax^2+bx+c$$
So plugging in $x$ and $y$ from your points $(0,0)$ and $(1,1)$, you make two equations:
$$0=a(0)^2+b(0)+c$$ $$1=a(1)^2+b(1)+c$$
The equations simplify to:
$$c=0$$ $$1=a+b$$
So the $c$ of your quadratic equation will be always 0. $a$ is your "width" of the parabola. The lower the value, the wider it is, the higher the value, the narrower it is. Just remember that whatever $a$ you chose, you have to chose $b$ so that $a+b=1$ as can be seen in the second equation.
To get the equation in terms of $W$ simply complete the square and manipulate the standard quadratic form (note that $c$ is $0$, so we exclude $c$):
$$y=ax^2+bx$$ $$y=a\Big(x^2+\frac{b}{a}x\Big)$$ $$y=a\Big(x+\frac{b}{2a}\Big)^2-\frac{b^2}{4a}$$
Now, since $a+b=1$ then $b=1-a$:
$$y=a\Big(x+\frac{1-a}{2a}\Big)^2-\frac{(1-a)^2}{4a}$$
Now, simply define $W=\frac{1}{a}$ and the equation will change into:
$$y=\frac{\big(x+\frac{W-1}{2}\big)^2}{W}-\frac{(W-1)^2}{4W}$$
Then, combine the two fractions into one and expand exponent:
$$y=\frac{4\Big(x^2+(W-1)x+\frac{(W-1)^2}{4}\Big)-(W-1)^2}{4W}$$ $$y=\frac{4x^2+4(W-1)x}{4W}$$ $$y=\frac{x^2+(W-1)x}{W}$$ $$y=\frac{x^2}{W}+\frac{(W-1)}{W}x$$
And that's it! We derived the equation in terms of $W$. Now, simply to change the width of the parabola, you change $W$. The bigger $W$, the wider the parabola, the lower $W$, the narrower the parabola. (Opposite of what happens if you change $a$ because we defined $W=\frac{1}{a}$). The parabola will rest on the points $(0,0)$ and $(1,1)$ as expected.
Also, notice what happens when you increase $W$ to infinity. With some further analysis, and taking $\lim_{W\to\infty} y$, you can see that the equation slowly becomes the line $y=x$, which is exactly what you predicted and wanted!
Note: If you would ever need three points instead of two, you won't be able to change the width of the parabola because three points describe exactly one parabola. With two points you have infinite parabolas, hence the ability to change width.
EDIT: I was answering it fast, and now I realized, that you don't have to complete the square at all! You simply need to start with:
$$y=ax^2+bx$$
Then just plug in $b=1-a$, and then $a=\frac{1}{W}$:
$$y=ax^2+(1-a)x$$ $$y=\frac{x^2}{W}+\Big(1-\frac{1}{W}\Big)x$$ $$y=\frac{x^2}{W}+\frac{(W-1)}{W}x$$
Sorry for making it more complicated than it should be.