In general, there is no parabola that goes through three given points. However, if you loosen the problem constraints and only define the Y coordinate of the parabola’s top and allow its X coordinate to be free, there is usually a solution.
Given A.x
, A.y
, B.x
, B.y
(A and B’s coordinates) and C.y
(the parabola’s top), one can find a parabola formula of the form:
f(x) = C.y - u (x - v)²
One needs to find u
and v
in this formula. The constraints give us, after some maths:
k = sqrt((C.y - A.y) / (C.y - B.y))
v = (k B.x - A.x) / (k + 1)
u = (C.y - A.y) / (A.x - v)²
For instance if A = (0, 0)
, B = (10, 5)
and C.y = 15
:
k = sqrt((15 - 0) / (15 - 5)) = 1.2247448714
v = (1.2247448714 * 10 - 0) / (1.2247448714 + 1) = 5.505102572
u = (15 - 0) / (0 - 5.505102572)² = 0.494948974
Hence the formula:
f(x) = 30 - 0.494948974 * (x - 5.505102572)²
You can see this parabola going from (0,0)
to (10,5)
with a peak at Y = 15
, as expected:

The following code should work:
pixels = []
k = sqrt((top_y - start_y) / (top_y - dest_y))
v = (k * dest_x - start_x) / (k + 1)
u = (top_y - start_y) / ((start_x - v) * (start_x - v))
for x in start_x to dest_x
y = top_y - u * (x - v) * (x - v)
pixels.push( [x,y] )
end
return pixels