How to create 3D mesh surface that joins two parallel 2D data plots of similar sized X,Y sets let say a Z distance apart?
4 views (last 30 days)
Show older comments
M. Waleed Shaukat
on 11 Jul 2015
Commented: M. Waleed Shaukat
on 12 Jul 2015
Let say if I have X1 and X2 arrays of equal size which represent two different 2D plots whose Y arrays are identical and of similar size as that of X1 or X2.
The two plots represents parallel traces in 3D space that are separated from one another by Z=50. That is, plot(X1,Y) is at Z=0 and plot(X2,Y) is at Z=50 in 3D space. And I want to connect the two plots with one another through linear vector line relationship to form a 3D mesh surface.
How should I do this in MATLAB?
Thanks
4 Comments
Walter Roberson
on 12 Jul 2015
Simply connecting points of the two plots in a sequential manner does not result in a surface: it results in a set of line segments, (x1(J),y(J),0) joined to (x2(J),y(J),50)
If you want a ribbon between the two plots then you need to specify whether you want rectangular faces or triangular faces.
Accepted Answer
Walter Roberson
on 12 Jul 2015
X = [x1(:), x2(:)];
Y = [y(:), y(:)];
Z = [zeros(numel(x1),1); 50*ones(numel(x1),1)];
vert = [X, Y, Z];
N = numel(x1);
fac = [1:N-1; 2:N; N+2:2*N; N+1:2*N-1].';
patch('Faces', fac, 'Vertices', vert);
More Answers (0)
See Also
Categories
Find more on Surface and Mesh 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!