8

I am developing a system, and generally in this system we examine the effect of a number of factors on our data. We choose to use Barycentric coordinates to help us to achieve that. I have no problem with representing these factors with barycentric coordinates as in the following figure: Barycentric Coordinate System

My only concern is to determine the distance between any point inside the triangle and the center of the triangle (in the figure it is label as P). I know how to do this with Cartesian coordinates but in the case of barycentric coordinates I guess it is different. I hope that someone can help me with this. I would also appreciate if the answer is explained in a simple way (with example if possible) as iam a software engineer and not a mathematician.

Thank you

  • 1
    I'm not exactly sure what you are asking, but in general, you would need to compute the Cartesian coordinates first and then compute the distance. – copper.hat Aug 04 '14 at 22:22
  • The barycentric coordinates 'know' nothing about the actual coordinates of the vertices, so the Cartesian coordinates of the vertices must be involved in computing the Cartesian distance. – copper.hat Aug 04 '14 at 23:11
  • Are you imagining your points to be in two dimensions, say with coordinates $(u,v)$ in a space with orthogonal $u,v$ axes? If so as noted in copper.hat's comments you need the coordinates of the three vertices in $(u,v)$ form. On the other hand, if you are working in the plane of three-space with equation $x+y+z=1$ then things are simple, as in Stephen Nand-Lai's (now deleted) answer. – coffeemath Aug 05 '14 at 00:22
  • @coffeemath I am working with 2D space. So do you mean that I should convert the Barycentric coordinates to Cartesian coordinates? if yes, do have any ideas how we do that? – user1894963 Aug 05 '14 at 06:46
  • Yes you need to convert initial barycentrics into Cartesian. All you need for this are the coordinates of the three vertices of the equilateral triangle you are working with. There are several ways one can obtain these, but I'd prefer knowing where you want these coordinates to be before giving details. For example maybe you want two vertices at $(-1,0)$ and $(1,0)$ and the third at $(0,\sqrt{3})$ to make the triangle equilateral. – coffeemath Aug 05 '14 at 07:06
  • @coffeemath I have no problem with what you have specified as long as the negative coordinates will not add any complications. It is also important to point to the fact that I work with 2D simplex shapes (so it might be 4 or 5 vertices). – user1894963 Aug 05 '14 at 07:59
  • The generalization of barycentrics which one might try will not give unique coordinates if there are more than three vertices involved. The negative coordinates only are used in the converted brycentrics, in order to plot the points. If I guess your application, in your case the barycentrics are all nonnegative (with sum 1) so that your points are inside the triangle or on its border. (Is that right?) In that case the negative coordinates only affect the "picture" of the overall triangle. – coffeemath Aug 05 '14 at 13:47

3 Answers3

4

For aesthetic reasons I'm not happy with the asymmetry in the currently accepted solution by coffeemath. So let's try a different approach.

