Public Group

# Help calculating x,y position of traveling ship

This topic is 3304 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I've got a ship in traveling and I want to represent it's location on a 2d map. The ship starts at an X,Y which is known and ends at a known X,Y. I also know the time the fleet started moving and how long it'll take to arrive. Using that info, is there a way to determine what x,y the ship would be at at a given time into the trip? Like say I wanted to know current, I could calculate the time traveled so far as 10 minutes, and use that to derive the current X,Y... Thanks for any help. Chu EDIT: I should point out that accelleration is constant in my game.

##### Share on other sites
Let startpos=(X,Y), endpos=(Xfinal, Yfinal). Then:

dir = endpos-startpos

intermediateposition = startpos + dir*(elapsedtime/wholetimeoftrip)

Hopefully this makes sense, the position you want is just the start position + the direction of movement scaled by the current time of travelling compared to the total time.

##### Share on other sites
I'm assuming you meant constant speed (therefore acceleration too).

In the following equations these variables are used:
In:
"ship starts at an X,Y" -> startX, startY
"ends at a known X,Y" -> endX, endY
"time the fleet started moving" -> startTime
"how long it'll take to arrive" -> tripTime
Out:
"what x,y the ship would be at at a given time" -> curX, curY

Plug the result of the first equation into the other two to get the ship's (X, Y) coordinate.

relTime = (curTime - startTime) / tripTime
curX = startX + (endX - startX) * relTime
curY = startY + (endY - startY) * relTime

1. 1
Rutin
34
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
633334
• Total Posts
3011410
• ### Who's Online (See full list)

There are no registered users currently online

×