Clipping 3D mesh along boundary, interp1 problem

3 visualizaciones (últimos 30 días)
Ingo Rück
Ingo Rück el 17 de Ag. de 2017
Respondida: Jan el 21 de Ag. de 2017
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 comentarios
Ingo Rück
Ingo Rück el 21 de Ag. de 2017
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 el 21 de Ag. de 2017
Editada: Jan el 21 de Ag. de 2017
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?

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 21 de Ag. de 2017
Check inpolygon ....with this you should be able to tell whether the given point lies inside or outside the given closed region.
  1 comentario
Ingo Rück
Ingo Rück el 21 de Ag. de 2017
This is just what I was looking for, works perfectly! Thank you very much!

Iniciar sesión para comentar.

Más respuestas (1)

Jan
Jan el 21 de Ag. de 2017
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.

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by