14
\$\begingroup\$

I have a missile that is shot from a ship at an angle, the missile then turns towards the target in an arc with a given turn radius. How do I determine the point on the arc when I need to start turning so the missile is heading straight for the target?

EDIT

What I need to do before I launch the missiles is calculate and draw the flight paths. So in the attached example the launch vehicle has a heading of 90 deg and the targets are behind it. Both missiles are launched at a relative heading of -45deg or + 45 deg to the launch vehicle's heading. The missiles initially turn towards the target with a known turn radius. I have to calculate the point at which the turn takes the missile to heading at which it will turn to directly attack the target. Obviously if the target is at or near 45 degrees then there is no initial turn the missile just goes straight for the target.

After the missile is launched the map will also show the missile tracking on this line as indication of its flight path.

What I am doing is working on a simulator which mimics operational software. So I need to draw the calculated flight path before I allow the missile to be launched.

Two missiles aimed at two targets

In this example the targets are behind the launch vehicle but the precalculated paths are drawn.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Is the heading precalculated or does it change during trajectory? (like a homing missile?) \$\endgroup\$ Jun 15, 2011 at 8:55
  • 1
    \$\begingroup\$ Wouldn't it just be when (x2-x1)^2 + (y2-y1)^2 = r^2, where (x1,y1) is the current missile position and (x2,y2) is the target? \$\endgroup\$ Jun 15, 2011 at 10:02
  • \$\begingroup\$ Maybe you should make drawing of what you want. \$\endgroup\$ Jun 15, 2011 at 11:10
  • 3
    \$\begingroup\$ Is this a 2D or 3D problem? \$\endgroup\$
    – Steve H
    Jun 15, 2011 at 15:08
  • \$\begingroup\$ If you are looking for something like a homing-missile, you can do it without using any trigonometry. See this question \$\endgroup\$ Jun 16, 2011 at 16:41

5 Answers 5

9
\$\begingroup\$

My math might be a bit wrong, so I have wikied the answer.

I assume you want to do the continually homing scenario - where the missile P1 travelling at a velocity V1 constantly tries to turn toward the player P2; but at a limited turning rate.

  1. Determine the vector between the player and the missile.

    V2 = P2 - P1
    
  2. Turn them into unit vectors.

    V3 = UNIT(V1)
    V4 = UNIT(V2)
    
  3. Determine the angle between the vectors.

    a = ARCCOS(V3 * V4) (* indicating dot product)
    
  4. Limit the value of the angle between them (remember your trig functions probably work with radians, so try 0.1 as the turning rate).

    a = SIGN(a) * MINIMUM(ABS(a), MaximumTurningRate)
    
  5. Create the new movement vector.

    V1 = UNIT(V3.x + SIN(a), V4.y + COS(a)) * MissileSpeed
    

EDIT: This has no 'starting point' as it is a more robust (and is an easier implementation) for the continually homing scenario. You don't need to find a starting point for a circle - just limit the rate at which the missile can change direction and the rest happens because of the ghost in the machine.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ Mmm... if memory serves, I think that you need to do a cross-product to get the direction of the angle. If you just do a dot product, you will know the magnitude of the angle but not the direction (as dot products can have V3*V4 = V4*V3, there seems to be no way to note difference in orientation). So, do the dot product, and then do a cross product--checking the sign of the Z coordinate--to find the orientation. \$\endgroup\$
    – ChrisE
    Jun 16, 2011 at 16:54
  • \$\begingroup\$ @ChrisE The example is in 2D (looking at 5.), so the original orientation and the angle magnitude should be sufficient. \$\endgroup\$
    – Keeblebrox
    Jun 23, 2011 at 18:14
  • \$\begingroup\$ Calculating the angle between is correct, but I'm not sure what your stated intention with step 5 is OR what it produces. Is step 5 suppose to add the angle a to the v3 because I don't understand the math. \$\endgroup\$
    – dlots
    May 11, 2013 at 12:45
  • \$\begingroup\$ @dlots step 5 is supposed to add the new 'limited turn rate angle' to the current movement vector - basically it changes the direction of the missile. \$\endgroup\$ May 13, 2013 at 8:52
  • \$\begingroup\$ What is SIGN in step 4? \$\endgroup\$ Sep 11, 2013 at 3:23
2
\$\begingroup\$

I assume you want to change the direction by changing the launching heading to the target heading then continue straight to the target (a more fun problem should be to hit the target when turning!).

I have to assume that you are able to turn with the same turn radius in all direction (this is a simplification that is hard to see in real missiles).

