Calculate the angle of Escape

226 Views Asked by At

There is a 200 meter long and 10 meter wide road (200, 0, 10); I am a pedestrian in the middle of the road at Vector3(100, 0, 5); I can run 6 meters per second fast.

A car with the width of 10 meters is driving on the road towards me. Means that I have to get off the road to avoid getting hit. The car has a speed of 50 meters per second, means it hits me in 2 seconds.

Now I want to calculate in which directions (Angle) I can run off the road to avoid the car in time before it hits me.

Visualized:

To calculate the maximum angle that I can run to escape the car, I tried the following already:

  1. Calculate the time it takes for the car to reach your current position, which is 2 seconds.

  2. Subtract the time it takes for you to reach the edge of the road when running straight towards the roadside (0.83 seconds) from the time the car takes to reach your current position (2 seconds). This gives you the maximum amount of time you have to reach the edge of the road when running diagonally towards the roadside: 1.17 seconds.

  3. For each angle θ, calculate the time it takes for you to reach the edge of the road using ((0.5 * roadwidth) / sin(θ)) / speed

  4. If the time calculated in step 3 is less than or equal to the maximum time calculated in step 2, then you can escape the car by running at that angle. Otherwise, you cannot escape the car in time.

  5. Repeat step 4 for a range of angles to find the maximum angle at which you can escape the car.

However, if I run diagonally against or away from the car towards the roadside, the car needs either more or less time than 2 seconds to reach me because I run towards or away from the car.

So I would have to add that to the calculation somehow?

Ultimately I want to calculate that in C++, maybe using a for loop via trial and error? Or is there a better algorithm for that?

I think the approach I'm doing is somewhat correct but there is probably some formular which can help me with that. Since I'm not the best in maths I'd appreciate it if someone could point me into the right direction :)

2

There are 2 best solutions below

4
On BEST ANSWER

Car $x$-position = $50 t$

Your position: $(100, 5) + 6 t (\cos \theta , \sin \theta) $

where $\theta$ is the angle your direction makes with the positive $x$-axis. It is assumed that $ 0^\circ \le \theta \le 180^\circ $.

To reach the sidewalk , consider your $y$ coordinate. This will give

$ t_1 = \dfrac{5}{6 \ \sin \theta} $

Next, consider the collision time, consider the $x$ coordinates, collision will occur if

$ 50 t = 100 + 6 t \cos \theta $

implies hitting time is

$t_2 = \dfrac{100}{ 50 - 6 \ \cos \theta} $

Now, we want $t_1 \le t_2 $, that is,

$ \dfrac{5}{6 \ \sin \theta} \lt \dfrac{100}{ 50 - 6 \ \cos \theta} $

Re-arranging the above inequality, we get

$ 250 - 30 \ \cos \theta \lt 600 \sin \theta $

i.e.

$ 600 \ \sin \theta + 30 \ \cos \theta \gt 250 $

The solution of this inequality is

$ 21.729^\circ \lt \theta \lt 152.546^\circ $

This is the safe range of $\theta $.

If $ 180^\circ \lt \theta \lt 180^\circ$ , then the safe range will be

$ (360^\circ - 152.546^\circ) \lt \theta \lt (360^\circ - 21.729^\circ) $

i.e.

$ 207.454^\circ \lt \theta \lt 338.271^\circ $

0
On

The distance to the edge of the road is $5\sec\theta$ (with $\theta = 0$ as the most direct path to the edge of the road)

If you get to the edge of the road, this will increase the distance from the starting point of the car by $5\tan \theta$

In order to survive:

$\frac {100 + 5\tan\theta}{50} < \frac {5\sec \theta}{6}$

And to maximize theta then the left-hand equals the right-hand side.

$6(100 + 5\tan \theta) < 250\sec\theta\\ 600 \cos\theta + 30\sin\theta < 250$

let $\phi = \arctan \frac {1}{20}$

$\cos \phi = \frac {20}{\sqrt {20^2 + 1}} = \frac {20}{\sqrt {401}}\\ \sin \phi = \frac {1}{\sqrt {20^2 + 1}} = \frac {1}{\sqrt {401}}$

$30\sqrt{401}(\cos\phi\cos\theta + \sin\phi\sin\theta) < 250\\ \cos(\theta - \phi) < \frac {25}{3\sqrt{401}}\\ \theta < \arccos \frac {25}{3\sqrt {401}} + \arccos \frac {20}{\sqrt {401}}$

$\theta \approx 1.19 \text { radians }\approx 68^\circ$

You take $2\frac 14$ seconds to clear the road. You go of the road $12.5 m$ down the road from your starting point.

There is also a way to solve this problem that uses calculus.

If you run toward the car....

$\theta < -\arccos \frac {25}{3\sqrt {401}} + \arccos \frac {20}{\sqrt {401}}$