Shortest route to intersection
I asked this question about 2 months ago but found none of the answers to be helpful enough. So I am giving it another shot. I think it was my fault not describing it well enough. So lets try again.
(source: bja888.com)Here is a rough idea of what I am trying to accomplish.
The goal is to send a projectile from point T to intercept the object represented by point R. What is known:- The location of object R
- The direction object R is traveling
- The speed at which object R is traveling
- The location of object T
- Speed at which object T will travel
I am looking for the direction object T should be sent and thus find the location they will collide at. Either one.
For example: If...
- The 开发者_如何学运维location of R was (1,5)
- R is traveling at a 45 degree angle (relative to d)
- R is traveling at 1 unit per second
- T is located at (1,1)
- T also travels at 1 unit per second
L makes the location of the collision at (3,3)
There are an infinite number of possibilities. Consider a concentric series of circles from the points R and T, representing the distance each could travel at increasing times. Where the circles intersect is the point of collision, a vector between the point of collision and T is where T should have been aimed at for that particular instant. If you are looking for the shortest path, you need to get the normal to R's path and fire T at the appropriate time by calculating the time it takes for T to traverse this distance so it will arrive at the same time as R.
Assume no air friction, gravity, external forces, near-speed-of-light missiles, violation of physical laws, etc.
Suppose initially R = (x, y) and T = (0, 0). (Change your coordinates system if T not at the origin).
Suppose the velocity of T is constantly (cos θ, sin θ), where θ is unknown but does not depend on time. (Change your coordinates system or unit of time if the speed if not 1.)
Suppose the velocity of R is constantly (v, 0). (Change your coordinates system if the velocity is not along the horizontal.)
Suppose at time t the two objects collide. So we have 2 equations and 2 unknowns:
- t cos θ = x + vt
- t sin θ = y
So obviously
- t2 = (x + vt)2 + y2.
Solve this quadratic equation to get t. Plug it into the y equation to get θ. QED.
精彩评论