Sign in to follow this  

Linear Targeting

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a linear targeting system. I have the system of equations down, but the answer I get when I solve them doesn't seem like it can possibly be right. x1 + v1 t cos a = x2 + v2 t cos b y1 + v1 t sin a = y2 + v2 t sin b (x1, y1) is the position of a bullet I need to fire. (x2, y2) is the position of the target, and b is the angle the target is moving at. The two equations above are when the bullet and target will intersect. I need to find a, the angle to shoot the bullet at. Through my own work I came up with this: t = ((y2 - y1) - (x2 - x1)) / (v2 cos b - v2 sin b) I would then take this t and use it to solve for my angle. However, it can't possibly be right. Two things jump out at me: if the target is not moving I will get a divide by zero, and if the target is at 45 or 225 degrees I will get a divide by zero. I'm not sure where I went wrong, and showing all the work this way would take forever. Can anyone point me in the right direction?

Share this post


Link to post
Share on other sites
As a is unknown you don't know the postion of the bullet at time t but you know it lies on a circle as it has travelled a distance v1t from it's start. The equation of this is

(x - x1)2 + (y - y1)2 = (v1t)2


(x2 + v2t cos b - x1)2 + (y2 + v2t sin b - y1)2 = (v1t)2

This is a quadratic in t, so you should be able to solve it using the quadatic equation: it gives you in general two solutions. One of which may be negative so in the past, or they may be complex in which case there's no possible solution.

Once you have t you can substitute it into your original equations to get the position and so the angle.

Share this post


Link to post
Share on other sites
Quote:

Through my own work I came up with this:

t = ((y2 - y1) - (x2 - x1)) / (v2 cos b - v2 sin b)

I would then take this t and use it to solve for my angle.

However, it can't possibly be right. Two things jump out at me: if the target is not moving I will get a divide by zero, and if the target is at 45 or 225 degrees I will get a divide by zero.


You've eliminated v1 in order to get the expression for t. This means the v1 could have any value. Now, either you know your v1 and just need to find the angle, or you don't know your v1, and it is a free variable.

If the former, you've done something like this (where x and y are unkowns and a is known)

1) x = y * a
2) x = y + a

1) a = x/y
2) a = x - y

3) x/y = x - y
3) x = xy - y^2
3) x(1-y) = - y^2
3) x = y^2/(y-1)

In other words, you treated a constant as a varaible, isolated it, and subbed it back in. This doesn't actually help solve the problem as you haven't used the equations you have to isolate something that you can actually change. It's equivalent to trying to solve the problem using just one of given equations. In some cases, it does add in artificial singularities, like y = 1 in the above example, or the 45 degrees problem is your case (I think).


If, however, v1 really is an unknown, then you have 3 unknowns (v1, t and a), but only two equations, meaning something's going to be unspecified. In this case, you can vary v1 and a, so you can arbitrarily pick any t at which to satisfy your two given equations.


There is also the case where if v1 = v2, a = b, x1 = x2 and y1 = y2, then t is undefined, as no matter what t is used, the rays are coincident.


If v1 is known, what I'd suggest doing is isolate t in both equations you have, then equating them. Doing this gives me

(x2 - x1)/(v1*cos(a) - v2*cos(b)) = (y2 - y1)/(v1*sin(a) - v2*sin(b))

However actually solving this for a is rather difficult...

A better method might be to do what the first response post suggested, and find the time or point when the ray coming form (x2, y2) in direction (v1*sin(b), v1*cos(b)) intersects the circle of radius vt*t centred at (x1, y1). Knowing that you can get the necessary angle. If v1 is fixed though, there might not be such an intersection, as previous poster mentioned.

Share this post


Link to post
Share on other sites

This topic is 4817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this