www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/CartesianCoordinatesCovertedtoBarycentricCoordinatesExample.m

    %% Cartesian Coordinates Converted to Barycentric Coordinates  

% Copyright 2015 The MathWorks, Inc.


%% 
% Create a triangulation from a set of points, |P|, and triangulation connectivity
% list, |T|. 
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);  

%% 
% Specify the first triangle. 
ti = 1;  

%% 
% Get the coordinates of the third vertex in the first triangle. 
PC = TR.Points(TR.ConnectivityList(1,3),:)  

%% 
% Convert the point to barycentric coordinates. 
B = cartesianToBarycentric(TR,ti,PC)