我认为你可以做这样的事情(注意 - 大脑编译的代码......)
figure;
patch('faces', edges, 'vertices', points, 'edgecolor', 'b');
axis equal;
其中edges 应该是Nx2 索引矩阵,points 应该是Mx3 坐标矩阵(points 数组的转置)。
根据我的经验,直接调用patch 比重复调用plot 快得多。
给出一些想法,使用我的(诚然旧的!)MATLAB 7.1 生成 1000 个随机生成的线段的时间如下:
- 呼叫
patch:0.03 秒。
- 呼叫
plot:0.5 秒。
编辑:让边缘颜色按您的意愿表现的一种方法(为每条边缘指定一种颜色)是引入重复的顶点,如下所示:
这解决了边缘颜色只能通过顶点颜色数据间接指定的问题。如果我们仅依赖于顶点颜色,那么共享一个公共顶点的所有边可能最终都使用分配给该顶点的颜色 - 查看 'flat 'edgecolour 描述 here。
%% a "star" shape, so that we can really see what's going on
%% with the edge colours!!
pp = [0,0,0; 1,-1,0; 1,1,0; -1,1,0; -1,-1,0];
ee = [1,2; 1,3; 1,4; 1,5];
%% important - only 1 colour known per edge, not per vertex!!
cc = (1:size(ee,1))';
%% setup a new set of vertices/edges/colours with duplicate vertices
%% so that each edge gets it's correct colour
nnum = 0;
pnew = zeros(2 * size(ee, 1), 3); %% new vertices
enew = zeros(1 * size(ee, 1), 2); %% new edge indices
cnew = zeros(2 * size(ee, 1), 1); %% new edge colours - via vertices
for j = 1 : size(ee, 1)
n1 = ee(j, 1); %% old edge indices
n2 = ee(j, 2);
enew(j, 1) = nnum + 1; %% new edge indicies into pnew
enew(j, 2) = nnum + 2;
pnew(nnum + 1, :) = pp(n1, :); %% create duplicate vertices
pnew(nnum + 2, :) = pp(n2, :);
cnew(nnum + 1) = cc(j); %% map single edge colour onto both vertices
cnew(nnum + 2) = cc(j);
nnum = nnum + 2;
end
%% Draw the set efficiently via patch
tic
figure;
hold on;
patch('faces', enew, 'vertices', pnew, 'facevertexcdata', cnew, ...
'edgecolor', 'flat', 'facecolor', 'none');
plot(pnew(:,1), pnew(:,2), 'b.');
axis equal;
toc
如果 MATLAB 允许您直接指定边缘颜色数据会更好 - 但它似乎不支持...
希望这会有所帮助。