-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_grid.m
119 lines (101 loc) · 3.02 KB
/
plot_grid.m
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function [] = plot_grid(filename, dim, n_stop)
nodes = load(filename);
if nargin > 2
boundary = nodes(1:n_stop, :);
else
boundary = nodes;
end
if dim == 1
y = zeros(1,length(nodes(:,1)));
plot(nodes(:,1),y, '.');
elseif dim == 2
plot(nodes(:,1), nodes(:,2), '.');
elseif dim == 3
subplot(2,1,1);
plot_3d_subgrid(boundary, dim, 0);
boundary = nodes(find(boundary(:,2) <= 0),:);
subplot(2,1,2);
plot_3d_subgrid(boundary,dim, 0);
% subplot(1,2,2);
% plot_3d_subgrid(nodes,dim, 1);
% subplot(1,2,4);
% plot_3d_subgrid(boundary,dim, 1);
end
end
function [] = plot_3d_subgrid(nodes, dim, type)
if nargin < 3
type = 0
end
if type == 0
%plot_3d_shell(nodes);
plot_3d_hull(nodes);
else
plot3(nodes(:,1), nodes(:,2), nodes(:,3), '.');
end
pbaspect([1 0.5 0.5]);
axis tight
end
function [] = plot_3d_hull(p)
% Color for the surfaces (in RGB)
bcol=[250 250 0]/256;
icol=[250 250 0]/256;
% Color for the lines indicating where the spherical shell will be split.
lcol = [255 0 204]/255;
K = convhulln(p);
hW = trisurf(K,p(:,1),p(:,2),p(:,3));
hold off
% Set the properties of the patches.
set(hW,'facecolor',icol,'FaceAlpha',0.75,'edgelighting','phong','facelighting','phong','LineStyle','none','marker','.','markeredgecolor','b','markersize',15);
axis equal
view([40.5 10])
% Add a light
camlight headlight
% Plot line around sphere where it will be cut in half.
hold on;
%thc = linspace(-pi/2,pi/2,101)';
%[xc,yc,zc] = sph2cart(0*thc,thc,0*thc+Ro);
%plot3(xc,yc,zc,'--','LineWidth',2,'Color',lcol)
%[xc,yc,zc] = sph2cart(0*thc+pi,thc,0*thc+Ro);
%plot3(xc,yc,zc,'--','LineWidth',2,'Color',lcol)
%plot3(p(:,1), p(:,2), p(:,3),'--','LineWidth',2,'Color',lcol)
%plot3(p(:,1), p(:,2), p(:,3),'.','Color',lcol)
% axis off
hold off;
end
function [] = plot_3d_shell(p)
% Color for the surfaces (in RGB)
bcol=[250 250 0]/256;
icol=[250 250 0]/256;
% Color for the lines indicating where the spherical shell will be split.
lcol = [255 0 204]/255;
t=delaunayn(p);
pmid=zeros(size(t,1),3);
for ii=1:4
pmid=pmid+p(t(:,ii),:)/4; % Compute the circumcenter of the tetrahedra.
end
% Only keep the tetrahedra whose circumcenters are inside shell.
%t=t(feval(fdist,pmid)<-1e-3,:);
% First do the whole sphere
%figure
%subplot(2,2,1)
%triW=surftri(p,t);
%hW=trimesh(triW,p(:,1),p(:,2),p(:,3));
hW = tetramesh(t, p);
hold off
% Set the properties of the patches.
set(hW,'facecolor',icol,'FaceAlpha',0.75,'edgelighting','phong','facelighting','phong','LineStyle','none','marker','.','markeredgecolor','b','markersize',15);
axis equal
view([40.5 10])
% Add a light
camlight headlight
% Plot line around sphere where it will be cut in half.
hold on;
%thc = linspace(-pi/2,pi/2,101)';
%[xc,yc,zc] = sph2cart(0*thc,thc,0*thc+Ro);
%plot3(xc,yc,zc,'--','LineWidth',2,'Color',lcol)
%[xc,yc,zc] = sph2cart(0*thc+pi,thc,0*thc+Ro);
%plot3(xc,yc,zc,'--','LineWidth',2,'Color',lcol)
%plot3(p(:,1), p(:,2), p(:,3),'--','LineWidth',2,'Color',lcol)
% axis off
hold off;
end