旋转直线形成单叶双曲面matlab程序动画
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
x1=-2:0.2:2;
y1=x1;
[x,y]=meshgrid(x1,y1);
a=1;b=1;c=1;% 假设a=1;b=1;c=1
z1=sqrt(c.^2*(x.^2/(a.^2)+y.^2/(b.^2)+1));
z2=-sqrt(c.^2*(x.^2/(a.^2)+y.^2/(b.^2)+1));
mesh(x,y,z1)
hold on;
mesh(x,y,z2)
>> x=[-0.6,0.8];
y=[0.8,-0.6];
z=[3.0,-3.0];
[th,phi,r]=cart2sph(x,y,z);
n=120;%divided the circle into n pieces
k=24;%pause and write it to the animation every k pieces
% figure properties setting
hf=figure;
axis([-2,2,-2,2,-4,4]);
hold on
% lines
hc=plot3([0,0],[0,0],[-3.9,3.9],'b');
hl0=plot3(x,y,z,'r');
hlt0=plot3([0,x(1)],[0,y(1)],[z(1),z(1)],'r--');
hlb0=plot3([0,x(2)],[0,y(2)],[z(2),z(2)],'r--');
% gif figure setting
gifFilename='UnipartedHyperboloid.gif';
ifr=0;
for i=1:n
% temporary
[xt,yt,zt]=sph2cart(th+2*pi*i/n,phi,r);
% draw a pieces of patch (to get a surface by many pieces) hp=fill3([x(1),xt(1),xt(2),x(2)],[y(1),yt(1),yt(2),y(2)],...
[z(1),zt(1),zt(2),z(2)],'g');%[1,0.667,0.333,0] set(hp,'LineStyle','none')
set(hp,'FaceAlpha',0.7)
% plot lines
plot3([x(1),xt(1)],[y(1),yt(1)],[z(1),zt(1)],'r');
plot3([x(2),xt(2)],[y(2),yt(2)],[z(2),zt(2)],'r');
x=xt;y=yt;z=zt;
if i>=2
delete(hl)
delete(hlt)
delete(hlb)
end
hl=plot3(x,y,z,'r');
hlt=plot3([0,x(1)],[0,y(1)],[z(1),z(1)],'r--');
hlb=plot3([0,x(2)],[0,y(2)],[z(2),z(2)],'r--');
if(mod(n,k)==0)
pause(.05)
%write the frame to gif file
ifr=ifr+1;
hfr=getframe(hf);
im=frame2im(hfr);
[I,map]=rgb2ind(im,256);
if ifr==1
imwrite(I,map,gifFilename,'gif','Loopcount',1,'DelayTime',0.1);
else
imwrite(I,map,gifFilename,'gif','WriteMode','append','DelayTime',0.1);
end
end
end