MikeT
MikeT

Reputation: 5500

Calculating Intercepting Vector

I have 2 objects (i'll refer to them as target and interceptor). I know the target's current location and velocity. I know the interceptor's current location and speed it can travel.

From that, what I now need to know is :

i.e target @ (120,40) with a V(5,2) per second and interceptor @ (80,80) that can travels with a speed of 10 per second.

I've looked around and found plenty of ways to find out what point they meet and they all revolve around the angle between the two vectors and as I don't know the second vector and I can't calculate that and I'm getting lost trying to resolving this.

Any suggestions or guidance on how to proceed?

Upvotes: 5

Views: 6401

Answers (2)

Kevin
Kevin

Reputation: 76194

Given:

At time 0, the target is at point A and the interceptor is at point B. At some point in the future, they will intersect at point C.

line segment a is opposite point A, and likewise for b and B, and c and C.

enter image description here


We know the positions of A and B. We can derive the angle CAB from the target's heading. We know that the ratio of the lengths of line segments a and b equals (interceptor.speed/target.speed).

First, find angle CAB.
Let vector B^ be equal to the target's velocity.
Let vector C^ be equal to (interceptor.position.x - target.position.x, interceptor.position.y - target.position.y).
Determine the angle between them using the dot product formula.

B dot C = ||B|| * ||C|| * cos(angle)
cos(angle) = (B dot C) / (||B|| * ||C||)
angle = arccos((B dot C) / (||B|| * ||C||))

...Where "dot" is the dot product, and ||B|| is the scalar magnitude of vector B. angle is angle CAB.

Now we'll find angle ABC.
Using the law of sines, we know that sin(ABC) / b == sin(CAB) / a. Rearrange the equation into ABC = arcsin( sin(CAB) * (b/a) ).
We found CAB in the last step, and we know that b/a is target.speed/interceptor.speed, so plug those values in and find ABC.

Now that you know two angles and two points, you should be able to derive the position of C. Angle ACB is equal to 180 - (CAB + ABC) if you're using degrees, or Pi - (CAB + ABC) if you're using radians. Use the sine law to determine the lengths of sides b and c. Now you can find T using T = b / target.speed, and C using C = target.position + (target.velocity * T).


My C# is a little rusty, so here is a sample Python implementation instead. Let's plug in your sample values, and the result is:

Collision pos: Point(163.065368246, 57.2261472985)
Time: 8.61307364926
Angle A: 113.198590514
Angle B: 29.6680851288
Angle C: 37.1333243575
a: 86.1307364926
b: 46.3828210973
c: 56.5685424949

The position and time are the same as the ones found by gdir, so I'm pretty confident that both our approaches work.

Edit: MikeT: the C# version

public static double Dot(Vector a, Vector b)
{
    return a.X * b.X + a.Y * b.Y;
}
public static double Magnitude(Vector vec)
{
    return Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y);
}
public static double AngleBetween(Vector b, Vector c)
{
    return Math.Acos(Dot(b, c) / (Magnitude(b) * Magnitude(c)));
}

public static  Vector? Find_collision_point(Point target_pos, Vector target_vel, Point interceptor_pos, double interceptor_speed)
{
    var k = Magnitude(target_vel) / interceptor_speed;
    var distance_to_target = Magnitude(interceptor_pos - target_pos);

    var b_hat = target_vel;
    var c_hat = interceptor_pos - target_pos;

    var CAB = AngleBetween(b_hat, c_hat);
    var ABC = Math.Asin(Math.Sin(CAB) * k);
    var ACB = (Math.PI) - (CAB + ABC);

    var j = distance_to_target / Math.Sin(ACB);
    var a = j * Math.Sin(CAB);
    var b = j * Math.Sin(ABC);


    var time_to_collision = b / Magnitude(target_vel);
    var collision_pos = target_pos + (target_vel * time_to_collision);

    return interceptor_pos - collision_pos;
}

Upvotes: 7

gdir
gdir

Reputation: 952

You can compute the intersection with a 2D vector calculation. The target moves along a line. We know the starting point of the target, its direction and speed.

At any time t >= 0 the target is at point x defined by

enter image description here

where s_t is the starting point of the target (120, 40) and v_t is the velocity vector of the target (5, 2).

We know the interceptor's starting point (s_i), its speed (v_i), but not its direction. We can describe the interceptors range by a circle around the starting point, whose radius increases over the time. In vector calculus we get

enter image description here

where x is a point on the circle, s_i is the starting point of the interceptor (80, 80), r is the radius (or range) of the interceptor at time t, and v_i is the speed of the interceptor (10).

When the target and the interceptor meet at time t, their location x must be equal. We use the x of the line equation in the x of the circle equation and get

enter image description here

That's just a normal quadratic equation for t:

enter image description here

You can easily solve this. In this case you get a valid and an invalid solution:

t1 = -5.2328 => invalid because t must be >= 0

t2 = 8.61307

Now that you know t, you can compute the intersection point with the first line equation. Target and interceptor meet at (163.065, 57.223)

Upvotes: 12

Related Questions