# Barycentric coordinates of a triangle

I have to do what described next:

Consider the planar triangle $[p_1,p_2,p_3]$ with vertices $$p_1=\left(\begin{array}[c]\,-2\\-1\end{array}\right), p_2=\left(\begin{array}[c]\,3\\-1\end{array}\right), p_1=\left(\begin{array}[c]\,1\\4\end{array}\right),$$ compute the barycen-tric coordinates $\lambda_1,\lambda_2,\lambda_3$ of the point $$p=\left(\begin{array}[c]\,2\\1\end{array}\right),$$ and verify that $p$ can indeed be expressed as the convex combination $\lambda_1p_1+\lambda_2p_2+\lambda_3p_3$.

Repeat this computation for the point $$p'=\left(\begin{array}[c]\,3\\3\end{array}\right).$$ Finally, transform the triangle and the point p with the linear mapping $$\phi:R^2 \to R^2, \phi\left(\begin{array}[c]\,x\\y\end{array}\right) =\left(\begin{array}[c]\,2x-1\\x-3y-2\end{array}\right),$$ and compute the barycen-tric coordinates of the transformed point $q=\phi(p)$ with respect to the transformed triangle $[q_1,q_2,q_3]$, where $q_i=\phi(p_i)$, for $i=1,2,3$.

Consider the planar triangle $[p_1,p_2,p_3]$ with vertices $p_1=\begin{pmatrix}-2\\-1\end{pmatrix}$, $p_2=\begin{pmatrix}3\\-1\end{pmatrix}$, $p_3=\begin{pmatrix}1\\4\end{pmatrix}$, compute the barycentric coordinates of the point $p=\begin{pmatrix}2\\1\end{pmatrix}$, and verify that $p$ can indeed be expressed as the convex combination $\lambda_1p_1+\lambda_2p_2+\lambda_3p_3$. Repeat this computation with the point $p'=\begin{pmatrix}3\\3\end{pmatrix}$. Finally transform the triangle and the point $p$ with the linear mapping $\phi \colon \mathbb R^2\to\mathbb R^2$, $\phi\begin{pmatrix}x\\y\end{pmatrix}=\begin{pmatrix}2x-1\\x-3y+2\end{pmatrix}$, and compute the barycentric coordinates of the transformed point $q=\phi(p)$ with respect to the transformed triangle $[q_1,q_2,q_3]$, where $q_i=\phi(p_i)$, for $i=1,2,3$.

Any ideas on how to do this?

• @EdGorcenski I am using this formula at the moment en.wikipedia.org/wiki/…. – kokos Oct 17 '12 at 22:48
• @EdGorcenski If you have something to propose me I am glad to know! – kokos Oct 17 '12 at 22:50

To calculate the barycentric cooordinates of a point wrt a given triangle, the wikipedia formulae are fine. You can write the formulae in terms of triangle areas or vector cross products, instead, if you want. This makes them look tidier, certainly, and provides some intuituion: http://mathworld.wolfram.com/BarycentricCoordinates.html

If you're writing code, the formulae based on areas or cross products will be more convenient if you already have functions for computing the latter.

Again, if you're writing code, you have to think about which two coordinates you will get from the quotient formulae, and which one you'll compute by subtraction. Some calculations will be more stable than others.

By definition you want to find $\lambda_1$, $\lambda_2$, $\lambda_3$ such that $p=\lambda_1p_1+\lambda_2p_2+\lambda_3p_3$ and $\lambda_1+\lambda_2+\lambda_3=1$. This give you three linear equations with three variables. For example, in the case of the point $p$ you will get \begin{align*} \lambda_1+\lambda_2+\lambda_3&=1\\ -2\lambda_1+3\lambda_2+\lambda_3&=2\\ -\lambda_1-\lambda_2+4\lambda_3&=1\\ \end{align*}

If you solve this system, you get $\lambda_1=\frac1{25}$, $\lambda_2=\frac{14}{25}$, $\lambda_3=\frac25$. You can try to solve the remaining ones in this way. (Please, include what you get to show your work.)

The second part is related to the fact that affine functions preserve barycentric combinations.

You can use a very simple method presented in "Beginner's guide to mapping simplexes affinely" and "Workbook on mapping simplexes affinely", namely calculate $$(-1) \frac{ \det \begin{pmatrix} 0 & \vec{i} & \vec{j} & \vec{k} \\ 2 & -2 & 3 & 1 \\ 1 & -1 & -1 & 4 \\ 1 & 1 & 1 & 1 \end{pmatrix} }{ \det \begin{pmatrix} -2 & 3 & 1 \\ -1 & -1 & 4 \\ 1 & 1 & 1 \end{pmatrix} } = \frac{1}{25} \vec{i} + \frac{14}{25} \vec{j} + \frac{2}{5}\vec{k},$$ where coefficients near $$\vec{i}$$, $$\vec{j}$$, and $$\vec{k}$$ are barycentric coordinates.

The general formula for any dimension is $$\vec{\Lambda} = (-1) \frac{ \det \begin{pmatrix} 0 & \vec{e}_{1} & \vec{e}_{2} & \dots & \vec{e}_{n+1} \\ \begin{matrix} x_{1} \vphantom{x_{1}^{(1)}} \\ x_{2} \vphantom{x_{1}^{(1)}} \\ \cdots \\ x_{n} \vphantom{x_{1}^{(1)}} \\ \end{matrix} & % \begin{matrix} x_{1}^{(1)} \\ x_{2}^{(1)} \\ \cdots \\ x_{n}^{(1)} \\ \end{matrix} & % \begin{matrix} x_{1}^{(2)} \\ x_{2}^{(2)} \\ \cdots \\ x_{n}^{(2)} \\ \end{matrix} & % \cdots & % \begin{matrix} \!x_{1}^{(n+1)}\! \\ \!x_{2}^{(n+1)}\! \\ \cdots \\ \!x_{n}^{(n+1)}\! \\ \end{matrix} \\ % 1 & 1 & 1 & \cdots & 1 \end{pmatrix} }{ \det \begin{pmatrix} \begin{matrix} x_{1}^{(1)} \\ x_{2}^{(1)} \\ \cdots \\ x_{n}^{(1)} \\ \end{matrix} & % \begin{matrix} x_{1}^{(2)} \\ x_{2}^{(2)} \\ \cdots \\ x_{n}^{(2)} \\ \end{matrix} & % \cdots & % \begin{matrix} \! x_{1}^{(n+1)}\! \\ \!x_{2}^{(n+1)}\! \\ \!\cdots \! \\ \! x_{n}^{(n+1)} \!\\ \end{matrix} \\ % 1 & 1 & \cdots & 1 \end{pmatrix} }.$$ Here $$\vec{x}^{\,(1)}$$, $$\dots$$, $$\vec{x}^{\,(n+1)}$$ are vertices of the simplex, $$x_{1}$$, $$\dots$$, $$x_{n}$$ --- coordinates of the point, which barycentric coordinates you want to know, and $$\vec{e}_{1}$$, $$\dots$$, $$\vec{e}_{n+1}$$ are some formal orthonormal vectors. As a result you get a "vector" $$\vec{\Lambda}$$, which components are barycentric coordinates of the point $$\vec{x}$$.

To read more on the theory everything relies on, you may want to check "Beginner's guide to mapping simplexes affinely" that is written by authors of the formula, or check concrete example in their "Workbook on mapping simplexes affinely".