Complex Time, Distance & Speed

  • Context: MHB 
  • Thread starter Thread starter DNA1
  • Start date Start date
  • Tags Tags
    Complex Speed Time
Click For Summary
SUMMARY

This discussion addresses the mathematical problem of calculating the optimal firing time for a torpedo from a submarine to hit a moving ship on a 2D board. Key variables include the submarine's position and angle, the torpedo's speed, and the ship's position, angle, and speed. The solution involves deriving equations based on the ship's and torpedo's trajectories, leading to a system of nonlinear equations that can be solved using substitution methods. The atan2 function is recommended for angle calculations to avoid quadrant ambiguity.

PREREQUISITES
  • Understanding of 2D coordinate systems and vector mathematics
  • Familiarity with trigonometric functions and their applications in navigation
  • Knowledge of nonlinear equations and methods for solving them
  • Experience with programming concepts, particularly the atan2 function
NEXT STEPS
  • Implement the derived equations in a programming language to simulate torpedo targeting
  • Explore the use of vector mathematics in game development for realistic movement
  • Study the atan2 function in various programming languages for angle calculations
  • Research optimization techniques for real-time calculations in game physics
USEFUL FOR

Game developers, mathematicians, and anyone interested in physics simulations, particularly in the context of targeting systems in gaming applications.

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:

Similar threads

Replies
1
Views
2K
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 25 ·
Replies
25
Views
5K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 27 ·
Replies
27
Views
2K
  • · Replies 18 ·
Replies
18
Views
1K
  • · Replies 6 ·
Replies
6
Views
2K