Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: How To Track A Moving Object

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How To Track A Moving Object

    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.

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How To Track A Moving Object

    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.

  5. #5
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  6. #6
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default 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.

  7. #7
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: How To Track A Moving Object

    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.

    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.

    Obviously the speed of the missile must be higher than that of the aircraft.
    ok

    The aircrafts fly in a steady speed.
    Not necessary to know this fact as long as the above is true

    This is also true about the missiles but they are moving with a higher speed.
    Same for this but ok

    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.

Similar Threads

  1. [SOLVED] Keeping Track
    By Nuggets in forum Loops & Control Statements
    Replies: 2
    Last Post: April 15th, 2012, 05:37 PM
  2. keep track of objects
    By keep smiling in forum Java Theory & Questions
    Replies: 4
    Last Post: February 20th, 2012, 03:44 PM
  3. Replies: 3
    Last Post: November 10th, 2011, 07:11 AM
  4. keeping track of array taht holds object
    By jack_nutt in forum Java Theory & Questions
    Replies: 1
    Last Post: June 20th, 2011, 11:17 PM
  5. Track the user session list
    By kalees in forum Java Servlet
    Replies: 3
    Last Post: October 24th, 2009, 02:34 PM