Results 1 to 15 of 15
 03162011, 05:40 PM #1Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
calculating the speed of moving point
hey,
i receive one set of x and y coordinates. the coordinates keeps on changing randomly. the x could increase and y could decrease or vise versa.
the x and y values could stop changing suddenly.
the x and y values could start increasing/decreasing very fast or very slowly.
the x value could increase/decrease but y value could stay the same or vise versa.
the input of x and y is received when the program is executed and the new values of x and y are fed to the program while the program is executing.
what i want is to calculate the speed of that moving point(x,y) , in pixels per second.
so if the point is not moving( x and y values do not change ) the speed should be 0
if the x and y values increase/decrees very fast the speed should change accordingly e.g 1000 pixels/sec
it should work in the similar concept as the car, once the driver sits in the car and starts the engine and if he or she does not know where and how far they going the speedometer would still be showing the speed at which the car is going
i do not know what distance the x and y will cover and i do not know the time for how long the program will be executed and how long the x and y values will be changing
i hope you understand what i need and will be able to help me.
thank you very much
any help will be greatly appreciated
 03162011, 06:02 PM #2
Do you know the distance formula? Just use it to determine distance each step, then take the average.
How to Ask Questions the Smart Way
Static Void Games  Play indie games, learn from game tutorials and source code, upload your own games!
 03162011, 06:11 PM #3Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
thanks for your reply
well i do know distance formula it would be speed = distance/time;
but as i said i do not know the distance and i do not know the time.
and i do not get any different stages in the program my x y moves all around the screen or just stops.
thanks
 03162011, 06:14 PM #4Senior Member
 Join Date
 Jan 2009
 Posts
 671
 Rep Power
 6
Speed is distance/time. To calculate the distance between two points,
Java Code:double delX = x2  x1; double delY = y2  y1; double d = Math.sqrt(delX*delX+delY*delY);
 03162011, 06:23 PM #5
The distance formula is not distance/time. That would not make sense. I meant the point distance formula.
I'm not really sure what you're saying about not getting different stages. If you want help with code, you'll have to post an SSCCE that demonstrates what you're talking about.
PS You really shouldn't post duplicate threads. It's really confusing to follow.How to Ask Questions the Smart Way
Static Void Games  Play indie games, learn from game tutorials and source code, upload your own games!
 03162011, 06:34 PM #6Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
thanks for this formula, but what would be the x2 and y2 i understand x1 and y1 is the current position of my point.
if x2 and y2 is the previous position, but which position would it be and when.
the coordinates change all the time think of it as a mouse cursor if you move it the speed of it would change according how fast you moving it and if you stop the speed should be zero.
mouse cursor does not have starting or ending position it just moves when you tell it to move and moves as long as you keep on instructing it to move. so how would the speed of it would be calculated
thank you
 03162011, 06:49 PM #7
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 13,447
 Blog Entries
 7
 Rep Power
 20
 03162011, 07:48 PM #8Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
sorry for double posting , new to this forum...
so if i store the coordinates lets say every 100 milliseconds. then i find the distance between the coordinates that i stored 100 milliseconds ago and now. so i have my distance which i would divide by 100 milliseconds this would have to show me the speed right?
am i on the right track?
thanks again
 03162011, 10:12 PM #9Senior Member
 Join Date
 Jan 2009
 Posts
 671
 Rep Power
 6
Yes, that's correct. The disadvantage of sampling fast is that you will end up with limited resolution. For example, if you are sampling so fast that there is never more than 1 pixel of motion, then your speed is going to alternate between 0 and 1/time_delta...which is probably not what you want.
What you're trying to do can be algorithmically challenging, because what you probably really want is a Kalman filter that is tolerant of noise and predicts what the speed is *now* instead of reporting what it *was*.
Best of luck!

Two similar threads merged together. Original poster, please don't double post the same question in multiple threads.
 03172011, 10:23 AM #11Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
yeah thats a problem it gives me the speed that *was* instead of what it is now. also the problem with the above solution is that if small range of coordinates has been covered very fast it would still be divided just after 100 miliseconds and it still would give me the avrage speed instead of the current speed.
Kalman filter that is tolerant of noise and predicts what the speed is *now* instead of reporting what it *was*.
thank you very much
 03172011, 10:33 AM #12could you tell me more about this kalman filter ?
db
 03172011, 11:51 AM #13Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
well i read about it but i am still very puzzled how could this be implemented in the code. and the theory of it is too hard to grasp for me cos my math knowledge is limited to my high school education.
could you please explain to me how Kalman filter could be used in my situation.
thank you very much
 03172011, 02:45 PM #14Senior Member
 Join Date
 Jan 2009
 Posts
 671
 Rep Power
 6
A Kalman filter is a statistical predictor. It's implementation is a signal processing question rather than a Java question.
 03172011, 03:29 PM #15Member
 Join Date
 Feb 2010
 Posts
 51
 Rep Power
 0
Similar Threads

Java Topology suit (JTS)  calculating point
By ArticRoot in forum New To JavaReplies: 4Last Post: 02222011, 02:54 PM 
Moving objects  setting different speed
By Antigol in forum Java 2DReplies: 2Last Post: 08142009, 01:14 AM 
How to speed sql Statements?
By bezudar in forum Advanced JavaReplies: 3Last Post: 11202008, 09:53 AM 
compare speed
By bbq in forum JDBCReplies: 1Last Post: 06282007, 05:34 PM
Bookmarks