Numerical integration over a triangle in 3D I want to numerically integrate a surface discretized in triangles.
Let's say I have a triangle with vertices: $(x_1,y_1,z_1)$, $(x_2,y_2,z_2)$ and $(x_3,y_3,z_3)$. In order to integrate it easily I would like to map it to the reference triangle defined as: $T_{ref} = \{(0,0,0),(1,0,0),(0,1,0)\}$. However, I do not the form of the jacobian in order to perform the change of variables over the integral.
What I tried was to define the affine transformation:
$$B\hat{x} + c = \begin{bmatrix} x_1-x_3 & x_2-x_3 & 0\\ y_1-y_3 & y_2-y_3 & 0\\z_1-z_3 & z_2-z_3 & 0\end{bmatrix}\begin{bmatrix}\hat{x}\\\hat{y}\\\hat{z}\end{bmatrix} + \begin{bmatrix}x_3\\y_3\\z_3\end{bmatrix}$$
and to define the jacobian as $B^T$ but of course it does not work because the determinant would be zero. Moreover, the third column of $B$ could be any value so it does not make sense to me.
Can anyone explain to me how to integrate a triangle define in 3D by passing it to the reference triangle?
Thanks.
 A: Your reference triangle lives naturally in 2D. So I'd define it as
$$T_{ref} = \{(0,0),(1,0),(0,1)\}.$$
Now your transformation is 
$$
B\begin{bmatrix}\hat{x}\\\hat{y}\end{bmatrix} + c = 
  \begin{bmatrix} 
    x_1-x_3 & x_2-x_3 \\ 
    y_1-y_3 & y_2-y_3 \\
    z_1-z_3 & z_2-z_3
  \end{bmatrix}
  \begin{bmatrix}\hat{x}\\\hat{y}\end{bmatrix} + 
  \begin{bmatrix}x_3\\y_3\\z_3\end{bmatrix}.
$$
To translate an integral over the reference triangle to an integral over the 3D triangle, you've got to account for the degree to which $B$ distorts area. To do so, note that $B$ maps the square in 2D to a parallelogram spanned by the columns of $B$ in 3D. Thus, the area distortion is simply the area of this parallelogram which can be computed as the magnitude of the cross-product of those column vectors.
Note that, more generally, if $\vec{p}:U\to\mathbb R^3$ maps a region $U$ in a $uv$-plane to $\mathbb R^3$, then the local area distortion of $\vec{p}$ is
$$||\vec{p}_u \times \vec{p}_v||.$$
This is the standard distortion factor that's used when computing surface integrals, as described on Wikipedia.
