-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrawmesh.m
More file actions
68 lines (51 loc) · 1.45 KB
/
drawmesh.m
File metadata and controls
68 lines (51 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
function h = drawmesh(t, x, B, ecolor, color, alpha)
newplot = isempty( get(gca, 'child') ); % ~isempty( get(0,'CurrentFigure') ) && ~isempty( get(gcf, 'CurrentAxes') );
if nargin<3, B = []; end
if nargin<4, ecolor = 'k'; end
% ecolor = [1 1 1]*0.4; %'k';
if nargin<5, color = 'w'; end
% color = 'g'; %interp
% color = 'none';
if nargin<6, alpha = 1; end
if size(x, 1)==1 && size(x, 2)>1, warning('transpose x for display'); x = x.'; end
if ~isreal(x), x = [real(x) imag(x)]; end
linewidth = 1;
% figure;
% drawfunc = @trisurf;
drawfunc = @trimesh;
dim = size(x,2);
if dim>3
if range( x(:,4) )<1e-10, x(:,4) = 0; end
h=drawfunc(t, x(:,1), x(:,2), x(:,3), x(:,4));
view(3);
elseif dim>2
h=drawfunc(t, x(:,1), x(:,2), x(:,3), zeros(size(x,1),1));
if range( x(:,3) )>1e-10
view(3);
else
view(2);
end
else
h=drawfunc(t, x(:,1), x(:,2), zeros(size(x,1),1));
view(2);
end
set(h, 'FaceColor', color, 'EdgeColor', ecolor, 'FaceAlpha', alpha, 'LineWidth', linewidth);
if nargin>2 && ~isempty(B)
hold on;
tB = [B B(1)];
if dim<3
hB = plot( x(tB, 1), x(tB, 2) );
else
hB = plot3( x(tB, 1), x(tB, 2), x(tB, 3));
end
set(hB, 'color', 'b', 'linewidth', linewidth+1);
h(end+1) = hB;
end
%% note, don't mix LineSmoothing with face/edge alpha, may crash matlab
% set(h,'LineSmoothing','on');
if newplot
axis equal;
axis off;
end
% axis tight;
% camlight; lighting gouraud;