Computation of piece-wise linear hat functions

First define one triangle and interpolations as follows: $$ \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x_1 \\ y_1 \\ z_1 \end{bmatrix} + \begin{bmatrix} x_2-x_1 \\ y_2-y_1 \\ z_2-z_1 \end{bmatrix} \xi + \begin{bmatrix} x_3-x_1 \\ y_3-y_1 \\ z_3-z_1\end{bmatrix} \eta \qquad \mbox{with:} \quad \begin{cases} \xi > 0 \\ \eta > 0 \\ \xi+\eta < 1 \end{cases} $$ And quite in general: $$ \phi = \phi_1 + (\phi_2-\phi_1)\,\xi + (\phi_3-\phi_1)\,\eta $$ From this reference we infer that: $$ \begin{cases} \xi = [ (y_3 - y_1).(x - x_1) - (x_3 - x_1).(y - y_1) ] / \Delta \\ \eta = [ (x_2 - x_1).(y - y_1) - (y_2 - y_1).(x - x_1) ] / \Delta \end{cases} $$ Where $\Delta$ is twice the area of a triangle.
The Finite Element shape functions thus are, still for one triangle: $$ N_1 = 1-\xi-\eta \quad ; \quad N_2 = \xi \quad ; \quad N_3 = \eta $$ $$ x = N_1x_1+N_2x_2+N_3x_3 \\ y = N_1y_1+N_2y_2+N_3y_3 \\ z = N_1z_1+N_2z_2+N_3z_3 \\ \phi = N_1\phi_1+N_2\phi_2+N_3\phi_3 $$ Now specify for the 6 triangles in you mesh and you're done, for $\,\xi = \eta = 0\,$ eventually:
  1. $(1)\rightarrow(17) \;,\; (2)\rightarrow(11) \;,\; (3)\rightarrow(12)$
  2. $(1)\rightarrow(17) \;,\; (2)\rightarrow(12) \;,\; (3)\rightarrow(13)$
  3. $(1)\rightarrow(17) \;,\; (2)\rightarrow(13) \;,\; (3)\rightarrow(14)$
  4. $(1)\rightarrow(17) \;,\; (2)\rightarrow(14) \;,\; (3)\rightarrow(15)$
  5. $(1)\rightarrow(17) \;,\; (2)\rightarrow(15) \;,\; (3)\rightarrow(16)$
  6. $(1)\rightarrow(17) \;,\; (2)\rightarrow(16) \;,\; (3)\rightarrow(11)$