Hello... I want to get a diagonal cross section cut of the mesh plot. and want to get a 2D plot which have 1.) z axis of mesh plot nd 2.)Diagonal of the X and Y axis of mesh plot.Can anyone suggest me how can i do that.?? plz..need the solution ASAP.

19 views (last 30 days)
i want the diagonal cut of mesh plot.. can anyone help me for its coding.. here i am attaching the image of that mesh plot...
the function of this plot is as below.. [X,Y]=meshgrid(-2:0.25:2,-2:0.25:2); Z=X.*exp(-X.^2-Y.^2);
please if anyone is having idea about it then reply me... thanks in advance...

Accepted Answer

Mike Garrity
Mike Garrity on 31 Jul 2015
The problem I described in this blog post was about intersecting two implicit surfaces. That's not what you're trying to do here, but the solution I described actually works. The reason is that the approach I described was to create a mesh from the first implicit surface and then intersect that with the second. In your case, you have a mesh already, and the surface you want to intersect it with is simply
x==y
So, let's sneak up on it. We'll start with this:
[x,y] = meshgrid(-2:0.25:2,-2:0.25:2);
z = x.*exp(-x.^2-y.^2);
mesh(x,y,z)
Now we'll insert those vertices into our implicit equation.
t = x-y;
We can look at what we have like this:
surf(x,y,z,t,'FaceColor','interp')
colormap(lines(6))
So we want the line between the purple and the orange. On simple way of getting that would be this:
tol = 1e-8;
mask = abs(t) < tol;
x2 = x(mask);
y2 = y(mask);
z2 = z(mask);
plot3(x2,y2,z2)
Notice that I didn't compare t to 0 exactly. That's to avoid roundoff error problems.
Now we'll go back to 2D.
plot(x2,z2)
And you have a plot of the diagonal. That's pretty simple. It's actually too simple.
That only worked in this case because the points of the mesh actually lay on the diagonal. If you used some other implicit function you would have found that it went in between the points of your mesh and the mask didn't select any. In that case you need to find points which are on opposite sides of the line and compute the X,Y,Z where they edge connecting them crosses the line. That's what I was describing in that blog post . I'll leave that step as an exercise for you. The one hint is that I had a triangle mesh in that case, but you've got a quad mesh. That means that your case will be a little different where it comes to identifying edges that connect points on opposite sides.
Does that give you a good enough start?
  2 Comments
Mike Garrity
Mike Garrity on 31 Jul 2015
BTW, after hitting submit I noticed that you wanted the opposite diagonal. That means you'll need to change a sign in the implicit equation I used. Do you see how to do that?

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!