How To Track A Moving Object
There is a randomly moving object(obj1) on the panel. We have another object(obj2) that is supposed to track obj1 initiating from the (0,0) point on the panel. The obj2 must get closer to the obj1 as time passes.
What logic should I use to do this?
In my code, I have that obj1 moving aimlessly on the screen with a line pointing that object only from the (0,0) point.
I put a link here that can help me make myself clear.
Free Cloud Storage - MediaFire
Re: How To Track A Moving Object
Quote:
What logic should I use to do this?
That is indeed the question. What logic will you use? What would be the first step?
You said obj2 starts at 0,0 .... where is obj1 at that time?
So you will need to be able to get the location of obj1 to track it.
You will need to get the location of obj2 so you can know if obj2 has met obj1 or not.
You will also need to be able to tell obj2 to move to a position closer to obj1 than the current position of obj2 is.
So you will need some way to determine a good location to move to between obj1 and obj2.
Take these ideas and organize a plan to solve the problem. Also please post your code with your question, (on the forum), very few people click links.
Re: How To Track A Moving Object
Hi. thank you for your reply jps.
the current location of both objects are available, but one of the objects(the aircraft) will move randomly on the plane while the other object(the missile) has to set its next location and move there according to the new location that the aircraft has moved to. So first the aircraft moves and then we set the new location of the missile accordingly so that it will get closer to the aircraft.
I don't know how to write the code for this proces, I mean the process in which I find the next point to move the missile to. And of course the missile is supposed to move in a constant speed.
Re: How To Track A Moving Object
Quote:
I don't know how to write the code for this proces, I mean the process in which I find the next point to move the missile to.
It is not time to write code yet. Right now it is time to develop a process by which you can solve the problem. Once you have a process that solves the problem you write code to perform the process. Develop the process first and work on the code later. Once the process has been organized into steps make sure the process does in fact solve the problem while meeting any requirements before moving on to writing code.
Re: How To Track A Moving Object
I know that the process must be clear at first and then there must be the code!
I'm asking you to help me in the process! so please if you know just kindly help me and tell me how I can solve this problem.
thank you so much.
Re: How To Track A Moving Object
The obj2 must get closer to the obj1 as time passes.
In your words I assume.
Lets think about this. Obj2 must get closer to Obj1. .... 2 must get closer to 1.... (1 and 2 for short)
The first question I have is what is 1 and what is 2?
The second question I have is where is 1 and where is 2?
The third question I have is where to move 2 to? This will be based on several things.... What things?
--Well the current position of 1 (we already know this from above)
--The current position of 2 (we already know this from above)
--The speed of 2, well we will have to get that too..
Pick up where I left off. Or better yet start over and do it all in your own words. I have given you plenty to go on. See what you can come up with and include it in your next post.
Re: How To Track A Moving Object
Hi.
Well, this is part of a simulation in which there will be some Firing Stations(the user defines the position) and some randomly moving aircrafts(so they can be anywhere at any time) on the map.
There are also radars that will detect these aircrafts as they enter their zone. Then the radar must command the Firing Station connected to it so that it will fire a missile to target the aircraft. This missile is a smart one, meaning that it must track the aircraft as it moves so that finally hit it (like what happens in reality).
Obviously the speed of the missile must be higher than that of the aircraft.
The aircrafts fly in a steady speed. This is also true about the missiles but they are moving with a higher speed.
So in every step we have the coordinates of the missile and the aircraft.
In my question I asked, to simplify the question I assumed that the missile will always be fired from the (0,0) coordinates.
The link I had droped in my first question can help me a lot in making myself clear.
So what do you think I must do now?
Thank you so much for the time.
Re: How To Track A Moving Object
Quote:
The link I had droped in my first question can help me a lot in making myself clear.
There is no need to be more clear. Your point was made clear in the first post. I (and others) fully understand what you are trying to accomplish. However no one is going to do it for you.
Quote:
So what do you think I must do now?
I think you should read everything I said so far, since it is the same thing written different ways, and you still have not done so.
You need to write down a step by step process which will solve the problem. Note that this has nothing to do with code yet.
Quote:
Obviously the speed of the missile must be higher than that of the aircraft.
ok
Quote:
The aircrafts fly in a steady speed.
Not necessary to know this fact as long as the above is true
Quote:
This is also true about the missiles but they are moving with a higher speed.
Same for this but ok
Quote:
So in every step we have the coordinates of the missile and the aircraft.
Now this is some useful information. How you get this information will be part of the solution.
It all boils down to this: If you don't know how to write the code for it, you need a guide. The guide is what I am trying to get you to write up. The process of getting locations, doing some work to determine the heading of the missile, and repeating the process until the missile has hit the aircraft.
Two reasons why I don't write it for you.
1)You have to learn how to solve your own problems. (This is what we help with, we do not directly help with writing code.)
2)Since I don't know anything about the existing code, there is little chance I would offer advice that fit your code correctly. (Short of the very general advice given so far)
I would say the missile movement would be part of the missile class. A reference to the aircraft being targeted would be passed to the missile as the missile was fired (possibly this is when the missile is created so perhaps in the constructor). The missile could then get the target's location and adjust heading on each tick.
I'm going to insist you put some effort in before your next reply, or have a good question about where you are stuck.