Best Heading/Orientation for Fastest Interception of a Moving Target

  • Context: Undergrad 
  • Thread starter Thread starter nilum
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around determining the optimal heading or orientation for a player character in a video game to intercept a moving target. The focus is primarily on mathematical modeling and calculations necessary for achieving the fastest route to the target, considering both two-dimensional and three-dimensional coordinates and velocities.

Discussion Character

  • Exploratory
  • Mathematical reasoning
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks assistance in finding a formula to calculate the best orientation for intercepting a moving target without acceleration.
  • Another participant suggests that the problem can be approached by finding the direction that maximizes the decrease in the square of the distance to the target.
  • A different approach involves plotting time on a z-axis to find the intersection of a line with a cone.
  • One participant provides a detailed mathematical formulation involving the coordinates of the target and player, leading to a quadratic equation to solve for interception time.
  • Concerns are raised about the initial formula not accounting for the target's heading, suggesting that trigonometric considerations may be necessary.
  • Another participant proposes reducing the problem to two dimensions and applying the Law of Sines to calculate angles and distances related to the interception.
  • Further elaboration on creating a triangle with the player and target vectors is presented, discussing how the velocity ratio affects the angles involved in the interception calculation.
  • One participant expresses ongoing difficulty in deriving a formula or function despite the outlined approaches and considerations.

Areas of Agreement / Disagreement

Participants express various methods and considerations for calculating interception, but there is no consensus on a single approach or formula. Multiple competing views and methods remain unresolved.

Contextual Notes

Some participants note limitations regarding the assumptions made about the target's motion and the player's speed, as well as the potential for special cases where interception may not be possible.

nilum
Messages
6
Reaction score
0
I am trying to write an addon for a videogame which will give the best orientation/heading to intercept a target. The best would mean the fastest route to a moving target.

There is no acceleration in the game.

I can get the speed/velocity of the target and player, as well as their coordinates and orientation/heading in three dimensions.

For the most part I will only need to use the XY plane, but there are some instances where being able to figure in pitch would be handy.

--

The problem is I am not very adept with math or physics.

I've tried to find a formula, but haven't had much luck.

Can anyone help me out?
 
Physics news on Phys.org
If you assume that the target is moving in a straight line without acceleration, and your speed is also fixed, then you are looking for the direction in which the decrease of the square of the distance to the target is the greatest. Smells like twelfth grade math. Maybe I scribble something and come back...
 
I found another way: If you plot the time on the z axis, you will see that you need to find the intersection of a line with a cone.
 
Well, if you have the coordinates of the target as three functions of time
[tex]\begin{align}x_t(t) &= x_{t0} + v_{tx}t \\<br /> y_t(t) &= y_{t0} + v_{ty}t \\<br /> z_t(t) &= z_{t0} + v_{tz}t\end{align}[/tex]
and you have the current position [itex](x_{p0}, y_{p0}, z_{p0})[/tex] and speed [itex]v_{p}[/itex] of the player, then the intersection point will be<br /> <br /> [tex](x_{t0} + v_{tx}t)^2 + (y_{t0} + v_{ty}t)^2 + (z_{t0} + v_{tz}t)^2 - x_{p0}^2 - y_{p0}^2 - z_{p0}^2 = (v_{p}t)^2[/tex]<br /> <br /> or<br /> <br /> [tex]\left(x_{t0}^2 - x_{p0}^2 + y_{t0}^2 - y_{p0}^2 + z_{t0}^2 - z_{p0}^2\right) + \left(2x_{t0}v_{tx} + 2y_{t0}v_{ty} + 2z_{t0}v_{tz}\right)t + \left(v_{tx}^2 + v_{ty}^2 + v_{tz}^2 - v_p^2\right)t^2 = 0[/tex]<br /> <br /> which is a quadratic equation you can solve to get the time it will take to intercept the target. It's messy but it shouldn't be hard to program the computer to do it. Once you figure out the time, you can get the position by plugging in the time to the target coordinate formulas above. Then just figure out what heading the player needs to aim for that position.<br /> <br /> If you happen to have access to a vector math library, the equation (and the programming) becomes a lot simpler:<br /> [tex](\vec{x}_{t0}^2 - \vec{x}_{p0}^2) + 2\vec{x}_{t0} \cdot \vec{v}_{t}t + (\vec{v}_{t}^2 - \vec{v}_{p}^2)t^2 = 0[/tex][/itex]
 
Last edited:
Thanks a lot guys. This helps a lot.
 
hey diazona

Thanks for the formula, but one thing I noticed was that it doesn't take into consideration the angle my target is heading. I think with this formula it just gives me the time it will take if the player and target are heading straight for each other.

I think some trig needs to be involved in the formula as well.
 
nilum said:
For the most part I will only need to use the XY plane, but there are some instances where being able to figure in pitch would be handy.
You can always reduce this problem to 2D by doing the caluclation in a local coordinate system where the XY plane contains the target & player postions and the direction vector of the target.

As for the trigonometry, I would apply the http://en.wikipedia.org/wiki/Law_of_sines" to the triangle formed by the target, player and the planed interception:
You know the angle between player-target and target-interception (or target direction). And you know the ratio of the distances player-interception and target-interception: it is the player / target velocity ratio. So you can compute the angle between player-target and player-interception. Your program might have to handle some special cases and there is not always a solution (if the target is faster than the player).
 
Last edited by a moderator:
This is what I have so far:
P = (Xp,Yp) = Player Coordinate
T = (Xt, Yt) = Target Coordinate

What we need to do is create a triangle with the line PT, Target vector (Tv), and Player vectory (Pv).

The Angle of TvPT (that is the angle formed by the Target Vector and line PT) = the Angle of PvPT (that is the angle formed by the Player Vector and line PT)

The Inerception point is then where Tv intersects with Pv.

The final part is the velocity ratio. If Ps (Player Velcoity/Speed) is twice as much as Ts (Target Velocity/Speed) then the ratio is 2:1. So the angle PvPT is half (i.e. if it was 45 degrees it would be 22.5 degrees). If Ps (Player Velocity/Speed) is half as much as Ts (Target Velocity/Speed) then the ratio is 1:2. So the angle PvPT is twice as much (i.e if it was 35 degrees it would be 70 degrees).

The Interception point will still be where Tv intersects with Pv.

There will be some cases where Interception is not possible. It could be because the Target moves faster than the Player or Tv is 90 degrees or greater.

Knowing all this I am still having trouble coming up with a formula or a function. Any help?
 
Last edited:
nilum said:
This is what I have so far:
P = (Xp,Yp) = Player Coordinate
T = (Xt, Yt) = Target Coordinate

What we need to do is create a triangle with the line PT, Target vector (Tv), and Player vectory (Pv).

The Angle of TvPT (that is the angle formed by the Target Vector and line PT) = the Angle of PvPT (that is the angle formed by the Player Vector and line PT)

The Inerception point is then where Tv intersects with Pv.

Yes but first you compute the absolute value of angle PvPT:

|PvPT| = asin( sin(TvPT) * (target_velocity / player_velocity) )

Now to get the direction of Pv you rotate PT around P by a signed PvPT(multiply it with a http://en.wikipedia.org/wiki/Rotation_matrix" ). PvPT is negative (clockwise rotation) if (Xpt * Ytv) - (Ypt * Xtv) is negative (or the other way round, try it out).

There might be a simpler way using vector algebra only. Ask in some math / game programming forum.
 
Last edited by a moderator:

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 0 ·
Replies
0
Views
2K
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
10
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 40 ·
2
Replies
40
Views
5K
  • · Replies 6 ·
Replies
6
Views
3K