Mercurial > repos > public > sbplib
view surfSym.m @ 577:e45c9b56d50d feature/grids
Add an Empty grid class
The need turned up for the flexural code when we may or may not have a grid for the open water and want to plot that solution.
In case there is no open water we need an empty grid to plot the empty gridfunction against to avoid errors.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 07 Sep 2017 09:16:12 +0200 |
parents | bcddbc2beef4 |
children |
line wrap: on
line source
function h = surfSym(X,Y,Z) if isvector(X) && isvector(Y) [X,Y] = meshgrid(X,Y); end V_nodes = [X(:), Y(:), Z(:)]; X_centers = neighbourMean(X); Y_centers = neighbourMean(Y); Z_centers = neighbourMean(Z); V_centers = [X_centers(:), Y_centers(:), Z_centers(:)]; N = prod(size(X)); nodeIndecies = reshape(1:N, size(X)); centerIndecies = reshape(N+(1:prod(size(X)-[1,1])), size(X) - [1,1]); % figure() % h = line(V_nodes(:,1),V_nodes(:,2),V_nodes(:,3)); % h.LineStyle = 'none'; % h.Marker = '.'; % h = line(V_centers(:,1),V_centers(:,2),V_centers(:,3)); % h.LineStyle = 'none'; % h.Marker = '.'; % h.Color = Color.red; % axis equal I_0 = nodeIndecies(1:end-1, 1:end-1); I_1 = nodeIndecies(2:end, 1:end-1); I_2 = nodeIndecies(2:end, 2:end); I_3 = nodeIndecies(1:end-1, 2:end); I_C = centerIndecies; S.Vertices = [ V_nodes; V_centers; ]; S.Faces = [ I_0(:), I_1(:), I_C(:); I_1(:), I_2(:), I_C(:); I_2(:), I_3(:), I_C(:); I_3(:), I_0(:), I_C(:); ]; % figure() h = patch(S, 'FaceVertexCData', S.Vertices(:,3),'FaceColor','flat'); end % Calculate the mean of four neighbours around a patch function M = neighbourMean(A) 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; end