MHB Complex Time, Distance & Speed

AI Thread Summary
The discussion centers on calculating the optimal firing time for a torpedo from a submarine to hit a moving ship in a 2D space. It outlines the need to account for the submarine's and ship's positions, speeds, and angles. The equations provided describe the trajectories of both the torpedo and the ship, leading to a system of nonlinear equations that can be solved using substitution methods. The use of the atan2 function is recommended for determining angles accurately. The conversation highlights the complexity of the problem, particularly when the ship's speed exceeds that of the torpedo.
DNA1
Messages
1
Reaction score
0
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 traveling - Speed);

The angle, distance of the sub and the ship will always be different.

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

DNA
 
Last edited by a moderator:
Mathematics news on Phys.org
You've given us a 2D problem. Let's keep this abstract. Suppose the ship's speed is the constant $v$, its bearing is $\theta$, and its initial position is $\langle x_{s0}, y_{s0} \rangle$. Let $r= \sqrt{x_{s0}^{2}+y_{s0}^{2}}$ be the initial distance from the sub to the ship. 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 $x$ axis.

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

Now, the ship's trajectory is quite simple: $\mathbf{x}_{s}= \langle x_{s0}, y_{s0} \rangle + tv \langle \sin(\theta),\cos(\theta) \rangle$. The torpedo's trajectory is also quite simple: $\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 $t$ such that $\mathbf{x}_{s}= \mathbf{x}_{t}$, or
$$ \langle x_{s0}, y_{s0} \rangle +tv \langle \sin(\theta),\cos(\theta) \rangle=tu \langle \sin(\varphi), \cos( \varphi) \rangle.$$
This is system for $\varphi$ and $t$ in two equations:
\begin{align*}
x_{s0}+tv \sin( \theta)&= tu \sin(\varphi) \\
y_{s0}+tv \cos( \theta)&= tu \cos( \varphi).
\end{align*}
Since the equations are nonlinear, I would opt for a substitution method. I'd probably solve one of the equations for $t$, and plug that into the other:
\begin{align*}
x_{s0}&=t \left( u \sin( \varphi)-v \sin( \theta) \right) \\
t&= \frac{x_{s0}}{u \sin( \varphi)-v \sin( \theta)} \\
y_{s0}&=t \left( u \cos( \varphi)-v \cos( \theta) \right) \\
&= \frac{x_{s0} \left( u \cos( \varphi)-v \cos( \theta) \right)}{u \sin( \varphi)-v \sin( \theta)} \\
y_{s0} u \sin( \varphi)-y_{s0} v \sin( \theta)&= x_{s0} u \cos( \varphi)- x_{s0} v \cos( \theta) \\
y_{s0} u \sin( \varphi)-x_{s0}u \cos( \varphi)&=y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta) \\
y_{s0} \sin( \varphi)-x_{s0}\cos( \varphi)&= \frac{y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta)}{u} \\
r \sin( \varphi+ \text{atan2}(-x_{s0},y_{s0}))&=\frac{y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta)}{u} \\
\sin( \varphi+ \text{atan2}(-x_{s0},y_{s0}))&=\frac{y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta)}{ru} \\
\varphi+ \text{atan2}(-x_{s0},y_{s0})&= \arcsin \left( \frac{y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta)}{ru} \right) \\
\varphi&= \arcsin \left( \frac{y_{s0} v \sin( \theta)-x_{s0}v \cos( \theta)}{ru} \right)
-\text{atan2}(-x_{s0},y_{s0}).
\end{align*}
The atan2 function is usually available in many programming languages. It's essentially the arctangent function, but without the usual ambiguity. That is, it'll return an angle in the correct quadrant.

If you find that these equations give you complex numbers as answers, that would be an indication that the system has no solution - entirely possible if the ship's speed is larger than the torpedo's speed and you're far away enough.
 
Last edited:
Seemingly by some mathematical coincidence, a hexagon of sides 2,2,7,7, 11, and 11 can be inscribed in a circle of radius 7. The other day I saw a math problem on line, which they said came from a Polish Olympiad, where you compute the length x of the 3rd side which is the same as the radius, so that the sides of length 2,x, and 11 are inscribed on the arc of a semi-circle. The law of cosines applied twice gives the answer for x of exactly 7, but the arithmetic is so complex that the...
Thread 'Unit Circle Double Angle Derivations'
Here I made a terrible mistake of assuming this to be an equilateral triangle and set 2sinx=1 => x=pi/6. Although this did derive the double angle formulas it also led into a terrible mess trying to find all the combinations of sides. I must have been tired and just assumed 6x=180 and 2sinx=1. By that time, I was so mindset that I nearly scolded a person for even saying 90-x. I wonder if this is a case of biased observation that seeks to dis credit me like Jesus of Nazareth since in reality...
Thread 'Imaginary Pythagoras'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...
Back
Top