Projectile Problem
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).
Can anyone help me with this?
email me at shawndgarner@hotmail.com
What I have so far is:
newTargPos = targPos + (targSpeed * time) targDir;
I don't know if this is the right way to go about it.
[edited by - Juanman on May 14, 2002 11:20:35 AM]
This was discussed twice in recent threads. Make a search in the archive. The last one had asteroids and lasers in it. It also had a link to the first thread, which had the complete answer 
Cédric

Cédric
I looked at one article with Astroids. He was talking about things with variable speed which is not what I want. I also didn''t see any detailed solutions you were talking about. I did a search and only found the one article. I would appreciate links to both if you could find them.
Nope, not a homework question. A question for a game job programming test. They said I could research it. I've had only one physics class and never did stuff like this. I am going to the library tommorrow to try to find a good book but thought maybe I could save myself a trip if anyone knew how to do it.
[edited by - Juanman on May 14, 2002 12:11:08 AM]
[edited by - Juanman on May 14, 2002 12:11:08 AM]
May 14, 2002 10:05 PM
The new Game AI Wisdom book has an article that answers this very question.
I will look for that book at my University Library but I doubt they have it. You couldn''t post the answer or how to derive the answer could you? I did find the astroids post but didn''t quite clear things up for me.
well I did some reworking
p = interception point
pS = initial shot position
vS = direction + speed vector of bullet
t = time to intercept
pT = initial target position
vT = direction + speed vector of target
p = pS + vS * t;
p = pT + vT * t;
pS + vS * t = pT + vT * t
t = (pT - pS) / (vS - vT);
vS = ((pT - pS) / t) + vT
then the unit vector direction to shoot would be
vS/|vS|
But vS & vT are are vectors so how do you get a time number from subtracting two vectors and subtracting two points?
well I forgot about the scalar speed so here is the updated version
p = interception point
pS = initial shot position
vS = unit vector direction of shot
k1 = speed of bullet
t = time to intercept
pT = initial target position
vT = unit vector direction of target
k2 = speed of target
t = (pT - pS) / (vS * k1 - vT * k2)
vS = ((((pT - pS)/t) + vT * k2)/k1)
I still have the same question as above but was wondering if I could do this:
t = sqrt( (pT.x - pS.x) * (pT.x - pS.x) + (pT.y - pS.y) * (pT.y - pS.y) + (pT.z - pS.z) * (pT.z - pS.z) ) /
sqrt( (k1 * vS.x - k2 *vT.x) * (k1 * vS.x - k2 *vT.x) + (k1 * vS.y - k2 *vT.y) * (k1 * vS.y - k2 *vT.y) + (k1 * vS.z - k2 *vT.z) * (k1 * vS.z - k2 *vT.z) )
[edited by - Juanman on May 15, 2002 1:04:51 AM]
[edited by - Juanman on May 15, 2002 1:22:02 AM]
p = interception point
pS = initial shot position
vS = direction + speed vector of bullet
t = time to intercept
pT = initial target position
vT = direction + speed vector of target
p = pS + vS * t;
p = pT + vT * t;
pS + vS * t = pT + vT * t
t = (pT - pS) / (vS - vT);
vS = ((pT - pS) / t) + vT
then the unit vector direction to shoot would be
vS/|vS|
But vS & vT are are vectors so how do you get a time number from subtracting two vectors and subtracting two points?
well I forgot about the scalar speed so here is the updated version
p = interception point
pS = initial shot position
vS = unit vector direction of shot
k1 = speed of bullet
t = time to intercept
pT = initial target position
vT = unit vector direction of target
k2 = speed of target
t = (pT - pS) / (vS * k1 - vT * k2)
vS = ((((pT - pS)/t) + vT * k2)/k1)
I still have the same question as above but was wondering if I could do this:
t = sqrt( (pT.x - pS.x) * (pT.x - pS.x) + (pT.y - pS.y) * (pT.y - pS.y) + (pT.z - pS.z) * (pT.z - pS.z) ) /
sqrt( (k1 * vS.x - k2 *vT.x) * (k1 * vS.x - k2 *vT.x) + (k1 * vS.y - k2 *vT.y) * (k1 * vS.y - k2 *vT.y) + (k1 * vS.z - k2 *vT.z) * (k1 * vS.z - k2 *vT.z) )
[edited by - Juanman on May 15, 2002 1:04:51 AM]
[edited by - Juanman on May 15, 2002 1:22:02 AM]
The last thread on this subject concluded that it is easier to iterate to find the answer to this problem. I disagree, but I did not provide the complete analytical answer in the last thread and I don't know if it was provided in the first, so here it is:
What we know:
Ts : speed of the target
Bs: speed of the bullet
B : position of the shooter
T : position of the target
d: |T - B |
Unknown:
P : position of the target when the bullet reaches it
t: time
V : direction in which to shoot
Derivation:
This is nothing but a simple triangle problem. Two letters indicate an edge of the triangle (TB is the edge between T and B)
TB = d
TP = Ts * t
BP = Bs * t
By the law of cosines,
(Bs * t)² = (Ts * t)² + d² - 2Ts * t * d * cos(alpha)
So,
(Bs² - Ts²) * t² + 2Ts * t * cos(alpha) * t - d² = 0
This is a quadratic equation where only t is unknown. Solve for t.
Now that you have t, you can easily find P
P = T + Ts * t
And the direction to shoot.
V = P - B
I didn't double-check the maths, so if anybody finds a mistake, please post here and I will correct it. I say it's not much harder than the guess and correct approach and it's certainly more precise.
Cédric
[edited by - cedricl on May 15, 2002 4:33:11 PM]
[edited by - cedricl on May 15, 2002 4:38:23 PM]
What we know:
Ts : speed of the target
Bs: speed of the bullet
B : position of the shooter
T : position of the target
d: |T - B |
alpha: dot( (T - B ), Ts ) ---------------------- (|T - B | * |Ts |)
Unknown:
P : position of the target when the bullet reaches it
t: time
V : direction in which to shoot
Derivation:
This is nothing but a simple triangle problem. Two letters indicate an edge of the triangle (TB is the edge between T and B)
TB = d
TP = Ts * t
BP = Bs * t
By the law of cosines,
(Bs * t)² = (Ts * t)² + d² - 2Ts * t * d * cos(alpha)
So,
(Bs² - Ts²) * t² + 2Ts * t * cos(alpha) * t - d² = 0
This is a quadratic equation where only t is unknown. Solve for t.
Now that you have t, you can easily find P
P = T + Ts * t
And the direction to shoot.
V = P - B
I didn't double-check the maths, so if anybody finds a mistake, please post here and I will correct it. I say it's not much harder than the guess and correct approach and it's certainly more precise.
Cédric
[edited by - cedricl on May 15, 2002 4:33:11 PM]
[edited by - cedricl on May 15, 2002 4:38:23 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement