I want to calculate the launch velocity needed for a projectile to land on a specific point on top of a cliff.
*This is for a realtime computer simulation, so we can ignore air resistance, etc, and just assume that the only acceleration is from gravity on the vertical component, while the horizontal component is constant. I would like to avoid expensive trig functions, and instead just calculate the vertical and horizontal components independently using the displacement formula, then add them together to get the total launch vector. So given a desired horizontal and vertical displacement Dx and Dy, gravity acceleration a, and a flight duration t, just use: Vx = Dx/t to get needed horizontal velocity, and Dy = Dy/t – 1/2at^2 which yields Vy = Dy/t – at ½ if you divide the whole thing by time to get velocity on the left side. This works perfectly to hit the point.
1) The equations are too “dumb” to know if the arc is high enough to actually clear the cliff edge, so it might hit into the wall in spite of “correct” values.
2) Passing in a pre-set duration for all calculations makes it shoot really high into the air when very close to the target, and too shallow when very far away from the target. It should use a smaller duration value when closer, so it doesn’t fly too high, and a larger duration value when far away, so it actually gets there.
So I’m thinking I need polynomial interpolation to do this – setting three points to pass through: the launch location, the target, and a point at the minimum height above the ledge for it to always clear the ledge and hit the target. If I generate three equations from these points, and solve for the alpha beta and gamma coefficients by which to scale the basis polynomials x^2, x, and 1, then I will have the perfect curve. Note - the desired curve must be 2nd degree quadratic to be realistic, no higher degree will work
Then I just take the derivative of this curve at the launch point to find the slope at which to launch it by, but I don’t know how exactly to do this.
1) what’s the most efficient way other than solving for the inverse matrix to get the coefficient vector? Lagrange Polynomials?
2) More importantly, the launch position and target point are unique, but the point above the ledge is not. It could be any value with a sufficient height to clear the ledge. However, if it is too low, the curve containing the other 2 points would not pass through it, either.
How do I solve for this inequality?
Any help would be much appreciated, thanks.