Time, Distance & Speed help

DNA_Deliverer

New member
Joined
Feb 12, 2014
Messages
11
Hi all,

I'm currently developing a game app, but I've hit a math problem, which I'm hoping someone here could help me with.

The problem:

This is a 2D board, which has cords (x,y).
I have a sub facing e.g. north, that firers a torpedo(moving e.g. 30) and the same direction as the sub. The target is a ship (moving at e.g. 7) moving left or right.

So the problem is how do I calculate a targeting calculation that measures the distance and time, as to when to fire a torp so that it will hit the ship from a distance.
Now keep this in mind, the ship will not always be at right angle. It is more likely that it will be at an odd angle...

I can safely say I had more hair before I hit this problem.

To round off what objects and values are used:

1) Sub (Location in x,y - Angle (0-360) facing);
2) Torpedo (speed);
3) Ship (Location in x,y - Angle travelling - Speed);

Have fun losing sleep, thanks to anyone and everyone that trys to help :)

DNA
 
Just let me know if I haven't made everything clear or if you require more additional information.

Again thanks all.

DNA
 
Hi all,

I'm currently developing a game app, but I've hit a math problem, which I'm hoping someone here could help me with.

The problem:

This is a 2D board, which has cords (x,y).
I have a sub facing e.g. north, that firers a torpedo(moving e.g. 30) and the same direction as the sub. The target is a ship (moving at e.g. 7) moving left or right.

So the problem is how do I calculate a targeting calculation that measures the distance and time, as to when to fire a torp so that it will hit the ship from a distance.
Now keep this in mind, the ship will not always be at right angle. It is more likely that it will be at an odd angle...

I can safely say I had more hair before I hit this problem.

To round off what objects and values are used:

1) Sub (Location in x,y - Angle (0-360) facing);
2) Torpedo (speed);
3) Ship (Location in x,y - Angle travelling - Speed);

Have fun losing sleep, thanks to anyone and everyone that trys to help :)

DNA

Which academic-class gave you this problem?
 
I think that parametric equations would help. That is, functions of time which output the x- and y-coordinates for both the ship and torpedo.

Does the ship always travel in a straight line?

Is the speed of the ship always the same constant?

Is the speed of the torpedo always the same constant?

Are the (x,y) coordinates for both the ship and the torpedo provided for some point in time?

If the answers to these four question are all "yes", then it seems like you need only determine (1) the direction to aim the torpedo, and (2) the point in time to fire the torpedo. Is this your understanding?
 
Thanks for the reply.

The ship will always travel in the same direction and speed. The torpedo has a set speed. The cords of the sub and ship are available.

Yes you are right, the direction and time is the information I need to come out of the calculation.

DNA
 
Well mainly the time, the sub will be facing one direction awaiting for the ship to enter the x time away from where the torpedo will hit.

When the sub gets into position, thats when the targeting calculation is done, hence is mainly just the time of firing.

DNA
 
If I were to this problem, I would:

Locate the ship (with co-ordinates) and draw a straight-line (fictitious) in the direction of its travel - find the equation of this line

Locate the submarine (with co-ordinates) and draw a straight-line (fictitious) in the direction of its travel- find the equation of this line

Locate the point where these lines intersect

Knowing the speed of the ship - you can calculate when the ship will arrive at that point.

Now you need to calculate the speed of the torpedo (or location of the sub along the ) line to make sure that the torpedo and the ship arrive at the point at the same time.

Then you can claim - I sank your battle-ship!!

Tell us what do you get.
 
If I were to this problem, I would:

Locate the ship (with co-ordinates) and draw a straight-line (fictitious) in the direction of its travel - find the equation of this line

Locate the submarine (with co-ordinates) and draw a straight-line (fictitious) in the direction of its travel- find the equation of this line

Locate the point where these lines intersect

Knowing the speed of the ship - you can calculate when the ship will arrive at that point.

Now you need to calculate the speed of the torpedo (or location of the sub along the ) line to make sure that the torpedo and the ship arrive at the point at the same time.

Then you can claim - I sank your battle-ship!!

Tell us what do you get.

This is how I visualise the problem, but its turning it into a formula, which is eluding me.

DNA
 
This is how I visualise the problem, but its turning it into a formula, which is eluding me.

DNA

There is no standard formula - you have to do it step-by-step!

Show your steps - and you will see you'll arrive at the expression!

Show your steps.

for example -

how did you express the first line mathematically (along which the ship is traveling)?

how did you express the second line mathematically (along which the sub/torpedo is traveling)?
 
The route the ships will take is randomised, thus they do not come from the same direction.

As with the sub, the player moves the sub around to position the sub in the best location in which to attack the coming ship.
 
The route the ships will take is randomised, thus they do not come from the same direction.

As with the sub, the player moves the sub around to position the sub in the best location in which to attack the coming ship.

When the sub wants hit a particular ship -

The location and velocity of the "victim" ship is known - yes?

The location and velocity of the "agressor" sub is known - yes?
 
This nice bloke (in the quote below) posted a formula, now it looks sound but could someone check it over and translate it into English for me lol...

Ackbach said:
You've given us a 2D problem. Let's keep this abstract. Suppose the ship's speed is the constant \(\displaystyle v\), its bearing is \(\displaystyle \theta\), and its initial position is \(\displaystyle \langle x_{s0}, y_{s0} \rangle\). In the navy, a "bearing" is a measure, in degrees, of the ship's direction, where North is zero, and positive angles are clockwise. This is in contrast to typical mathematics, where angles are positive counterclockwise, and are measured relative to the positive \(\displaystyle x\) axis.

Suppose also that the torpedo has a constant speed \(\displaystyle u\), at a bearing \(\displaystyle \varphi\).

Now, the ship's trajectory is quite simple:

\(\displaystyle \mathbf{x}_{s}= \langle x_{s0}, y_{s0} \rangle + tv \langle \sin(\theta),\cos(\theta) \rangle\)

The torpedo's trajectory is also quite simple:

\(\displaystyle \mathbf{x}_{t}=tu \langle \sin(\varphi), \cos( \varphi) \rangle\)

Here I've set the origin at the submarine. What we want is a single time \(\displaystyle t\) such that \(\displaystyle \mathbf{x}_{s}= \mathbf{x}_{t}\), or

\(\displaystyle \langle x_{s0}, y_{s0} \rangle +tv \langle \sin(\theta),\cos(\theta) \rangle=tu \langle \sin(\varphi), \cos( \varphi) \rangle\)

This is an overdetermined system for \(\displaystyle \varphi\), because it's really two equations:

\(\displaystyle \begin{align*}
x_{s0}+tv \sin( \theta)&= tu \sin(\varphi) \\
y_{s0}+tv \cos( \theta)&= tu \cos( \varphi).
\end{align*}\)

So you should solve one of these for \(\displaystyle \varphi\), and then check that the other equation is satisfied. If either cannot be satisfied, then you can't hit the ship. Solving the first equation, for example, yields

\(\displaystyle \varphi= \arcsin \left( \frac{x_{s0}+tv \sin( \theta)}{tu} \right).\)

Then you just check that the other holds.
Thanks to those who have taken the time to post, up to now :grin:
 
Last edited:
P.S. I would have linked and credited the person who gave the above formula but was unsure if it was against form rules.
 
Top