title: Construct ternary grid, evaluate a function on the grid and contour plot in Matlab
body: <p>I need to evaluate a function (say)
  Fxy = 2*x.^2 +3 *y.^2;
  on a ternary grid x-range (0 - 1), y-range (0-1) and 1-x-y (0 - 1).
  I am unable to construct the ternary grid on which I need to evaluate the above function. Also, once evaluated I need to plot the function in a ternary contour plot. Ideally, I need the axes to go counter clockwise in the sense (x -> y--> (1-x-y)).</p>
  
  <p>I have tried the function </p>
  
  <pre><code>function tg = triangle_grid ( n, t )
  
    ng = ( ( n + 1 ) * ( n + 2 ) ) / 2;
    tg = zeros ( 2, ng );
  
    p = 0;
  
    for i = 0 : n
      for j = 0 : n - i
        k = n - i - j;
        p = p + 1;
        tg(1:2,p) = ( i * t(1:2,1) + j * t(1:2,2) + k * t(1:2,3) ) / n;
      end
    end
  
    return
  end
  </code></pre>
  
  <p>for the number of sub intervals between the triangle edge coordinates</p>
  
  <pre><code>n = 10 (say)
  </code></pre>
  
  <p>and for the edge coordinates of an equilateral triangle </p>
  
  <pre><code>t = tcoord = [0.0, 0.5,           1.0;
                0.0, 1.0*sqrt(3)/2, 0.0];
  </code></pre>
  
  <p>This generated a  triangular grid with the x-axis from 0-1 but the other two are not from 0-1.</p>
  
  <p>I need something like this: </p>
  
  <p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Ternary_plot_1.png/726px-Ternary_plot_1.png" alt="wiki link"> </p>
  
  <p>... with the axes range 0-1 (<em>0-100 would also do</em>).</p>
  
  <p>In addition, I need to know the coordinate points for all intersections within the triangular grid. Once I have this I can proceed to evaluate the function in this grid.</p>
  
  <p>My final aim is to get something like this. This is a better representation of what I need to achieve (as compared to the previous plot which I have now removed)</p>
  
  <p><a href="https://i.stack.imgur.com/uL5RY.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uL5RY.gif" alt="better representation"></a></p>
  
  <p>Note that the two ternary plots have iso-value contours which are different in in magnitude. In my case the difference is an order of magnitude, two very different Fxy's.  </p>
  
  <p>If I can plot the two ternary plots on top of each other then and evaluate the compositions at the intersection of two iso-value contours on the ternary plane. The compositions should be as read from the ternary plot and not the rectangular grid on which triangle is defined. 
  Currently there are issues (as highlighted in the comments section, will update this once the problem is closer to solution).  </p>