I need to search a line in a 3D space. I have a starting point (coordinates) of the line and the angle at which it is suppose to go (relative to each of the axis).
I need to start from the starting coordinates and search every element (every coordinate contains an element) $1$ by $1$ until I find one that matches the condition.
Imagine a bullet going through air to some target.
Doesn't seem that hard, but I haven't managed to find the solution for this.
In 2D space this would be something like
$$y = x\cos(\mbox{angle}) + \mbox{startPosition}$$
I assume you'll need $2$ formulas for my problem. Any idea how to solve it?
A line parallel to the nonzero vector ${\bf v} = (a, b, c)$ through the starting point ${\bf x}_0 = (x_0, y_0, z_0)$ can be traced by the constant-speed parameterization $${\bf x}(t) := {\bf x}_0 + t{\bf v}.$$
In our case, the starting position ${\bf x}_0$ is given, as are the angles $\alpha, \beta, \gamma$ the line respectively makes with the $x$-, $y$-, and $z$-axes.
We can work out $a, b, c$ by evaluating the dot product between the velocity vector ${\bf v}$ and the unit vectors ${\bf i}, {\bf j}, {\bf k}$ respectively in the positive $x$-, $y$-, and $z$-directions: On the one hand, $${\bf v} \cdot {\bf i} = |{\bf v}| |{\bf i}| \cos \alpha = |{\bf v}| \cos \alpha,$$ and on the other $${\bf v} \cdot {\bf i} = (a, b, c) \cdot (1, 0, 0) = a,$$ which gives $$a = |{\bf v}| \cos \alpha.$$ Similarly, \begin{align} b &= |{\bf v}| \cos \beta \\ c &= |{\bf v}| \cos \gamma \\ \end{align} So, the parameterization with (positive) speed $v := |{\bf v}|$ is $$\color{#df0000}{{\bf x}(t) = (x_0, y_0, z_0) + v (\cos \alpha, \cos \beta, \cos \gamma)}.$$