Original Post
Hi, I'm having trouble with something that should be a simple problem. The problem is this: Given a target, its velocity, the start position for the projectile and the speed of the projectile calculate the position to shoot at to intercept the target. I had a look on the forums for the answer and found several, one was an iterative approximation and the other was an algebraic solution. The approximation works OK but the algebraic one does not (which is the one I want). The source code for the algebraic solution is given below (I tested it in matlab). All of the function parameters are 2D vectors except for bulletSpeed which is a scalar. function result = Lead(bulletOrigin, bulletSpeed, targetOrigin, targetVelocity) D = targetOrigin - bulletOrigin; E = dot(D,D); F = 2 * dot(targetVelocity, D); G = bulletSpeed * bulletSpeed - dot(targetVelocity, targetVelocity) T = (F + sqrt(F * F + 4 * G * E)) / (G * 2); result = D / T - targetSpeed; This code just does not work, it either coughs up the wrong answer or throws a divide by zero. What the hell is the formula for intercepting a target??? The solution would be much appreciated - this is driving me nuts.