The simplest solution is to use the 90° bending: the missile files until its trajectory forms a right angle with the target. if you turn exactly at the 90° point you will miss the target exactly by the turn radius, because you have to take into account the turning itself. The solution is to start to turn exactly "turn radius" meters(?) before reaching the 90° point, then turn forming a (try to guess) 90° arc to go straight to your target.

This solution is not always feasible, for example when you don't have the visibility on the 90° path (buildings or other obstacles).

The good news is that the solution works for every angle (not just the mythical 90°) the trick is to take in account the space needed to turn starting turning before.

How much before? This is why the 90° stuff is the simplest solution...

Let's say that you reach the visibility or the best target heading when the firing path forms an angle of θ° then you should anticipating the turn by:

(sec(90° - θ°) + tan(90° - θ°)) * turning_radius

...where secant is the reciprocal of the cosine. The proof is trivial and is left to the reader.

Seriously, the formula comes from a simple geometrical construction.

Turning point graph

Black line is the firing path, while the thin black line is the same path moved toward the target by turning_radius units; the same for the red ones that are the target path.

The green segments are turning_radius in length so you should see that:

AB is the tangent of 90° - θ°

BC is the secant.

Both of the green lines that come from the turning point are turning_radius in length and are perpendicular to the two paths; meaning that the turning radius is correct and the arc is tangent to both of the paths (as it should be if you make a turn under physical constraints).

Let me know if you see some error.

EDIT:

The drawing you are posted shows that there are multiple choices for path even with fixed shooter and target as you can see here:

enter image description here

Once the target is choosed you can apply what i said above with the proper angles.

\$\endgroup\$
1
  • \$\begingroup\$ Please note that this is not a continuous updating system. Since homing requires more cpu (a lot), this should be consider the right approach for fixed targets or if one whant to implement a "semi-dumb" missile of course. The trajectory can be simply parametrized over t splitting the path in 3 subpath and the arc can be approximated by a Bezier curve. \$\endgroup\$
    – FxIII
    Jun 17, 2011 at 7:05
1
\$\begingroup\$

I'd implement a "steering behaviour" for the missle. The missile has: A velocity(a number), a position(a vector) and a (current)rotation. At each update in your game / at each frame, the missle's rotation is changed just a bit (towards the target). Then the missile is moved forward according to its current rotation and current velocity.

Works for 2D and 3D obviously, since the only difference is an additional dimension.

Another possibility would be to calculate the path of the missile before fiering it. Look up bezier curves or spline.

\$\endgroup\$
2
  • \$\begingroup\$ The problem with using a spline here is that you would need to continuously update the control points if the target moves. A simple steering algo here may be computationally cheaper. \$\endgroup\$
    – ChrisE
    Jun 16, 2011 at 16:57
  • \$\begingroup\$ Actually I'm trying to precalculate the path to the target. What I am working is a simulator for some real equipment and I am trying to mimic the real equipment's behaviour. \$\endgroup\$
    – Tony
    Jun 17, 2011 at 2:12
0
\$\begingroup\$

I feel like you're solving the wrong problem here. A real-world missile isn't going to worry about where to turn, it's simply going to turn until it's pointed at it's target. The only where-to calculation involved is when to start bringing the controls back to neutral as a real-world missile can't instantly change it's turn rate. That calculation will take only the missile's indicated airspeed as an input value and I would think would be precalculated.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ A real world missile especially the later weapons have inertial guidance systems or GPS or both in them so they get programmed to go to a search area and start looking for a target. Woe betide if a friendly is near by. The programming is supposed to enable you to send the missile on a path that avoids friendlies and other obstacles such as landmasses and innocent bystanders. \$\endgroup\$
    – Tony
    Jun 17, 2011 at 7:58
0
\$\begingroup\$

I think the simplest algorithm would just follow two rules:

  1. If the current target is closer to the missile than the turning diameter then keep going straight. This avoids the missile orbiting close targets instead of actually getting to them.

  2. Otherwise turn towards the target until you are pointing at it.

To calculate the point where the turn ends in 2D:

  1. At the point where you want to start turning, the centre of the turning circle is located in a direction perpendicular to the current heading at a distance of your turning radius. Note that there's two of those points - you probably want the one closest to your target. Calculate that position and call it P.

  2. You can now construct a right angled triangle with the right angle at the tangent, and two known points - P and your destination. This lets you calculate the distance from the tangent to your target point with Pythagoras. Call it D.

  3. Now you need to calculate the intersection of a circle of radius D at your destination with your turning circle. You'll get two solutions which are the two tangent points on that circle where the missile would stop turning (one for each direction of travel round the circle). Pick the point that is in front of the missile - that is your answer.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .