필터 지우기
필터 지우기

User defined surface grid

조회 수: 35 (최근 30일)
Lars
Lars 2013년 11월 27일
편집: Hannes Eschmann 2019년 11월 28일
Hallo.
I am currently having troubles with defining a grid on the surface of my 3D plot (created by using mesh-function to plot with).
Would like to have something in between what's seen on the pictures below.
Wish to create following grid:
  • Horizontal lines (parallel with x-axis) for z = (0:1:10)
  • Vertical lines (parallel with z-axis) for x = (-10:2:10).
My code:
[X,Y] = meshgrid(-8:.1:8);
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
surf(X,Z,Y,Z)
set(gca,'YDir','Reverse','ZDir','Reverse')
colorbar; ylabel('y'); xlabel('x'); zlabel('z') ;
shading interp % To create right picture
What is the Matlab command for creating a surface grid as i wish?

채택된 답변

Jeremy Wurbs
Jeremy Wurbs 2013년 11월 28일
Ahh, I see. That is trickier. I get slightly better results by changing
mesh(XX,ZZ,YY,ZZ);
to
surf(XX,ZZ,YY,ZZ,'FaceAlpha',0)
although some of the edges are hidden still. If you're willing to cheat a little you can stick the edges out a tad bit:
surf(XX,ZZ+0.03,YY,ZZ,'FaceAlpha',0)
which seems to produce decent results.
  댓글 수: 1
Lars
Lars 2013년 11월 29일
Thank you so much for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jeremy Wurbs
Jeremy Wurbs 2013년 11월 27일
편집: Jeremy Wurbs 2013년 11월 27일
Great question. If I'm understanding correctly, you don't like the lines connecting your points to be so prevalent. You can fix this in your surf line:
surf(X,Z,Y,Z, 'EdgeAlpha', alpha)
Where alpha is some value between 0 and 1 (0.2 is probably good).
Hope that helps and is what you were looking for. Cheers.

Lars
Lars 2013년 11월 28일
Thanks a lot for the answer so far. It improved a lot on the figure.
However it was not entirely what i was looking for. In the picture below i want a combination where i have the smoothness of the surface from the left picture but the gridlines from the right picture.
I tried with following code, where i create 3D plots in same figure, but can't get the "mesh" to be transparent.
[X,Y] = meshgrid(-8:0.1:8) ;
[XX,YY] = meshgrid(-8:1:8) ;
R = sqrt(X.^2 + Y.^2) + eps ;
Z = sin(R)./R ;
ZZ = (Z((1:10:size(Z)),(1:10:size(Z)))) ;
surf(X,Z,Y,Z,'EdgeAlpha', 0) ; hold on
mesh(XX,ZZ,YY,ZZ);
set(gca,'YDir','Reverse','ZDir','Reverse')
colorbar; ylabel('y'); xlabel('x'); zlabel('z') ;
The result is as following, which i don't like either:
  댓글 수: 1
Hannes Eschmann
Hannes Eschmann 2019년 11월 28일
편집: Hannes Eschmann 2019년 11월 28일
an excessive way of archiving a smooth coarse grid, would be to just create it yourself, e.g., via
smoothMesh(X,Y,Z,10,'k',1,1)
where
function smoothMesh(X,Y,Z,delta,color,alp,w)
hold on
for i = 1:delta:size(X,1)
p = plot3(X(i,:),Y(i,:),Z(i,:),color,'LineWidth',w);
p.Color(4) = alp;
end
p = plot3(X(end,:),Y(end,:),Z(end,:),color,'LineWidth',w);
p.Color(4) = alp;
for i = 1:delta:size(X,2)
p = plot3(X(:,i),Y(:,i),Z(:,i),color,'LineWidth',w);
p.Color(4) = alp;
end
p = plot3(X(:,end),Y(:,end),Z(:,end),color,'LineWidth',w);
p.Color(4) = alp;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by