step = pi/60; % angle step
step2 = 2;
a = 6;
t = 0:2e-1:5;
t = [t fliplr(t(1,1:end-1))];
time_lapse = 0.25;
filename = 'Kerr_black_hole_animation.gif';
% Display settings
h = figure;
set(h,'Position',get(0,'ScreenSize'));
axis tight manual;
for k = 1:length(t)
i = 1;
j = 1;
for u = 0:5e-2:8
for v = 0:step:2*pi
% computing each (x,y,z) point belonging to the surface
X(i,j,k) = a*cosh(u)*cos(v+t(1,k)*u);
Y(i,j,k) = a*cosh(u)*sin(v+t(1,k)*u);
Z(i,j,k) = a*u;
j = j+1;
end
E(k,i) = a*cosh(u).*cos(4*t(1,k)*u);
F(k,i) = a*cosh(u).*sin(4*t(1,k)*u);
G(k,i) = a*u;
j = 1;
i = i+1;
end
% Sample in x, y, z
X = X(1:step2:size(X,1),1:step2:size(X,2),:);
Y = Y(1:step2:size(Y,1),1:step2:size(Y,2),:);
Z = Z(1:step2:size(Z,1),1:step2:size(Z,2),:);
for m = 1:size(Z,1)
line(X(m,:,k),Y(m,:,k),Z(m,:,k),'Color',[0 1 1],'Linewidth',2), hold on;
end
for n = 1:size(Z,2)
line(X(:,n,k),Y(:,n,k),Z(:,n,k),'Color',[0 1 1],'Linewidth',2), hold on;
end
plot3(E(k,:),F(k,:),G(k,:),'Color',[1 0 0],'Linewidth',3), hold on;
set(h,'PaperPosition',[0.635 6.345 20.305 15.228]);
set(gcf,'Color',[0 0 0]);
set(gca,'Color',[0 0 0]);
axis square;
axis off;
view(0,30);
campan(0,2.3);
camzoom(3.2);
title('Kerr black hole rotation and trajectory of an object passing through its horizon.', 'Color', [1 1 1], 'FontSize', 16);
drawnow;
frame = getframe(h);
im = frame2im(frame);
[imind,cm] = rgb2ind(im,256);
% Write to the .gif file
if k == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',Inf,'DelayTime',time_lapse);
else
imwrite(imind,cm,filename,'gif','WriteMode','append','DelayTime',time_lapse);
end
clf(1);
end