User:Salix alba/sandbox3

Integration over triangle with Barycentric coordinate system

I = \int_{T} f(\mathbf{r}) \ d\mathbf{r} = 2A \int_{0}^{1} \int_{0}^{1 - \lambda_{2}} f(\lambda_{1} \mathbf{r}_{1} + \lambda_{2} \mathbf{r}_{2} + (1 - \lambda_{1} - \lambda_{2}) \mathbf{r}_{3}) \ d\lambda_{1} \ d\lambda_{2} $$ Now let $$f(\mathbf{r}_{1})=f_1$$ etc.

I = 2A \int_{0}^{1} \int_{0}^{1 - \lambda_{2}} \lambda_{1} f_1 + \lambda_{2} f_2 + (1 - \lambda_{1} - \lambda_{2}) f_3 \ d\lambda_{1} \ d\lambda_{2} $$

I = 2A \int_{0}^{1} \int_{0}^{1 - \lambda_{2}} f_3 + \lambda_{1} ( f_1 - f_3) + \lambda_{2} (f_2-f_3) \ d\lambda_{1} \ d\lambda_{2} $$

I = 2A \int_{0}^{1} \left [ f_3 \lambda_{1} + \tfrac12 \lambda_{1}^2 ( f_1 - f_3) + \lambda_{1} \lambda_{2} (f_2-f_3) \right ]_{0}^{1 - \lambda_{2}} \ d\lambda_{2} $$

I = 2A \int_{0}^{1} f_3 (1 - \lambda_{2}) + \tfrac12 (1 - \lambda_{2})^2 ( f_1 - f_3) + (1 - \lambda_{2}) \lambda_{2} (f_2-f_3) \ d\lambda_{2} $$

I = 2A \int_{0}^{1} \tfrac12 (f_1+f_3) + (-f_1+f_2-f_3) \lambda_2 + \tfrac12 (f_1-2 f_2 +f_3)\lambda_2^2 \ d\lambda_{2} $$

I = 2A \left[ \tfrac12 (f_1+f_3) \lambda_2 + \tfrac12 (-f_1+f_2-f_3) \lambda_2^2 + \tfrac16 (f_1-2 f_2 +f_3)\lambda_2^3 \right]_0^1 $$

I = 2A \left[ \tfrac12 (f_1+f_3) + \tfrac12 (-f_1+f_2-f_3) + \tfrac16 (f_1-2 f_2 +f_3) \right] $$

I = \frac{A}{3} (f_1+f_2+f_3) $$

$${C_x =\frac {1}{V}\iiint \limits _{V} x\ dV,}$$

For the centroid case we want $$f(\mathbf{r}) = \tfrac12 x^2\cdot n_x$$

I = A\ n_x \int_{0}^{1} \int_{0}^{1 - \lambda_{2}} \left(\lambda_{1} x_1 + \lambda_{2} x_2 + (1 - \lambda_{1} - \lambda_{2}) x_3\right)^2 \ d\lambda_{1} \ d\lambda_{2} $$

= A\ n_x \int_0^1 ((x_3 (-1 + \lambda_2) - x_2 \lambda_2)^3 + (x_1 - x_1 \lambda_2 + x_2 \lambda_2)^3)/(3 (x_1 - x_3)) d \lambda_2 $$

= \frac{1}{12} A\ n_x (x_1^2 + x_2^2 + x_3^2 + x_1 x_2 + x_1 x_3 + x_2 x_3) $$

Now take $$F(x,y,z) = \tfrac13 (x,y,z)$$ i.e. $$F(\mathbf{r}) =\tfrac13 \mathbf{r}$$

$$ \begin{align} V&=\iiint _{V}\left(\mathbf {\nabla } \cdot \mathbf {F} \right)\,dV \\ &= \iint_S \mathbf {F} \cdot \mathbf {\hat {n}}\ dS \\ &= \iint_{\mathbf{r}\in S} \tfrac13 \mathbf{r} \cdot \mathbf {\hat {n}} \ dS \\ &= \tfrac13 \sum_{T\in faces} \iint_{\mathbf{r}\in T} \tfrac13 \mathbf{r} \cdot \mathbf {\hat {n}} \ dT \end{align} $$

For a linear function $$g(\mathbf{r})$$ integrating over the triangle gives the area of the triangle times the mean of the function evaluated over the three vertices of the triangle are $$A,B,C$$.

$$\iint_{\mathbf{r}\in T} g(\mathbf{r})\ dT = \text{area} * \tfrac13 (g(A)+g(B)+g(C))$$

Here

$$V= \tfrac13 \sum_{T\in faces} \tfrac13\ \text{area} * \left(A+B+C \right) \cdot \mathbf {\hat {n}}$$

Now a non-normalised normal can be calculated as $$\mathbf{\tilde{n}}=(B-A)\times(C-A)$$ the triangle area is $$\text{area}=\tfrac12 | \mathbf{\tilde{n}} |$$ and a unit normal is $$\mathbf {\hat {n}} = \frac{ \mathbf{\tilde{n}} }{ | \mathbf{\tilde{n}} |}$$ so $$\text{area} * \mathbf {\hat {n}} = \frac12 \mathbf{\tilde{n}}$$

$$ \begin{align} V &= \sum_{T\in faces} \tfrac1{18} \left(A+B+C \right) \cdot \mathbf {\tilde {n}} \\ &= \sum_{T\in faces} \tfrac1{18} \left(A+B+C \right) \cdot (B-A)\times(C-A) \\ &= \sum_{T\in faces} \tfrac1{18} \left(A+B+C \right) \cdot (B\times C -A\times C- B\times A + A\times A) \\ &= \sum_{T\in faces} \tfrac1{18} \left(A\cdot B\times C - B\cdot A\times C- C\cdot B\times A \right) \\ &= \sum_{T\in faces} \tfrac1{18} \left(A\cdot B\times C + B\cdot C\times A + C\cdot A\times B \right) \\ &= \sum_{T\in faces} \tfrac1{6} \left(A\cdot B\times C \right) \end{align} $$

$$ V= \sum_{T\in faces} \tfrac1{6} \left(A\cdot B\times C \right) $$