All the methods listed in the documentation of 'interp1' give worse results, with the exception of 'pchip', which looks roughly the same as 'linear'.
Clipping 3D mesh along boundary, interp1 problem
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!