当前位置: 首页 > news >正文

MATLAB旋转动图的绘制

MATLAB旋转动图的绘制

文章目录

  • MATLAB旋转动图的绘制
    • 1、动图效果
    • 2、matlab代码

利用matlab实现三维旋转动图的绘制。

1、动图效果

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

2、matlab代码

close all
clear
clcf=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;
[x,y,z]=meshgrid(linspace(-3,3));
val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0);
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');
view(3);grid on;axis equal;% f=@(x,y,z)(x.^2+ (9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;
% [x,y,z]=meshgrid(linspace(-1.5,1.5));
% val=f(x,y,z);
% isosurface(x,y,z,val,0); 
% axis equal;view(3);colormap([1 0.2 0.2])
% spinningGIF('心形图1.gif');% el=-45;  %设置仰角为30度。
% for az=0:1:1080  %让方位角从0变到360,绕z轴一周
%     view(az,el);
%     drawnow;
% end% az= 345;   %设置方位角为0
% for el=0:1:360*1000   %仰角从0变到360
%     view(az,el);
%     drawnow;
% end% spinningGIF(fname): makes a spinning GIF of the current plot and saves it
% Usage: make your 3D plot (using plot3(...) or scatter3(...) etc.) and
% then call SpinningGIF with the file name that you want
function spinningGIF(fname)
%     axis off
%     view(0,10)center = get(gca, 'CameraTarget');pos = get(gca, 'CameraPosition');radius = norm(center(1:2) - pos(1:2));angles = 0.5*pi:0.02*pi:1.5*pi;for ii=1:length(angles)angle = angles(ii);set(gca, 'CameraPosition', [center(1) + radius * cos(angle),...center(2) + radius * sin(angle),...pos(3)]);drawnow;frame = getframe(1);im = frame2im(frame);[imind,cm] = rgb2ind(im,256);if ii == 1imwrite(imind,cm,fname,'gif', 'Loopcount',inf);elseimwrite(imind,cm,fname,'gif','WriteMode','append','DelayTime', 0.25);endend
endt = 0:0.5:10;   % 设置间隔filename = 'test.gif';   % 打开或者创建一个gif文件for i = 1:length(t)% 动画效果c = (1+0.3*cos(2*t(i)));th=0: pi/50: pi;phi=0: pi/50:2* pi;[Th, Phi]=meshgrid(th, phi);X=0.9* abs(Th).* sin(Th).* cos(Phi)*c;Y=abs(Th).* sin(Th).* sin(Phi)*c;Z=abs(Th).* cos(Th)*c;surf(X,Y,Z)axis equalaxis([-3 3 -3 3 -4 1]);shading interpcolormap([1 0 0])light('Position',[2 1 2])% 写入gif过程CurrFrame = getframe;   % 获取像素,否则无法显示动画im = frame2im(CurrFrame);   % [A,map] = rgb2ind(im,256);  % 将RGB图像转换为索引图像if i == 1imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0.1);  % DelayTime表示写入的时间间隔elseimwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0.1);end
end
http://www.lryc.cn/news/154526.html

相关文章:

  • 算法笔记 近似最近邻查找(Approximate Nearest Neighbor Search,ANN)
  • uni-app 之 vue语法
  • Android之RecyclerView仿ViewPage滑动
  • 【owt-server】AudioSendAdapter分析
  • day33 List接口
  • 云原生周刊:Linkerd 发布 v2.14 | 2023.9.4
  • CS420 课程笔记 P5 - 内存编辑 数据类型
  • oracle报错 ORA-02290: 违反检查约束条件问题
  • Prometheus + grafana 的监控平台部署
  • npm、yarn、pnpm
  • 力扣|两数相加
  • prometheus通过blackbox-exporter监控web站点证书
  • CentOS7 Hadoop3.3.0 安装与配置
  • 2023年9月CDGA/CDGP数据治理认证考试报名,当然弘博创新
  • Re45:读论文 GPT-1 Improving Language Understanding by Generative Pre-Training
  • VB.NET 如何将某个Excel的工作表中复制到另一个的Excel中的工作表中https://bbs.csdn.net/topics/392861034
  • 深入解析Kotlin类与对象:构造、伴生、单例全面剖析
  • JavaScript构造函数
  • 手写嵌入式操作系统(基于stm8单片机)
  • vue3.3 ~
  • 滑动窗口实例4(将x减到0的最小操作数)
  • 数据库原理及应用(MySQL)
  • 初识Maven(一)命令行操作和idea创建maven工程
  • MHA高可用配置及故障切换
  • FPGA/IC秋招面试题 1(解析版)
  • 华为云 异构数据迁移
  • wininet,winhttp,xmlhttprequest,各版本区别 《转》
  • 朴素,word,任何参考文献导入endnote
  • 数学建模--三维图像绘制的Python实现
  • Spring Cloud Alibaba-Feign整合Sentinel