Change the vertex of a parabola while ensuring it still passes through a particular point

quadratics

I have a parabola defined by the quadratic equation $y = -(x + 0)(x – endPoint)$, which also passes through a particular point $(a, b)$. I would like to know how to alter the equation so that I can ensure that the vertex of the parabola reaches a particular $height$ while still passing through point $(a, b)$ and while still passing through the $endPoint$ when $y = 0$ (although I don't mind if the other side of the parabola no longer passes through the origin).

For reference, I'm programming a computer game where a projectile moves in a parabolic arc. Point $(a, b)$ is the point from which the projectile is launched, and point $(endPoint, 0)$ is where the projectile lands, which is why those two points must remain immutable. But I need to be able to define how high the parabola is at its apex so that I can ensure the projectile will pass over certain obstacles.

Also, as far as my mathematical skill goes, I've spent the last couple of days digging up my memories of high school quadratics, and that was nearly 20 years ago.

Best Answer

The general parabola $y = f(x)$ with a given root $p$ (i.e., given $x$-coordinate of the endpoint) has the form $$y = f(x) = - A (x - p) (q - x),$$ where $A$ and $q$ are arbitrary constants. The condition that the parabola passes through $(a, b)$ is that $f(a) = b$, so that $$\boxed{A(a - p)(a - q) = b} .$$ By symmetry the vertex of the parabola has $x$-coordinate $\frac{p + q}{2}$, so the requirement that the parabola has (for $A > 0$) maximum height (i.e., $y$-coordinate) $h$ there is $f\left(\frac{p + q}{2}\right) = h$, or $$\boxed{A (p - q)^2 = -4 h} .$$

Multiplying the equations and canceling $A$ gives $$-4h (a - p) (a - q) = b (p - q)^2 .$$ This is a quadratic equation in $q$, and expanding, collecting like terms in $q$, and applying the quadratic formula gives an expression for $q$ in terms of $a, b, h, p$. Substituting this expression in either of the above boxed equations (the first is easier to use, since it is linear, not quadratic, in $q$) and solving gives an expression for $A$. The result is: $$\boxed{A = \frac{z}{(a - p)^2}, \qquad q = \frac{a z + (p - a) b}{z}, \qquad \textrm{where} \qquad z := b - 2 h + 2 \sqrt{h (h - b)}}.$$