matlab中如何打出心,如何在MATLAB中再现这个心形网格?

这篇博客介绍了如何使用MATLAB生成一个心脏形状的三维轮廓网格,并通过添加其他元素如坐标轴和数学公式创建一个艺术化的视觉效果。作者使用了CONTOURC函数和isosurface来构建和填充网格,并通过调整视角和添加文字来增强图像的呈现。
摘要由CSDN通过智能技术生成

这是我最好的复制整个人物的尝试:

生成轮廓心网:

我使用CONTOURC函数在x-y,x-z和y-z平面中生成一系列轮廓.请注意,在要重现的图像中,心脏背面侧的网格线不会呈现.我想到的最简单的方法就是使用ISOSURFACE渲染一个白色表面,正好在网格的内表面之下,阻挡了背面的视图.

这是功能心脏的代码:

function heart

% Initialize the volume data, figure, and axes:

[X,Y,Z] = meshgrid(linspace(-3,3,101));

F = -X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;

hFigure = figure('Position',[200 200 400 400],'Color','w');

hAxes = axes('Parent',hFigure,'Units','pixels',...

'Position',[1 1 400 400],'NextPlot','add',...

'DataAspectRatio',[1 1 1],'Visible','off',...

'CameraViewAngle',10,...

'XLim',[32 70],'YLim',[39 63],'ZLim',[34 73]);

view([-39 30]);

% Create and plot contours in the y-z plane:

for iX = [35 38 41 45 48 51 54 57 61 64 67]

plane = reshape(F(:,iX,:),101,101);

cData = contourc(plane,[0 0]);

xData = iX.*ones(1,cData(2,1));

plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'k');

end

% Create and plot contours in the x-z plane:

for iY = [41 44 47 51 55 58 61]

plane = reshape(F(iY,:,:),101,101);

cData = contourc(plane,[0 0]);

yData = iY.*ones(1,cData(2,1));

plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'k');

end

% Create and plot contours in the x-y plane:

for iZ = [36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 69 71]

plane = F(:,:,iZ);

cData = contourc(plane,[0 0]);

startIndex = 1;

if size(cData,2) > (cData(2,1)+1)

startIndex = cData(2,1)+2;

zData = iZ.*ones(1,cData(2,1));

plot3(hAxes,cData(1,2:(startIndex-1)),...

cData(2,2:(startIndex-1)),zData,'k');

end

zData = iZ.*ones(1,cData(2,startIndex));

plot3(hAxes,cData(1,(startIndex+1):end),...

cData(2,(startIndex+1):end),zData,'k');

end

% Fill the inside of the mesh with an isosurface to

% block rendering of the back side of the heart:

p = patch(isosurface(F,-0.001));

set(p,'FaceColor','w','EdgeColor','none');

end

将图合在一起:

为了再现整个图形,我首先使用上面的心脏功能生成心脏网格,然后在其周围添加其他元素.我还使用了The MathWorks File Exchange的一些提交:

这里是函数I_Heart_Math(生成上图)的代码:

function I_Heart_Math

% Initialize heart plot and adjust figure and axes settings:

heart;

set(gcf,'Position',[200 200 700 300],'Name','Original image');

offset = get(gca,'CameraPosition')-get(gca,'CameraTarget');

offset = 35.*offset./norm(offset);

set(gca,'Position',[65 -9 300 300],'CameraViewAngle',6,...

'XLim',[21+offset(1) 70],'YLim',[16+offset(2) 63],...

'ZLim',[32 81+offset(3)]);

% Create the axes and labels, offsetting them in front of the

% heart to give the appearance they are passing through it:

arrowStarts = [81 51 51; 51 86 51; 51 51 32]+repmat(offset,3,1);

arrowEnds = [21 51 51; 51 16 51; 51 51 81]+repmat(offset,3,1);

arrow(arrowStarts,arrowEnds,5,40,40);

text('Position',[22 52 48]+offset,'String','x','FontSize',12);

text('Position',[50 17 49]+offset,'String','y','FontSize',12);

text('Position',[46.5 51 81.5]+offset,'String','z','FontSize',12);

% Create the equation text:

text('Position',[51 47 28],'FontName','Bookman','FontSize',8,...

'HorizontalAlignment','center',...

'String',{'(x^2+^9/_4y^2+z^2-1)^3-x^2z^3-^9/_{80}y^2z^3=0'; ...

'-3 \leq x,y,z \leq 3'});

% Create the large-type text:

hI = text('Position',[4 52 69.5],'String','I',...

'FontAngle','italic','FontName','Trebuchet MS',...

'FontSize',116,'FontWeight','bold');

hM = text('Position',[80.5 50 42.5],'String','Math',...

'FontAngle','italic','FontName','Trebuchet MS',...

'FontSize',116,'FontWeight','bold');

% Create an anti-aliased version of the figure too (the larger

% fonts need some adjustment to do this... not sure why):

set(hI,'Position',[4 52 68],'FontSize',86);

set(hM,'Position',[80.5 50 41],'FontSize',86);

myaa;

set(hI,'Position',[4 52 69.5],'FontSize',116);

set(hM,'Position',[80.5 50 42.5],'FontSize',116);

set(gcf,'Name','Anti-aliased image');

end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值