Azzera filtri
Azzera filtri

User defined surface grid

35 visualizzazioni (ultimi 30 giorni)
Lars
Lars il 27 Nov 2013
Modificato: Hannes Eschmann il 28 Nov 2019
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?

Risposta accettata

Jeremy Wurbs
Jeremy Wurbs il 28 Nov 2013
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.

Più risposte (2)

Jeremy Wurbs
Jeremy Wurbs il 27 Nov 2013
Modificato: Jeremy Wurbs il 27 Nov 2013
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 il 28 Nov 2013
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 Commento
Hannes Eschmann
Hannes Eschmann il 28 Nov 2019
Modificato: Hannes Eschmann il 28 Nov 2019
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;

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by