Extract row from Surface

2 次查看(过去 30 天)
Detox
Detox 2016-7-5
I created a surface with the following commands:
x2 = xCoord2;
y2 = yCoord2;
z2 = zCoord2;
tri2 = delaunay(x2,y2);
figure
trisurf(tri2,x2,y2,z2)
The problem I have now is the following: How can I extract a "row" from the surface in order to generate a x-z-Plot for an arbitrary row? Is this even possible for a triangularized surface? Thanks in advance!

回答(2 个)

KSSV
KSSV 2016-7-6
编辑:KSSV 2016-7-6
It is not that easy in Triangular Surface plot to extract a row of (x,z). Because, if you fix to some value of x, there is no fast rule that there exists a straight line with given nodal coordinates for chosen x. The line will deviate in a range of x+dx or x-dx. Three ways to achieve your task.
1) You have an option of plotting contours. If you want to plot a certain value z, you can use contour algorithms. These algorithms give you location (x,y) which have given value 'z'. From these locations you can search your x. Again not exactly x but you need to give a range x+dx to x-dx. You may find the contouring algorithm on triagular unstructured meshes from the below link:
https://in.mathworks.com/matlabcentral/fileexchange/38925-linearly-interpolate-triangulation/content/interptri.m
2) Fix your x,z and extract all the elements which have the given x. You will end up with the elements having the given x and z.
3) Convert your unstructured grid to structured, which makes extracting specific 'x' very easy.
  2 个评论
José-Luis
José-Luis 2016-7-6
I don't understand what you mean.
Detox
Detox 2016-7-6
Thanks for the detailed answer mate! I will give it a try later on and tell you how it worked.

请先登录,再进行评论。


José-Luis
José-Luis 2016-7-6
编辑:José-Luis 2016-7-6
%Say you want the line at x = 0.2
val = 0.2;
% Define the input grid
[x, y] = meshgrid(linspace(-1, 1));
% Calculate the two surfaces
z1 = y.^2 + 2*x;
z2 = x;
% Visualize the two surfaces
surface(x, y, z1, 'FaceColor', [0.5 1.0 0.5], 'EdgeColor', 'none');
surface(val.*ones(size(x)), y, z2, 'FaceColor', [1.0 0.5 0.0], 'EdgeColor', 'none');
view(3); camlight; axis vis3d
% Take the difference between the two surface heights and find the contour
% where that surface is zero.
zdiff = z1 - z2;
C = contours(val.*ones(size(x)), y, zdiff, [0 0]);
% Extract the x- and y-locations from the contour matrix C.
xL = C(1, 2:end);
yL = C(2, 2:end);
% Interpolate on the first surface to find z-locations for the intersection
% line.
zL = interp2(x, y, z1, xL, yL);
% Visualize the line.
line(xL, yL, zL, 'Color', 'k', 'LineWidth', 3);
xL and yL should be the coordinates of the intersection of the two planes. It hopefully should be evident from the plot. You'd need to replace x, y and z with your actual values.
  2 个评论
Detox
Detox 2016-7-6
Thanks for your answer. I do not think I can apply the meshgrid function on my x and y arrays. I will see if it works! :)
José-Luis
José-Luis 2016-7-6
You wouldn't need to apply meshgrid, just replace with the values you actually have.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Delaunay Triangulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by