# Barycentric Plots in gnuplot

Authors: Giulio Bottazzi 26 September 2006 0.1 GPL

# Some mathematical details

Consider an equilateral triangle and number its sides (and the opposing vertices) with 1, 2 and 3. Now take a point P inside the triangle and let h1, h2 and h3 be the distance of this point from side 1, 2 and 3 respectively. It is easy to show that for any point P it is:

```h1+h2+h3 = sqrt(3)/2 l
```

where l is the length of the triangle side.

Now consider a triangle with sides of unit length and imagine to embed it in a Cartesian system, with vertex 3 in the origin and side 1 along the x-axis. Vertex 1 is then at position (1/2,sqrt(3)/2) and vertex 2 at (0,1/2). It is easy to see that an internal point P at distances h1 and h2 from side 1 and 2 respectively has coordinates:

```( h1/sqrt(3)+2 h2/sqrt(3) , h1 )
```

# Barycentric coordinates

The above properties can be exploited to represent a function defined over the 2 dimensional simplex, that is over the triplet of points (x1,x2,x3) which satisfy the condition:

```x1+x2+x3=1   x1,x2,x3>0 .
```

Indeed, with the identification hi=sqrt(3)/2 xi for i=1,2,3, this relation is identical to the one given above concerning the sum of the distances of an interior point of an equilateral triangle from its sides. In the Cartesian system, the point (x1,x2,x3) is then represented by the couple of coordinates:

```( x1/2+x2 , x1 sqrt(3)/2 )
```

The two dimensional unit simplex is mapped in the equilateral triangle of side "2/sqrt(3)". In this representation, if the point P is nearer to the vertex 1, it means that x1> x2,x3. If the point is on one side, than the coordinate associated with the opposing vertex is zero. If it is on one vertex, than the associated coordinate is 1 (and the remaining two zero).

# Gnuplot representation

Imagine to have the function f(x1,x2) defined over the unit 2-simplex. When data are generated, the coordinates (x1,x2) should be transformed according to the equation above. This the points are automatically placed inside the equilateral triangle with its side 1 over the x-axis. The picture can be beautified applying some changes to the default setting. First of all remove the Cartesian axes and the associated ticks:

```unset border
unset xtics
unset ytics
```

and substitute it with the proper triangular frame:

```set arrow 1 from 0,0 to .5,sqrt(3)/2 nohead front lt -1 lw 1
set arrow 2 from 0,0 to 1,0          nohead front lt -1 lw 1
set arrow 3 from 1,0 to .5,sqrt(3)/2 nohead front lt -1 lw 1
```

properly numbering the vertex:

```set label 1 "1" at 0.5,sqrt(3)/2+.05
set label 2 "2" at 1+.05,0
set label 3 "3" at -.05,0
```

At this point you can draw a surface plot or also a map using the usual gnuplot options.