Google Answers Logo
View Question
 
Q: Heat Seeking Missile Algorithm ( No Answer,   1 Comment )
Question  
Subject: Heat Seeking Missile Algorithm
Category: Computers > Algorithms
Asked by: evanstaul-ga
List Price: $10.00
Posted: 29 Oct 2002 19:12 PST
Expires: 16 Nov 2002 10:00 PST
Question ID: 92714
I would like a computer algorithm, preferably in Java or C/C++.  Its
kinda physics-like.  I'm not sure if this is easy for most
programmers, or easily found on the web.  It also should have lots of
comments in the code so I can easily understand and learn from it. 
This is for a 2D demo.

There is a heat seeking missile, that has a top (tip) and bottom (base
or thruster).  There is gravity, a certain amount of fuel, and a
maximum speed.  When first launching this missile it will have a speed
of 0 and steadily increase to the maximum speed and to the target.  If
the target moves, the missile will adjust and follow, turning
accordingly.  The speed won't always start at 0, it could be fired
from a moving object.

It should act like real missile, but of course doesn't have to be too
real.  For example lets say on screen there is a missile facing up on
the ground, and a target helicopter flying across the screen far to
the right.  The missile will launch, slowly accelerating, and turning
right towards the copter (like a car, it cannot turn without moving
forward).  If the helicopter rises up to avoid it, the missile will
then try to turn upwards.  It may miss if the target's angle is too
sharp and have to angle its way towards it.  If the copter moves
around enough that the missile wastes its fuel, it will fall
to the ground.

Here is what the Missile object might look like: 

class Missile {
   double x,y; //Location on screen, ground=y=0, air=negative
   double angle; //The angle of the missile, tip and base 0=up
   double speed,max_speed;
   double acceleration,weight;
   //Possibly a lot more variables

   void start(int x,int y);
   void seek(int x,int y); //Heat seek to this coordinate
}

Thanks!

Clarification of Question by evanstaul-ga on 30 Oct 2002 16:39 PST
I was thinking that this kind of algorithm is very common in games and
could be found on the web somehow in one computer language or another.
 So far I can't find it easily on the web.  If one of the researchers
were a programmer they could find the algorithm, or something close to
it, and:

1) If it was a different language like Pascal, Basic, then convert it.
2) If it were pieces of a larger code then cut the minimal code and
show it.
3) Or explain/comment it well enough that I could do it myself.

This site contains some interesting behaviors:
   http://www.atomicmedia.com/autonomous/

The seek function, probably the only piece of code Ineed to do this,
would be something like:

//Pseudo java code, do the next frame of animation
void seek(int target_x,int target_y) {
   //Find the slope of the target to missile
   slope_x=target_x/x;
   slope_x=target_y/y; //More stuff than this

   //Angle towards target
   if(angle>slope??) angle++;

   //Detection
   if(y>=0) explode=true; //Hit floor
   els if(x==target_x&&y==target_y) explode=true; //Hit target

   //Add gravity
   y=y+GRAVITY;
}
  
Of course thats wrong, but I imagine the function would be kinda like
that.  So, I'm not expecting any graphics code or anything just the
basic physics of it.  I estimate it will go around one page of code. 
Pseudo code is fine too, but Java or C is preferred, because most of
the time when people write pseudo code it doesn't translate smoothly
to real code.

Request for Question Clarification by omniscientbeing-ga on 30 Oct 2002 19:02 PST
Are you interested in a real-world, guided-missile design approach to
this question, or just enough to create a computer or video game? I
have an Answer prepared for the former, if you are interested, but it
looks as though you are only playing games here.

~omniscientbeing-ga

Clarification of Question by evanstaul-ga on 30 Oct 2002 20:20 PST
I don't want a real world stuff, just 2D and enough to make a demo out
of.  Some source code and a nice explanation of how it works,
especially the mathematics, and physics of it.  Thanks.
Answer  
There is no answer at this time.

Comments  
Subject: Re: Heat Seeking Missile Algorithm
From: halcyon985-ga on 29 Oct 2002 23:32 PST
 
Dude you seem to know what your doing, I'm not writing your comp sci
project for you!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy