How to calculate distance for moving objects?

Hi
Is there anyway in corona to calculate a distance of a moving object given that I have the velocity of that object. The start point can be determined, however the the end point is not set. The object is moving in straight line.

[import]uid: 167063 topic_id: 30477 reply_id: 330477[/import]

Hi there,

Could you clarify your question a bit more?

What I understand you to be asking is that you have an object where (1) you know it’s current position (the “start point” as you called it) and (2) you know it’s current velocity. When you say you are looking for the “distance” or “end point”, do you mean you want to know how far the object will travel before it stops?

The first question is, why should the object ever stop at all? Imagine an object floating in space, where there is no air friction and nothing to bang into. In space, an object will keep moving in a straight line forever. On Earth, of course, things eventually slow down due to friction (either air friction or friction sliding along the ground), or because they collide into something else. Which situation are you trying to simulate?

  • Andrew [import]uid: 109711 topic_id: 30477 reply_id: 122099[/import]

Hi
I have a moving object that is moving from point A at velocity X to an indeterminate point in a straight line. Start point is where the object has 0 velocity, then it moves toward another point (let’s call it B). Now while the object is moving toward point B but has not reached it yet, I want to know the distance between point A and the current object position.

Basically, I want to calculate how many meters (or KM) an object has passed. I am guessing that I want to simulate scenario 2 with some modifications.

Thanks [import]uid: 167063 topic_id: 30477 reply_id: 122106[/import]

I see. So if I understand you correctly, the velocity doesn’t matter, and all you want to know is the distance between the object’s current position and its initial position?

In general, the distance between two points (x1,y1) and (x2,y2) is sqrt((x1-x2)^2 + (y1-y2)^2).

So, in your situation, if you store [lua]x[/lua] and [lua]y[/lua] as the starting coordinates of your object, and [lua]obj.x[/lua] and [lua]obj.y[/lua] are the current coordinates of your object, the distance between them would be [lua]math.sqrt((obj.x-x)^2 + (obj.y-y)^2)[/lua].

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 30477 reply_id: 122124[/import]

Hi there,

Could you clarify your question a bit more?

What I understand you to be asking is that you have an object where (1) you know it’s current position (the “start point” as you called it) and (2) you know it’s current velocity. When you say you are looking for the “distance” or “end point”, do you mean you want to know how far the object will travel before it stops?

The first question is, why should the object ever stop at all? Imagine an object floating in space, where there is no air friction and nothing to bang into. In space, an object will keep moving in a straight line forever. On Earth, of course, things eventually slow down due to friction (either air friction or friction sliding along the ground), or because they collide into something else. Which situation are you trying to simulate?

  • Andrew [import]uid: 109711 topic_id: 30477 reply_id: 122099[/import]

Hi
I have a moving object that is moving from point A at velocity X to an indeterminate point in a straight line. Start point is where the object has 0 velocity, then it moves toward another point (let’s call it B). Now while the object is moving toward point B but has not reached it yet, I want to know the distance between point A and the current object position.

Basically, I want to calculate how many meters (or KM) an object has passed. I am guessing that I want to simulate scenario 2 with some modifications.

Thanks [import]uid: 167063 topic_id: 30477 reply_id: 122106[/import]

I see. So if I understand you correctly, the velocity doesn’t matter, and all you want to know is the distance between the object’s current position and its initial position?

In general, the distance between two points (x1,y1) and (x2,y2) is sqrt((x1-x2)^2 + (y1-y2)^2).

So, in your situation, if you store [lua]x[/lua] and [lua]y[/lua] as the starting coordinates of your object, and [lua]obj.x[/lua] and [lua]obj.y[/lua] are the current coordinates of your object, the distance between them would be [lua]math.sqrt((obj.x-x)^2 + (obj.y-y)^2)[/lua].

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 30477 reply_id: 122124[/import]