Clipping 3D mesh along boundary, interp1 problem

조회 수: 5 (최근 30일)
Ingo Rück
Ingo Rück 2017년 8월 17일
답변: Jan 2017년 8월 21일
Hello everyone,
I'm currently trying to cut off parts of a 3D mesh that lie outside of a certain threshold. To do so, I use interp1 to check if a point on the grid is above or below my threshold. My upper and lower limit is created using the boundary function on a set of points as shown in the first figure (X-Y view).
I set every point that is outside of the boundary to NaN with following code, where xm,ym,zm are the matrices generating the mesh, lower/upper contain the points from the boundary function, so that x(lower),y(lower) forms the lower border.
for i=1:size(zm,1)
for j=1:size(zm,2)
dyl=interp1(x(lower),y(lower),xm(i,j));
dyu=interp1(x(upper),y(upper),xm(i,j));
if ym(i,j)-dyl<0 || ym(i,j)-dyu>0
zm(i,j)=NaN;
end
end
end
After setting all the values to NaN the following mesh remains.
To me it looks like the code worked at least in some places, but I cant figure out what causes the steep cuts along the upper border. My guess is that interp1 has problems giving interpolated values where the boundary has sharp bends. I tried using polyfit to compare the y-values to a fit function, both using boundary and convhull for the borders, but the results were not usable.
Can anyone see the problem here and is there a different/better way to do this?
Thanks for your help!
  댓글 수: 2
Ingo Rück
Ingo Rück 2017년 8월 21일
All the methods listed in the documentation of 'interp1' give worse results, with the exception of 'pchip', which looks roughly the same as 'linear'.
Jan
Jan 2017년 8월 21일
편집: Jan 2017년 8월 21일
The question is not clear yet. What is "upper" and "lower", "x" and "y" here? Why do you use an interpolation at all? The explanation mentions 3D, but the diagram and the code looks like 2D.
Do you want to set all points outside the boundary to NaN?

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2017년 8월 21일
Check inpolygon ....with this you should be able to tell whether the given point lies inside or outside the given closed region.
  댓글 수: 1
Ingo Rück
Ingo Rück 2017년 8월 21일
This is just what I was looking for, works perfectly! Thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 8월 21일
Do you want to set all points outside the boundary to NaN?
K = boundary(x, y); % Or with a matching shrink factor
Shape = alphaShape(x(K), y(K)); % Or with specific Alpha
Match = inShape(Shape, DataPoints);
DataPoints(~Match) = NaN;
I guessed the meaning of "x" and "y" and introduced the "DataPoints", because these details are not clear in the question. If you cannot adjust this to your real code, please post more details.

카테고리

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