• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 4
  • 25
  • 1
  • 0
  • 429
drawframe(1);
Write your drawframe function below
function drawframe(f)
% 3-D regular wave interaction pattern (spinning version)
persistent S n ax % Avoids duplicating calculations
if isempty(S)
% Time domain
t=-1:1/48:1-1/48;
% Spatial domain
[x,y]=deal(-3:0.05:3);
% Surface elevation calculation
n=zeros(numel(t),numel(x),numel(y));
ncomp=2^7+1;
for i=1:length(x)
for j=1:length(y)
for th=linspace(-pi,pi,ncomp)
n(:,i,j)=n(:,i,j)+cos(2*pi*(t-(x(i)*cos(th)+y(j)*sin(th))))';
end
end
end
% Surface plot
ax=gca;
[X,Y]=meshgrid(x,y);
S=surf(X,Y,squeeze(n(1,:,:)),'edgecolor','none');
axis off
view(-45,45)
zlim(ncomp*[-1 1])
clim(ncomp*[-1 1])
end
% Updating the surface
S.ZData=squeeze(n(f,:,:));
ax.View=ax.View+[90*f/48 0];
end
Animation
Remix Tree