Extract row from Surface

조회 수: 3 (최근 30일)
Detox
Detox 2016년 7월 5일
댓글: José-Luis 2016년 7월 6일
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에서 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