For a point with barycentric coordinates $(u,v,w)$ satisfying $u+v+w=1$ the point in the triangle is $uA+vB+wC$. Likewise a second point $(u',v',w')$ would be at $u'A+v'B+w'C$ and their difference vector would be $(u-u')A+(v-v')B+(w-w')C$.

Now I want to do this with complex numbers, using $\zeta_3=e^{i2\pi/3}$ as a third root of unity. So you can use $A=1,B=\zeta_3,C=\zeta_3^2=\zeta_3^{-1}$. The distance vector is represented by $d=(u-u')+(v-v')\zeta_3+(w-w')/\zeta_3$. Using $\lvert d\rvert^2=d\cdot\bar d$ we compute

\begin{align*} \lvert d\rvert^2&= \bigl((u-u')+(v-v')\zeta_3+(w-w')/\zeta_3\bigr)\bigl((u-u')+(v-v')/\zeta_3+(w-w')\zeta_3\bigr) \\&= (u-u')^2+(v-v')^2+(w-w')^2\\&\quad-(u-u')(v-v')-(v-v')(w-w')-(w-w')(u-u') \end{align*}

This is the distance in an equilateral triangle of edge length $\lvert 1-\zeta_3\rvert=\sqrt3$. For a triangle of unit edge length the squared length needs to be divided by $3$, so you can compute the distance as

$$\sqrt{\frac{(u-u')(u-u'-v+v')+(v-v')(v-v'-w+w')+(w-w')(w-w'-u+u')}3}$$

In the case of $u'=v'=w'=\frac13$ this becomes

\begin{gather*} \sqrt{\frac{(u-\tfrac13)(u-v)+(v-\tfrac13)(v-w)+(w-\tfrac13)(w-u)}3} \\= \frac13\sqrt{(3u-1)(u-v)+(3v-1)(v-w)+(3w-1)(w-u)} \end{gather*}

Now this formula looks quite different from what coffeemath wrote, why is that the case? On the one hand, he used a triangle of edge length $2$ not $1$ so we would expect twice the distances I got. On the other hand, neither formula makes use of the constraint $u+v+w=1$. If you substitute $w=1-u-v$ and scale my formula by $2$ then the (squared) formulas agree:

\begin{gather*} \frac49\bigl( (3u-1)(u-v)+(3v-1)(v-1+u+v)+(3(1-u-v)-1)(1-u-v-u) \bigr) \\=4u^2+4uv+4v^2-4u-4v+\tfrac43=\\ (u-v)^2+3\left(1-u-v-\tfrac13\right)^2 \end{gather*}

Actually Stephen Nand-Lal had written an even better answer which he later deleted (but which I'll vote to undelete). There he computed the distance as

$$\sqrt{\left(u-\tfrac13\right)^2+\left(v-\tfrac13\right)^2+\left(w-\tfrac13\right)^2}$$

This works by simply taking $A=(1,0,0)$, $B=(0,1,0)$ and $C=(0,0,1)$ as the corners of the triangle. Sure, that's in 3-space, but as long as $u+v+w=1$ the point in question will lie in the plane spanned by these three points. This is the distance computed for a triangle of edge length $\lVert A-B\rVert=\sqrt2$ so for unit edge length you might want to write

$$\frac1{3\sqrt2}\sqrt{\left(3u-1\right)^2+\left(3v-1\right)^2+\left(3w-1\right)^2}$$

MvG
  • 44,006
  • 1
    Nand-Lal's formula, comprising 27 printed symbols, may be written in thirteen:$$\sqrt{u^2+v^2 +w^2-\tfrac13}.$$ – John Bentin Jul 13 '22 at 12:55
2

Let the barycentric coordinates be $(u,v,w)$ with as usual $u+v+w=1.$ If your point is interior to (or on the edge of ) the triangle we also have $u,v,w \ge 0.$

Now if we choose to map to the equilateral triangle in the $x,y$ plane with vertices $A'=(-1,0),\ B'=(1,0),\ C'=(0,\sqrt{3})$ then the barycentric point $X:(u,v,w)$ gets mapped into $u\cdot (-1,0)+v\cdot(1,0)+w \cdot(0,\sqrt{3})$ i.e into $$X':(v-u, w\sqrt{3}).$$ In particular the barycentric $P(1/3,1/3,1/3)$ ends up at $P':(0,(1/3)\sqrt{3}).$ Then the distance from $X'$ to $P'$ by the usual distance formula sqrt[(delta x)^2+(delta y)^2] becomes $$d(X',P')=\sqrt{(v-u)^2+3\cdot(w-1/3)^2}.$$

coffeemath
  • 30,190
  • 2
  • 34
  • 53
  • 1
    Thank you so much. I reached to this solution yesterday as well. So, it conforms. I used the following reference: http://mathforum.org/library/drmath/view/51771.html – user1894963 Aug 06 '14 at 07:58
1

I know the question was asked some time ago but I came here looking for the answer so I assume others might too.

If $x:y:z$ are barycentric coordinates of a point on a triangle with side lengths $a:b:c$ then $x/a:y/b:z/c$ are trilinear coordinates. Convert both points to trilinear then normalise to actual distance trilinear coordinates.

To be specific if you use normalized barycentric coordinates so $x+y+z=1$ actual distance trilinear coordinates are $(2 \Delta x/a,2 \Delta y/b,2 \Delta z/c)=(x',y',z') $ where $\Delta$ is the area of the triangle

Then you can use the formula for distance between two points in actual distance trilinear coordinates given in Wikipedia. This has the advantage that it retains the symmetry of the homogeneous coordinate system.

So the distance between the points is $$\csc^2 C\sqrt{(x'_1-x'_2)^2+(y'_1-y'_2)^2+2(x'_1-x'_2)(y'_1-y'_2)\cos C}$$ $$= 2 \Delta \csc^2 C \sqrt{\left(\frac{x_1-x_2}{a}\right)^2+\left(\frac{y_1-y_2}{b}\right)^2+2\frac{(x_1-x_2)(y_1-y_2)}{ab}\cos C}$$ where $C$ is the interior angle of the triangle and of course the same formula holds under permutations of sides and angles.