changeset 550:e860670e72f1 feature/grids

Merge default
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 28 Aug 2017 14:29:46 +0200
parents ae905a11e32c (current diff) bcddbc2beef4 (diff)
children c5a7a13c03dc 12ee11893453
files
diffstat 2 files changed, 73 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/logsurf.m	Mon Aug 28 14:29:46 2017 +0200
@@ -0,0 +1,19 @@
+function [srfHandle, cbHandle] = logsurf(X,Y,Z, lim)
+    absLogZ = log10(abs(Z));
+    srfHandle = surf(X,Y,absLogZ);
+
+    cbHandle = colorbar();
+    colormap(hot(256));
+    ah = gca();
+    ah.CLim = lim;
+
+    oldTickLabels = cbHandle.TickLabels;
+
+    newTickLabels = {};
+
+    for i = 1:length(oldTickLabels)
+        newTickLabels{i} = sprintf('10^{%s}',oldTickLabels{i});
+    end
+
+    cbHandle.TickLabels = newTickLabels;
+end
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/surfSym.m	Mon Aug 28 14:29:46 2017 +0200
@@ -0,0 +1,54 @@
+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