521
|
1 function h = surfSym(X,Y,Z)
|
|
2 if isvector(X) && isvector(Y)
|
|
3 [X,Y] = meshgrid(X,Y);
|
|
4 end
|
|
5
|
|
6 V_nodes = [X(:), Y(:), Z(:)];
|
|
7
|
|
8 X_centers = neighbourMean(X);
|
|
9 Y_centers = neighbourMean(Y);
|
|
10 Z_centers = neighbourMean(Z);
|
|
11 V_centers = [X_centers(:), Y_centers(:), Z_centers(:)];
|
|
12
|
|
13
|
|
14 N = prod(size(X));
|
|
15 nodeIndecies = reshape(1:N, size(X));
|
|
16 centerIndecies = reshape(N+(1:prod(size(X)-[1,1])), size(X) - [1,1]);
|
|
17
|
|
18 % figure()
|
|
19 % h = line(V_nodes(:,1),V_nodes(:,2),V_nodes(:,3));
|
|
20 % h.LineStyle = 'none';
|
|
21 % h.Marker = '.';
|
|
22 % h = line(V_centers(:,1),V_centers(:,2),V_centers(:,3));
|
|
23 % h.LineStyle = 'none';
|
|
24 % h.Marker = '.';
|
|
25 % h.Color = Color.red;
|
|
26 % axis equal
|
|
27
|
|
28
|
|
29 I_0 = nodeIndecies(1:end-1, 1:end-1);
|
|
30 I_1 = nodeIndecies(2:end, 1:end-1);
|
|
31 I_2 = nodeIndecies(2:end, 2:end);
|
|
32 I_3 = nodeIndecies(1:end-1, 2:end);
|
|
33 I_C = centerIndecies;
|
|
34
|
|
35 S.Vertices = [
|
|
36 V_nodes;
|
|
37 V_centers;
|
|
38 ];
|
|
39
|
|
40 S.Faces = [
|
|
41 I_0(:), I_1(:), I_C(:);
|
|
42 I_1(:), I_2(:), I_C(:);
|
|
43 I_2(:), I_3(:), I_C(:);
|
|
44 I_3(:), I_0(:), I_C(:);
|
|
45 ];
|
|
46
|
|
47 % figure()
|
|
48 h = patch(S, 'FaceVertexCData', S.Vertices(:,3),'FaceColor','flat');
|
|
49 end
|
|
50
|
|
51 % Calculate the mean of four neighbours around a patch
|
|
52 function M = neighbourMean(A)
|
|
53 M = (A(1:end-1, 1:end-1) + A(2:end, 1:end-1) + A(1:end-1, 2:end) + A(2:end, 2:end))/4;
|
|
54 end
|