Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Analytical Firi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 590 of 670
Post > Topic >>

Analytical Firing Solution...

by "m0rdred" <idlerstyle@[EMAIL PROTECTED] > Oct 27, 2006 at 02:52 PM

Ok to start off, I know there may be other ways to attack this problem,
but I want the analytical way first, regardless of complexity and
flexibility issues that may arise.

Description of the problem:

I have two moving platforms, both are space ships operating in a
gravity free environment(for now).  I want to calculate the firing
solution for one ship to hit another with a projectile.  The projectile
doesn't move any faster than 3 or 4 times as fast as the ships
themselves.  When fired the projectile incorporates the ships vector
into its vector and is therefore affected by the ships movement when
launched.  I have established a MoveVector class that has two private
datamembers, angle and magnitude.  This is for storing vectors in the
polar coordinate form(am i correct with that?) rather than the
component form.  However I can produce the components merely by calling
a function to convert and retrieve both the x and y component(2d
graphics and calcs for now).  I have looked on the web for
conversations regarding this.  Let me share what I have so far based
off of these posts.  The following is pseudo code- some of my c++ stuff
and some more explanatory...  Note: this is for computer AI so theEnemy
is the ship that is trying to get a solution on theTarget.

//show you my knowns
MoveVector vToTarget;  //stores the angle to the target and distance or
magnitude to it
MoveVector theTarget.getVect(); //stores the angle/direction and
magnitude or speed that the target //is moving
MoveVector theEnemy.getVect(); //same as above

//show you my unknowns
t time is an unknown- because you dont know how long it will take to
reach the other ship while it is in flight.  however, i think it is
unneccesary to know this. i think t would be measured in passes through
my main game loop if it was needed.
theEnemy.getTheta(); theta is another variable of my shipclass
unrelated to the vector- it is the direction the ship is pointing and
in this case it is the aiming of the shot to be fired. it is what we
want to know.
distance ship will travel before being hit //this is unknown and is a
function of time
distance projectile will travel before hitting the ship// this is also
unknown and a function of time
angle between the vectors the ship and the projectile will make to
collide

//now i am going to show some pseudocode not using my MoveVector class
for now- for clarity
ProjX, ProjY //location of the projectile
TargX, TargY //location of the Target
velocityOfProjectile //this is the velocity vector for the projectile-
velProjX, velProjY //components of velocity vector for the projectile
velTargjX, velTargY //components of velocity vector for the target
theta// this is the variable i want to solve for- in my ship class it
is a datamember that refers to the direction the ship is pointing in


//position formula Pnew = Pold + Vel * Time; Pnew or new position
should match for both the

ProjX + t * velProjX  = TargX + t * velTargX; ProjY + t * velProjY =
TargY + t * velTargY

//knowing that the components are made up of:

velProjX = velocityOfProjectile * cos(theta); velProjY =
velocityOfProjectile  * sin(theta).

//substitute velocityOfProjectile * cos(theta) for velProjX:

ProjX + t * velocityOfProjectile * cos(theta) = TargX + t * velTargX

//solve for t and algebra steps get you:

t = (TargX - ProjX) / (v * cos(theta) - velTargX) //and
t = (TargY - ProjY) / (v * sin(theta) - velTargY)

//t should be the same for both so substitute and lose t all together

(v * sin(theta) - velTargY)(delta_x) = (v * cos(theta) -
velTargX)(delta_y)

//where:

delta_x = TargX - ProjX, delta_y = TargY - ProjY.

//now we need to solve for theta- but I am at a loss as to how to
proceed. the post that i got most of this from used:

(sin^2(z) + cos^2(z) = 1)

//to make

cos^2(z) = (1-sin^2(z) )

// and plug it in here

(v * sin(theta) - velTargY)(delta_x) = (v * (1-sin^2(z) ) -
velTargX)(delta_y)

//but cos^2(z) != cos(z) right??? That isnt possible, is it?  If so
explain.  If not, any ideas of where to go now?

I was thinking if I could get the sin(theta) over the cos(theta) I
could go tan(theta) and that would help a bunch.

Thanks
Scott I




 4 Posts in Topic:
Analytical Firing Solution...
"m0rdred" <i  2006-10-27 14:52:53 
Re: Analytical Firing Solution...
nathan@[EMAIL PROTECTED]   2006-10-27 23:36:39 
Re: Analytical Firing Solution...
"m0rdred" <i  2006-10-27 18:17:11 
Re: Analytical Firing Solution...
nathan@[EMAIL PROTECTED]   2006-10-28 02:28:09 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 7:00:27 CDT 2008.