Given a ray $\overrightarrow{r_0} + \overrightarrow{v} \cdot t, t \in [0;+\infty)$ and a $(D - 1)$-simplex, defined by $D$-tuple of its vertices $p_i = (p_i^1, p_i^2, \dots, p_i^D), i \in \{1, 2, \dots, D\}$, in $D$-space.
I want to check whether the ray intersects an internals of the above $D$-facet or not.
What I think at the moment is to find the point common for the ray and the facet, then find its barycentric coordinates within the facet and to check whether all they are positive values of not. Firstly, it requires the normalized normal equation of hyperplane, spanned on points $p_i, i \in \{1, 2, \dots, D\}$:
$\sum \limits_{i = 1}^{D}\left(x_i \cdot \frac{n_i}{|\overrightarrow{n}|}\right) - \frac{d}{|\overrightarrow{n}|} = 0$
where $\overrightarrow{n} = (n_1, n_2, \dots, n_D)$ — a normal to the hyperplane. $\frac{d}{|\overrightarrow{n}|}$ — a distance from the origin to the hyperplane.
$ n_i = \begin{vmatrix} p_1^1 & p_1^2 & \dots & p_1^{i - 1} & 1 & p_1^{i + 1} & \dots & p_1^D \\ p_2^1 & p_2^2 & \dots & p_2^{i - 1} & 1 & p_2^{i + 1} & \dots & p_2^D \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\ p_D^1 & p_D^2 & \dots & p_D^{i - 1} & 1 & p_D^{i + 1} & \dots & p_D^D \notag \end{vmatrix} \\ d = \begin{vmatrix} p_1^1 & p_1^2 & \dots & p_1^D \\ p_2^1 & p_2^2 & \dots & p_2^D \\ \vdots & \vdots & \ddots & \vdots \\ p_D^1 & p_D^2 & \dots & p_D^D \notag \end{vmatrix} $
Hence, an intersection point $a = (a_0, a_1, \dots, a_D)$:
$a = \overrightarrow{r_0} - \overrightarrow{v} \cdot \underbrace{\frac{(\overrightarrow{r_0} \cdot \overrightarrow{n}) - d}{(\overrightarrow{v} \cdot \overrightarrow{n})}}_\text{= -t}$
If $t \ge 0$ and $(\overrightarrow{v} \cdot \overrightarrow{n}) \ne 0$, then the ray intersects the hyperplane properly. Is it right?
Further, one need to compute a barycentric coordinates $c_i, i \in \{1, 2, \dots, D\}$ of the intersection point $a$ defined with respect to the facet:
$(c_0, c_1, \dots, c_D) \cdot \left( \begin{matrix} p_1^1 & p_1^2 & \dots & p_1^D \\ p_2^1 & p_2^2 & \dots & p_2^D \\ \vdots & \vdots & \ddots & \vdots \\ p_D^1 & p_D^2 & \dots & p_D^D \notag \end{matrix} \right) = (a_0, a_1, \dots, a_D) \Rightarrow c = a \cdot P^{-1}$
Am I right in the next assertion: if $c_i \ge 0, i \in \{1, 2, \dots, D\}$, then the $a$ lies on internals of the facet? And another (not too important) problem: is it right $\sum \limits_{i = 1}^D{c_i} = 1$ (it comes true automatically, at my mind)?
I conclude my approach is correct. To test it I wrote simple GNU Octave script for D3 case: