| [p]=hypersurface(x,y,z,M,layer,color,smoothing,fidelity,xlab,ylab,zlab)
|
function [p]=hypersurface(x,y,z,M,layer,color,smoothing,fidelity,xlab,ylab,zlab)
%hypersurface(x,y,z,M,layer) plots a hypersurface of magnitude 'layer' with
% the x-axis being 'x', y-axis being 'y' and the z-axis being 'z'. 'M' is a
% 3D matrix where [A,B,C]=size(M) A=length(x), B=length(y), and C=length(z).
% M holds the 4D values of the function f(x,y,z).
%[p]=hypersurface(x,y,z,M,layer) outputs graph's handle to change settings.
%hypersurface(x,y,z,M,layer,color) plots the graph with the surface the
% color defined by 'color'. Default='b'.
%
%hypersurface(x,y,z,M,layer,color,smoothing,fidelity) uses ndgrid to smooth
% out the surface. To smooth, smoothing='yes'. To define the fidelity set
% fidelity to desired number of points. Default smoothing='no' and
% fidelity=30;
% xlin = linspace(min(x),max(x),fidelity);
% ylin = linspace(min(y),max(y),fidelity);
% zlin = linspace(min(z),max(z),fidelity);
%
%
%hypersurface(x,y,z,M,layer,color,smoothing,fidelity,xlab,ylab,zlab) labels
% the axis. Default xlab='x',ylab='y', and zlab='z'.
% xlabel(xlab)
% ylabel(ylab)
% zlabel(zlab)
[AA,BB,CC]=size(M);
if length(x)~=AA
error ('x is not the right length')
elseif length(y)~=BB
error ('y is not the right length')
elseif length(z)~=CC
error ('z is not the right length')
end
if ~exist('smoothing', 'var')
smoothing='no';
end
if strcmpi('yes',smoothing)
if ~exist('fidelity', 'var')
fidelity=30;
end
xlin = linspace(min(x),max(x),fidelity);
ylin = linspace(min(y),max(y),fidelity);
zlin = linspace(min(z),max(z),fidelity);
[xx,yy,zz]=meshgrid(x,y,z);
X=[xx(:),yy(:),zz(:)];
MM=M(:);
[xn,yn,zn]=meshgrid(xlin,ylin,zlin);
XI=[xn(:), yn(:),zn(:)];
Mn = griddatan(X,MM,XI);
Mn = reshape(Mn, size(xn));
else
[xn,yn,zn]=ndgrid(x,y,z);
Mn=M;
end
% figure
p = patch(isosurface(xn,yn,zn,Mn,layer));
% isonormals(xn,yn,zn,Mn,p);
if ~exist('color', 'var')
color='b';
end
set(p,'FaceColor',color,'EdgeColor','none');
set(gcf,'Renderer','zbuffer')
view(3), camlight, lighting phong
if ~exist('xlab', 'var')
xlab='x';
end
if ~exist('ylab', 'var')
ylab='y';
end
if ~exist('zlab', 'var')
zlab='z';
end
xlabel(xlab,'fontsize',12)
ylabel(ylab,'fontsize',12)
zlabel(zlab,'fontsize',12)
lightangle(-45,100)
set(findobj(gca,'type','surface'),...
'FaceLighting','phong',...
'AmbientStrength',.3,'DiffuseStrength',.8,...
'SpecularStrength',.9,'SpecularExponent',25,...
'BackFaceLighting','unlit')
end
|
|