%Spherical deformations with Legendre Polynomials clear Movi=[]; scale = [linspace(0,1,20) linspace(1,0,20) linspace(0,-1,20) linspace(-0.95,0,20)]; %full cycle deformation for deg=2:6 for idx=1:length(scale) theta = 0:pi/40:pi; % polar angle phi = 0:pi/20:2*pi; % azimuth angle [phi,theta] = meshgrid(phi,theta); % define the grid degree = deg; order = deg-1; amplitude = 2.5; radius = 4; Ymn = legendre(degree,cos(theta(:,1)));%+legendre(degree,cos(2*theta(:,1))); Ymn = Ymn(order+1,:)'; yy = Ymn; for kk = 2: size(theta,1) yy = [yy Ymn]; end yy = yy.*cos(order*phi); order = max(max(abs(yy))); rho = radius + amplitude*scale(idx)*yy/order; r = rho.*sin(theta); % convert to Cartesian coordinates x = r.*cos(phi); y = r.*sin(phi); z = rho.*cos(theta); COL=min(rho)/radius;%use with ,'FaceColor',[COL(1) COL(1) COL(1) ] in surf parameters for effect figure(1) %s = surf(rho,'EdgeColor',[.2 .2 .2],'BackFaceLighting','lit','SpecularColorReflectance',0.9,'AmbientStrength',1); s = surf(x,y,z,'EdgeColor',[.2 .2 .2],'BackFaceLighting','lit','SpecularColorReflectance',0.9,'AmbientStrength',1); hold on; %colormap('gray') colormap('cool') set(gcf,'Renderer','zbuffer') light % add a light lighting gouraud %camzoom(1.5) axis equal off % set axis equal and remove axis %view(40,30) % set viewpoint set(gcf,'Position',[50 100 1100 900]); whitebg('black'); hold off Mov(idx)=getframe; end Movi=horzcat(Movi,Mov); end movie(Movi,15,50);