%% Convert Cartesian Coordinates to Barycentric Coordinates
% Create a triangulation from a set of points P and triangulation connectivity list T, and plot the triangulation.

P = [2.5 8.0; 6.5 8.0; 2.5 5.0; 6.5 5.0; 1.0 6.5; 8.0 6.5];
T = [5 3 1; 3 2 1; 3 4 2; 4 6 2];
TR = triangulation(T,P);
triplot(TR)

%
% Find the Cartesian coordinates of the third vertex in the first (leftmost) triangle in TR.

L = TR.ConnectivityList(1,3);
C = TR.Points(L,:)

%
% Convert the point C to barycentric coordinates with respect to the first triangle.

B = cartesianToBarycentric(TR,1,C)

% Copyright 2015 The MathWorks, Inc.