# Finding Shape Functions for a Triangle in 3D coordinate space

I have a Triangular Plane T given by three points in 3D space $$P_1 = (x_1,y_1,z_1)\\ P_2 = (x_2,y_2,z_2) \\ P_3 = (x_3,y_3,z_3)$$ I want to find the Shape Functions on this plane as $N_1(x,y,z),N_2(x,y,z),N_3(x,y,z)$. I am totally aware of finding the basis function for
2D but I have no clue on how to do it for the triangular plane in 3D. I hope I made my question clear.

Thanks

• I think one common approach is to build a basis using barycentric coordinates of the simplex. You could also place nodes on the simplex and use something like Lagrange Interpolation to build the basis functions at each node. – spektr Oct 26 '16 at 18:26
• I would expect you need some additional "constraints" or "conditions". A linear function in 3D has four free parameters, so you can find a parametric class of shape functions as you, I suppoe, require three values at three points P. – Peter Frolkovič Oct 26 '16 at 18:32
• @choward can you refer me to some reference where I can find and read about the approach you have mentioned here. Thanks – Him.sharma Oct 26 '16 at 19:11

This is actually quite simple. Let's say you have your (two-dimensional) reference triangle $\hat K=\left\{(\xi,\eta)\in {\mathbb R}^2: 0\le \xi \le 1, 0\le \eta\le 1, \xi \le (1-\eta)\right\}$. Then you know how to define the three basis functions on this triangle. They are: $$\hat N_1(\xi,\eta) = 1-\xi-\eta,\\ \hat N_2(\xi,\eta) = \xi,\\ \hat N_3(\xi,\eta) = \eta.$$

Now, if you take the mapping $(x,y,z)=\Phi(\xi,\eta)$ from the reference triangle $\hat K$ to the real triangle $K$, then you simply define $$N_i(x,y,z) = \hat N_i(\Phi^{-1}(x,y,z)),$$ or, equivalently but easier to compute, $$N_i(\Phi(\xi,\eta)) = \hat N_i(\xi,\eta).$$

• Thanks Dr.@Wolfgang Bangerth for the approach, but I am looking to do the Process without transforming the original triangle to the reference triangle . I am trying to avoid the transformation since my basis functions are defined in the natural coordinates. Therefore I was thinking if I can rotate my triangle in x-y plane with the help of rotation matrix and then once its in the x-y plane construct the basis function as we do for 2D and apply rotation matrix to the Constructed Basis Function. I don't know if this is correct or not ? as I am not sure how will I construct Rotation matrix. – Him.sharma Oct 27 '16 at 0:24
• @Wolfgang Bangerth: Since $\Phi$ is a $3\times 2$ transformation matrix, how uniquely can we do the mapping $(x,y,z)=\Phi(\xi,\eta)$ since $\Phi^{-1}(x,y,z)$ does not exist? What happens to the Jacobian? – AFP Feb 28 '18 at 18:04
• @AFP: $\Phi$ is not a matrix, it's a function that maps from one space to another. It can be written using a formula that contains a matrix. But the question you have is nevertheless valid. The way you would typically implement $\Phi^{-1}$ is to first transform back into a space $\xi,\eta,\zeta$ (using a 3x3 matrix) so that the reference triangle is in the $\xi,\eta$ plane, and then throw away $\zeta$ (i.e., project into the 2d plane of the reference triangle). This way, small deviations don't matter. – Wolfgang Bangerth Mar 1 '18 at 14:25
• @Him.sharma -- I never seem to have answered the first comment above. What you describe is possible -- and in fact turns out to be exactly equivalent to the way I construct shape functions above! – Wolfgang Bangerth Mar 1 '18 at 14:26

From @Wolfgang Bangerth's answer, there exists a mapping function $$(x,y,z)=\Phi(\xi,\eta)$$ which can be expressed as a function of the basis shape functions. Using a similar notation as @Wolfgang Bangerth, the reference or base triangle is defined as:

$$\left\{(\xi,\eta)\in {\mathbb R}^2: 0\le \xi \le 1, 0\le \eta\le 1, \xi \le (1-\eta)\right\}$$

The shape functions on the base triangle are:

$$\Phi_1(\xi,\eta) = 1-\xi-\eta,\\ \Phi_2(\xi,\eta) = \xi,\\ \Phi_3(\xi,\eta) = \eta.$$

Now, the mapping between the 3D triangle and the reference triangle can be written as:

$$(x,y,z) = \sum_{i=1}^3 \Phi_i(\xi,\zeta) X_i$$

where $$X_i$$ refers to the coordinate vector $$(x_i,y_i,z_i)$$ of point $$P_i$$.

Then, we can write

$$N_i(\Phi(\xi,\zeta)) = \Phi_i(\xi,\zeta)$$

Now, to find the inverse relation, we need to find the inverse mapping function $$\Phi^{-1}$$. The mapping can be written in matrix form as follows:

$$(x,y,z)^T = X_1 + A (\xi,\eta)^T$$

where $$A$$ is the following $$3x2$$ matriz:

$$[X_2-X_1, X_3-X_1]$$

As we cannot invert this matrix, it seems impossible to find the inverse mapping function. However, we know that the 3D triangle lies in a 3D plane, which means that one coordinate ($$x$$ for instance) of a point on the triangle can be written as a function of the 2 other coordinates ($$y$$ and $$z$$). Introducing those dependencies in the equations, you can write the mapping as:

$$(\widetilde{x},\widetilde{y})^T = B (\xi,\eta)^T$$

where $$B$$ is now a $$2x2$$ matriz and $$(\widetilde{x},\widetilde{y})$$ is obtained by removing the coordinate dependency (parametrizing the 3D triangle in a 2D-space for instance).

So, all of this is possible, if you really need this. However, in FEM analysis, you typically do not need an analytical expression of your shape functions on the 3D triangle. If you know the value of a shape function on the basis element, you automatically know it on the 3D triangle thanks to the mapping function, and that should suffice.

The derivative of the shape function on the 3D triangle is more tricky though:

$$\nabla_{\overline{x}} N_i = \nabla_\overline{\xi} \Phi_i \frac{d\overline{\xi}}{d\overline{x}}$$

where $$\frac{d\overline{\xi}}{d\overline{x}}$$ is a $$2x3$$ matrix and generally hard to find. You can find it though, considering all the above, and their are many ways to get what you need. I usually transform my 3D triangle to a 2D space, so that $$\frac{d\overline{\xi}}{d\overline{x}}$$ becomes a $$2x2$$ matrix and can be obtained easily by inverting $$\frac{d\overline{x}}{d\overline{\xi}}$$.

This is a possible procedure. Let's perform a change of base:

$$\overline{e_x} = \frac{\overline{X_1X_2}}{\|\overline{X_1X_2}\|}\\ \overline{e_z} = \frac{\overline{X_1X_2} \times \overline{X_1X_3}}{\|\overline{X_1X_2}\| \|\overline{X_1X_3}\|}\\ \overline{e_y} = \overline{e_z} \times \overline{e_x}$$

Then, projecting on the new basis, the coordinates of the triangle (taking $$X_1$$ at the origin) become: $$X_1 : ( 0, 0, 0) \\ X_2 : ( \overline{X_1X_2} . \overline{e_x}, 0, 0)\\ X_3 : ( \overline{X_1X_3}. \overline{e_x}, \overline{X_1X_3} . \overline{e_y}, 0 )$$

which are coordinates in a 2D plane.