function genWM(Ds,lambda,nmax)
%GENWM 生成W-M 隨機曲面
% 此處顯示詳細說明
% lambda
% Ds 分形維數(shù)
if nargin < 3
nmax = 10;
if nargin < 2
lambda = 1.5;
if nargin < 1
Ds = 2.3;
end
end
end
% nmax = 10;
An = 2*pi*rand(nmax,1);
Bn = 2*pi*rand(nmax,1);
Cn = randn(nmax,1);
x = 0:0.1:6;
y = 0:0.1:6;
[X,Y] = meshgrid(x,y);
% lambda = 1.5;
% Ds = 2.05;
Z= zeros(length(x),length(y));
for ni = 1:nmax
t = -(3-Ds)*ni;
temp1 = X.*cos(Bn(ni)) + Y.*sin(Bn(ni));
zn = Cn(ni)*lambda^t.*sin(lambda^ni.*temp1+An(ni));
Z = zn + Z;
end
surf(X,Y,Z);
xlabel('X');
ylabel('Y');
zlabel('Z');
filename = ['W-M fractal surface','_Ds',num2str(Ds),'_lambda',num2str(lambda),'.bmp'];
saveas(gcf,filename,'bmp');
end |