Jump to content
  • Advertisement
Sign in to follow this  
BlackDragon

Projectile Leading Problem

This topic is 4585 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 am trying find a solution to the problem below. The problem is for a tech test in which we are allowed research the problem in order to find a solution. I am having some trouble trying to figure out what exactly the question is looking for. Given an initial shot position (Spos), a constant shot speed (Sspeed), an initial target position (Tpos), and a constant target velocity (speed + dir) (Tvel) derive the equation for calculating the shot direction (Sdir) such that at some time (t) the shot would hit the target. Be sure to derive an equation for t as well! Write a function to compute these values (Sdir and t). So far all I have come up with is: Tpos - Spos = Dif(the diffrence between the two points) if I normlize the diffrence will that give me the direction vector? And if so then All I would need to do is Dif / Sspeed = t? Thanks

Share this post


Link to post
Share on other sites
Advertisement
The question is asking you to come up with an equation that determines how to hit a moving target.

"derive the equation for calculating the shot direction (Sdir) such that at some time (t) the shot would hit the target"

This means come up with a equation that computes the direction of your shot based on how long it takes for your shot to reach the target and the other stated parameters.

"Be sure to derive an equation for t as well!"

This means come up with an equation the computes how long it takes your shot to reach the target based (apparently) on the direction of the shot and the other stated parameters.

It might help to draw a picture.

Share this post


Link to post
Share on other sites
You face a problem, which may in some cases may never have an answer.

Consider where T moves faster than the projectile but parallel to it.

A possible approach is to simulate the environment, starting at time T0 and then increasing it with Delta

so
T = 0
Delta = 1

while (abs(Distance(FinalTargetPos,Spos) - R) < DesiredAccuracy)
{
R = T * ProjectileSpeed;
FinalTargetPos = TPos + Tvel*T;
switch of Distance(FinalTargetPos,SPos)
{
> R :Delta++;
< R : Delta /= 2;
== R: Bail
}
}

What you have at the top is a deriviation of Binary Searching, ones that is comple you can simple calculate the Direction Vector like this
Direction = FinalTargetPos - SPos;
----------------------------------------------
The above psuedo doesnt consider accuracy but you may argue that the Target is 10x10x10 and thus an accuracy of +-5 garuantees a hit

Share this post


Link to post
Share on other sites
There is a straightforward solution (and it is nothing like dawidjoubert's), but I doubt being "allowed to research the problem" includes asking someone to give you the answer. So I'm going to let you figure it out.

Share this post


Link to post
Share on other sites
JohnBolton is correct there is a straight forward method, but why shouldnt we tell you?
-------------------------
[Source]
C ****^
***** |G
**** F A|
Spos -------------->Tpos
D
[/Source]
[/source]

They Simple want you to solve F, and once you have F u can easily get C
A = Direction of the Target,BEARING OF TARGET, lets for this case say its 90 degrees
D = Distance Spos,Tpos
C = Projectile Speed/Magnitude * T
G = Target Speed/Magnitude * T

Because we have C & G & A we can use the sine rule to get

sin(90) sin(F)
-------- = ---------
C G

asin(sin(90)*G/C) = F

G/C = Target Velocity * T / Projectile Speed * T
thus
G/C = Target Velocity / Projectile Speed

Thus the Angle at which the Shooter must aim is

Angle = asin(sin(90)*Magnitude(TargetVelocity)/ProjectileSpeed);
And then u can simple do more substitution to get T
------------------------------------------------------------------------

Translating this into 3d is what you are left to do.

Share this post


Link to post
Share on other sites
Quote:
Original post by dawidjoubert
JohnBolton is correct there is a straight forward method, but why shouldnt we tell you?


Because he's taking a test and you are helping him cheat.

Share this post


Link to post
Share on other sites
Having someone just straight up give me the answer is not what im looking for. It would do me no good to complete the test and perhaps get a job in which I would not have been able to get using my own knowledge only to get fired a few weeks later. I was looking for help in finding the solution and being able to understand the solution vs just being given a solution.

Thanks

Share this post


Link to post
Share on other sites
So far no one is correct.

Angle = asin(sin(90)*Magnitude(TargetVelocity)/ProjectileSpeed);

Wrong because sin(90) = 1, so you are doing useless calculations here. What you are getting is not the angle, but an arbitrary value based on the ratio of the target's velocity and the projectile speed.

Dist = Tpos - Spos
Dir = Tvel - Sspeed
t = Dist / Tvel

Dist is true, but how does that help you? The target is moving. If you aim where it is now, when you get there it wont be there anymore.

Dir is incorrect because sSpeed is a scalar value, and you can not subtract vectors and scalars.

t is wrong because you cant divide vectors either. t is defined as a quadratic function, at^2 + bt + c. I will not give you the specifics, as this is the answer ;)

This problem is very complex, and a good physics/calc/math background is required to get to the solution. The iterative method is the easiest way to solve it, and it causes the least amount of dizzyness, but it is also extremely slow in most cases (unless you just get lucky and guess really close on the first divide).

Let me give you this bit of help:

The location of the target at any given time t is going to be tPos + Normal(tVel)*t, which is to say the starting position (tPos) + the velocity of the target (tVel) * the amount of time it moved at that velocity (which is constant, so no worries). The same is true for your projectile, except you dont know the velocity because you dont know its direction (you only know its magnitude). The trick is solving for time first, which proves very difficult without the velocity of the projectile, but it is possible!

You know how to find the location of the target and projectile at a given time t...and you know that when those two equations are equal (or very very near it), they are intersecting! You just need to find a way to get t into a quadratic form, so you can solve it for the correct time. Only one of the answers will be correct. You need a good physics (or calc) background to do this. There is also the case where they will never intersect, which you will need to find as well. As my physics teacher always said, "It's easy if you were paying attention, but if you weren't, you're going to fail!"

Share this post


Link to post
Share on other sites
Thanks for that insight, im glad to see that it is a very complex question which means im not a complete idiot (my binary/iterative thingy could work), how ever i will continue on my quest to solve this.

NOTE:U are wrong, in some cases there will be 2 possible answers, consider the Target moving faster than the projectile.

Imagine it will move closly past the SHootingPosition, then there will be 2 possiblities

A : Head on, The Projectiles Vector's head will point towards the Targets Vectors Head

B : Collsion Course, the two vectors will look in relatively the same direction and thus the Target will actually hit the projectile

How ever Bonehed316 i would greatly appreciate it if someone would post the solution once BlackDragon has solved it.

PS I didnt know he was doing an exam, must prob not have read the topic properly

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!