MATLAB has a convenient data visualization function to display vectors and matrices graphically, and can mark and print the graphics. High-level drawing includes 2D and 3D visualization, image processing, animation and expression drawing. It can be used for scientific calculation and engineering drawing. The new version of MATLAB has made great improvements and perfections to the entire graphics processing function, making it not only more complete in the functions that general data visualization software has (such as the drawing and processing of two-dimensional curves and three-dimensional surfaces, etc.), but also For some functions that other software does not have (such as graphics light processing, chromaticity processing, and four-dimensional data performance, etc.), MATLAB also shows excellent processing capabilities.
In this paper, the Matlab software platform is used to draw the rotating motion picture and generate the corresponding .gif picture. The specific content includes the dynamic process of the horizontal plane moving vertically along the Z axis to cut the saddle surface, the dynamic process of hyperbolic horizontal rotation and vertical rotation to form a curved surface, and the dynamic process of circular curve rotation to form a ring.
Make the dynamic process of cutting the saddle surface by moving the horizontal plane vertically along the Z axis, and mark the cutting curve (the line of intersection between the horizontal plane and the saddle surface).
Programming ideas:
Source code: see appendix
operation result
3.1 The dynamic process of hyperbola horizontal rotation and vertical rotation to form a curved surface
Programming ideas:
Source code: see appendix
operation result
3.2 The dynamic process of a circular curve rotating to form a torus
Programming ideas:
Source code: see appendix
operation result
1 Cutting animation of horizontal plane and saddle surface
clc
clear
close all
pic_num=1;
x=-4:0.03:4;
y=-4:0.03:4;
[X,Y]=meshgrid(x,y);
Z=-X.^2+Y.^2;
[r,c]=size(Z);
figure
title('马鞍面与水平面相切');
L=min(min(Z));
H=max(max(Z));
time=[L:1:H H:-1:L];
delt=0.03;
% view(-68,22);% Change the viewing angle
for i=time
Z2=zeros(r,c)+i;
alpha(0.1)
mesh(X,Y,Z)
hold on
alpha(0.1)
mesh(X,Y,Z2,'facecolor',[0.2 0.2 0])
hold on
XL=X(find(Z>i-delt&Z<=i+delt));
YL=Y(find(Z>i-delt&Z<=i+delt));
ZL=repmat(i,1,length(find(Z>i-delt&Z<=i+delt)));
plot3(XL,YL,ZL,'.','color',[1 0 0],'LineWidth',5)
hold off
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'马鞍.gif','gif', 'Loopcount',inf,'DelayTime',0.15);
else
imwrite(I,map,'马鞍.gif','gif','WriteMode','append','DelayTime',0.15);
end
pic_num = pic_num + 1;
end
2 The dynamic process of hyperbolic horizontal rotation and vertical rotation to form a curved surface
clc
clear
close all
pic_num=1;
a=4;
c=4;
z=-15:0.1:15;
x=a*sqrt(1+z.^2/c^2);
y=zeros(1,length(z));
[x1,y1,z1]=cylinder(x,51);
figure;
plot3(x,y,z,'color',[1 0 0],'LineWidth',2);
hold on
plot3(-x,y,z,'color',[1 0 0],'LineWidth',2);
title('双曲线绕Z轴旋转')
z1=30.*z1-15;
axis([-20,20,-20,20,-10,10]);
hold on
grid on
n=size(z1,2);
for i=1:n/2+1
z11=z1;
z11(:,i+1:n)=NaN;
mesh(x1,y1,z11);
mesh(-x1,-y1,z11);
drawnow
% pause(0.1)
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'垂直.gif','gif', 'Loopcount',inf,'DelayTime',0.15);
else
imwrite(I,map,'垂直.gif','gif','WriteMode','append','DelayTime',0.15);
end
pic_num = pic_num + 1;
end
v=x';
r=z; %自变量
th=linspace(0,2*pi,100);
[R,Th]=meshgrid(r,th);
[X,Y] = pol2cart(Th,R);
Z=(v*ones(size(th)))';
pic_num=1;
figure
plot3(X(1,:),Z(1,:),Y(1,:),'color',[1 0 0],'LineWidth',2);
hold on
plot3(X(1,:),-Z(1,:),Y(1,:),'color',[1 0 0],'LineWidth',2);
title('双曲线绕水平轴旋转')
view(-68,22);% 改变观测视角
axis([-20,20,-20,20,-20,20]);
n=size(X,1);
hold on
grid on
for i=1:n/2
mesh(X(i:i+1,:),Z(i:i+1,:),Y(i:i+1,:));
mesh(X(i:i+1,:),-Z(i:i+1,:),Y(i:i+1,:));
drawnow;
pause(0.2);
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'水平.gif','gif', 'Loopcount',inf,'DelayTime',0.15);
else
imwrite(I,map,'水平.gif','gif','WriteMode','append','DelayTime',0.15);
end
pic_num = pic_num + 1;
end
3 The dynamic process of a circular curve rotating to form a torus
clc
clear
close all
pic_num = 1;
R=10; %大圆半径
aplha1=0:pi/40:2*pi;
N=length(aplha1);
r=2; % Pipe circle radius
x0=r*cos(aplha1)+R;
z0=r*sin(aplha1);
y0=zeros(1,length(x0));
aplha2=0:pi/40:2*pi;
M=length(aplha2);
x= zeros(M,N);
y= zeros(M,N);
z= zeros(M,N);
for i=1:N
for j=1:M
x(j,i)=cos(aplha2(1,j))*x0(1,i);
y(j,i)=sin(aplha2(1,j))*x0(1,i);
z(j,i)=z0(1,i);
end
end
figure
mesh(x,y,z)
axis equal
figure
plot3(x(1,:),y(1,:),z(1,:),'color',[1 0 0],'LineWidth',2);
hold on
axis([-20,20,-20,20,-10,10]);
n=size(x,1);
hold on
grid on
line([0 0],[0 0],[-10 10],'linewidth',3);
for i=1:n-1
mesh(x(i:i+1,:),y(i:i+1,:),z(i:i+1,:));
drawnow;
% pause(0.2);
% alpha(0.5)
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'圆环.gif','gif', 'Loopcount',inf,'DelayTime',0.15);
else
imwrite(I,map,'圆环.gif','gif','WriteMode','append','DelayTime',0.15);
end
pic_num = pic_num + 1;
end