Deformed surf using griddata ?

조회 수: 6 (최근 30일)
Faez Alkadi
Faez Alkadi 2017년 8월 24일
댓글: Faez Alkadi 2017년 8월 25일
I have a set of data as attached. but when I surf them after using griddata. the result is deformed surf AS SHOWN IN THE PICTURE with red squares. Z values on the surf were supposed to follow the edges of the shape. I think its because there is something wrong with (z_surf) matrix in my code. But I don't know how to solve it.
Hope you can help me to solve this problem.
Thank you.
x_limit=xyz_board_ordered_dvd(:,1);
y_limit=xyz_board_ordered_dvd(:,2);
z_limit=xyz_board_ordered_dvd(:,3);
dx=1;
dy=1;
x_edge=floor(min(x_limit)):dx:ceil(max(x_limit));
y_edge=floor(min(y_limit)):dy:ceil(max(y_limit));
[x_surf,y_surf]=meshgrid(x_edge,y_edge);
z_surf=griddata(x_limit,y_limit,z_limit,x_surf,y_surf);
surf(x_surf,y_surf,z_surf)
xlabel('X')
ylabel('Y')
xlim([0 120])
ylim([0 120])
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 8월 24일
I notice that only 554 of the 604 points are unique.

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

채택된 답변

John D'Errico
John D'Errico 2017년 8월 24일
편집: John D'Errico 2017년 8월 24일
Easy, peasy.
Griddata will fail here. In fact, my own gridfit will produce some artifacts.
But essentially, you have a simple ribbon of the form z(y), which seems to be independent of x.
x = xyzSTL_board_ordered_dvd(:,1);
y = xyzSTL_board_ordered_dvd(:,2);
z = xyzSTL_board_ordered_dvd(:,3);
plot(y,z,'o')
There is NO x in that relationship. So all you need to do is fit the curve z(y). Use a spline. Start out by removing any replicates. Using my consolidator tool, as found on the file exchange :
[yhat,zhat] = consolidator(y,z,@mean);
plot(yhat,zhat,'-')
spl = pchip(yhat,zhat);
Use pchip here. This is fairly important.
[xgrid,ygrid] = ndgrid(linspace(min(x),max(x),10),linspace(min(y),max(y),100));
zgrid = repmat(ppval(spl,linspace(min(y),max(y),100)),10,1);
surf(xgrid,ygrid,zgrid)
  댓글 수: 8
Stephen23
Stephen23 2017년 8월 25일
Another option would be to fill "missing data" areas with NaNs, which will not be plotted.
Faez Alkadi
Faez Alkadi 2017년 8월 25일
편집: Faez Alkadi 2017년 8월 25일
John and Stephen,
Thank you so much for the explanation,
The data I got is from an .stl surface file. I'm wondering if there is any easier way to meshgrid and surf the a face of an .stl file.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 8월 24일
You can get closer to what you want if you add the 'nearest' option to the griddata() call.
You will get an odd artifact, which I figure is due to peculiarities about which is the "closest" point in 3-space.
There is no reason for the surface to follow the edge using griddata(). Gridding takes place in 3-space, so when you get sufficiently far from the edges, the closest points might be from a different z than you were picturing.
If you have a surface that you know should be a ribbon, then there are ways to decompose that.
  댓글 수: 2
Faez Alkadi
Faez Alkadi 2017년 8월 24일
편집: Faez Alkadi 2017년 8월 24일
Is there any other way to surf it and make it follow the shape edges other than using griddata?
Thank you so much
Faez Alkadi
Faez Alkadi 2017년 8월 25일
Walter,
The data I got is from an .stl surface file. I'm wondering if there is any easier way to meshgrid and surf the a face of an .stl file.
Thank you

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

카테고리

Help CenterFile Exchange에서 Surfaces and Volumes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by