查看: 8202| 回复: 29
跳转到指定楼层
上一主题 下一主题
收起左侧

[zz] I <3 Math: 用MATLAB画出3D心型

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
不素偶写的code :P

原帖地址:http://stackoverflow.com/questio ... aped-mesh-in-matlab



MATLAB code:
  1. % Initialize the volume data, figure, and axes:
  2. [X,Y,Z] = meshgrid(linspace(-3,3,101));
  3. F = -X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;
  4. hFigure = figure;
  5. sz = get(hFigure, 'Position');
  6. set(hFigure, 'Position', [sz(1)-0.15*sz(3) sz(2) 1.3*sz(3) sz(4)]);
  7. set(hFigure,'color','w', 'menu','none')

  8. hAxes = axes('Parent',hFigure,'NextPlot','add',...
  9.     'DataAspectRatio',[1 1 1],...
  10.     'XLim',[30 120],'YLim',[35 65],'ZLim',[30 75]);
  11. view([-39 30]);
  12. axis off

  13. % hidden surface removal
  14. hidden on

  15. % Fill the inside of the mesh with an isosurface to
  16. % block rendering of the back side of the heart
  17. p = patch(isosurface(F,-0.001));
  18. set(p,'FaceColor','w','EdgeColor','none');

  19. % Create and plot contours in the y-z plane:
  20. for iX = [35 38 41 45 48 51 54 57 61 64 67]
  21.     plane = reshape(F(:,iX,:),101,101);
  22.     cData = contourc(plane,[0 0]);
  23.     xData = iX.*ones(1,cData(2,1));
  24.     plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'k');
  25.     pause(.1), drawnow
  26. end

  27. % Create and plot contours in the x-z plane:
  28. for iY = [41 44 47 51 55 58 61]
  29.     plane = reshape(F(iY,:,:),101,101);
  30.     cData = contourc(plane,[0 0]);
  31.     yData = iY.*ones(1,cData(2,1));
  32.     plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'k');
  33.     pause(.1), drawnow
  34. end

  35. % Create and plot contours in the x-y plane:
  36. for iZ = [36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 69 71]
  37.     plane = F(:,:,iZ);
  38.     cData = contourc(plane,[0 0]);
  39.     startIndex = 1;
  40.     if size(cData,2) > (cData(2,1)+1)
  41.         startIndex = cData(2,1)+2;
  42.         zData = iZ.*ones(1,cData(2,1));
  43.         plot3(hAxes,cData(1,2:(startIndex-1)),...
  44.                 cData(2,2:(startIndex-1)),zData,'k');
  45.     end
  46.     zData = iZ.*ones(1,cData(2,startIndex));
  47.     plot3(hAxes,cData(1,(startIndex+1):end),...
  48.         cData(2,(startIndex+1):end),zData,'k');
  49.     pause(.1), drawnow
  50. end
  51. pause(.2)

  52. text(7,50,70,'I', 'fontWeight','bold','FontAngle','italic','fontsize',100)
  53. pause(.5)
  54. text(80,50,43,'Math', 'fontWeight','bold','FontAngle','italic','fontsize',100)
  55. pause(.2)

  56. line([20 80],[50 50],[52.5 52.5], 'color','k')
  57. line([50 50],[20 80],[52.5 52.5], 'color','k')
  58. line([50 50],[50 50],[30 80], 'color','k')
  59. text(20,50,50,'x')
  60. text(48,20,50,'y')
  61. text(45,50,80,'z')

  62. text(30,60,30,'(x^2+9/4y^2+z^2-1)^3 - x^2z^3-9/80y^2z^3=0', 'fontsize',8)
  63. text(35,45,30,'-3<x,y,z<3', 'fontsize',8)
复制代码
####

for Statistics geeks:

上一篇:【总结】电子书free下载资源汇总,欢迎添加
下一篇:FF 记不住login info是需要清空啥地方的?
🔗
modifiedname 2011-3-25 12:20:27 | 只看该作者
全局:
端木mm发的水贴都 总是这么有含金量
回复

使用道具 举报

🔗
zach 2011-3-25 12:25:28 | 只看该作者
全局:
本帖最后由 zach 于 2011-3-24 23:38 编辑

以前看过mathematica版本的,只要一句话……比MATLAB方便好多啊……
3D:
http://goo.gl/jDxGi
2D:
http://goo.gl/UXePi
回复

使用道具 举报

🔗
 楼主| duanmupeiyi 2011-3-25 12:37:36 | 只看该作者
全局:
回复 3# zach

赞~ 2d版本也不错~
回复

使用道具 举报

🔗
modifiedname 2011-3-25 12:57:26 | 只看该作者
全局:
我想知道这些公式是如何推出来的那?
回复

使用道具 举报

🔗
zach 2011-3-25 13:01:08 | 只看该作者
全局:
我想知道这些公式是如何推出来的那?
小K 发表于 2011-3-24 23:57

貌似是神马笛卡尔曲线
回复

使用道具 举报

🔗
RehsuR 2011-3-25 13:18:34 | 只看该作者
全局:
本帖最后由 RehsuR 于 2011-3-24 23:22 编辑

哈! 我有这个心的t-shirt! 穿到实验室被大家感慨, chinese geek啊.......哈哈, 有人很羡慕也想买, 我说是在中国的网站买的, 于是对方很郁闷, 哈哈哈
这个, 是matrix67设计的, 这里, 我前些日子才知道这个数学大牛居然是北大中文系的!
回复

使用道具 举报

🔗
zach 2011-3-25 13:33:52 | 只看该作者
全局:
哈! 我有这个心的t-shirt! 穿到实验室被大家感慨, chinese geek啊.......哈哈, 有人很羡慕也想买, 我说是在 ...
RehsuR 发表于 2011-3-25 00:18

太简单了有没有%……
自己拿MATLAB画出来,然后去:
http://www.customink.com/
把图片upload上去,还可以写你想写的whatever内容
回复

使用道具 举报

🔗
RehsuR 2011-3-25 13:41:55 | 只看该作者
全局:
太简单了有没有%……
自己拿MATLAB画出来,然后去:

把图片upload上去,还可以写你想写的whatever内容 ...
zach 发表于 2011-3-24 23:33


那哥们儿天天用mathematica做modeling, 肯定是可以做, 但是还没geek到那个份儿上吧...懒得追细节了, 只是觉得特cool, 呵呵~
回复

使用道具 举报

🔗
Saber 2011-3-25 15:58:27 | 只看该作者
全局:
哈! 我有这个心的t-shirt! 穿到实验室被大家感慨, chinese geek啊.......哈哈, 有人很羡慕也想买, 我说是在 ...
RehsuR 发表于 2011-3-25 13:18



    国内买了带过去?
   读Phd前就这么Geek啊....
     仰慕....
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表