Matlab--三维散点插值成曲面

问题:已知一系列三维的散点坐标,得到一个经过这些散点的曲面图。

  •  实例

    构造一个曲面分布,从曲面上取一些特征点,然后依据这些特征点进行二维插值,用到了griddata函数,提取的特征点越多,插值得到的曲面和原始曲面越接近。

  1. clear; clc;
  2. [X, Y, Z] = peaks(30);
  3. position = [13,26; 20,24; 16,27; 16, 21; 16,24; 9,19; 9,15; 7,17; 12,17; 9,17; 14,16; 14,11;
  4. 11,12; 16,12; 14,13; 17,11; 16,5; 13,8; 20,8; 17,8; 22,19; 22,12; 20,16; 25,16; 22,16];
  5. p1 = position(:, 1);
  6. p2 = position(:, 2);
  7. x = zeros(1,length(p1));
  8. y = zeros(1, length(p1));
  9. z = zeros(1, length(p1));
  10. for i = 1 : length(p1)
  11. x(i) = X(p1(i), p2(i));
  12. y(i) = Y(p1(i), p2(i));
  13. z(i) = Z(p1(i), p2(i));
  14. end
  15. subplot(1,2,1)
  16. surf(X, Y, Z)
  17. hold on
  18. plot3(x, y, z, 'or', 'MarkerFaceColor', 'r');
  19. hold off
  20. ylim([-2, 2]);
  21. [Xi,Yi,Zi] = griddata(x,y,z,linspace(min(x),max(x), 30)',linspace(min(y),max(y), 30),'v4');
  22. subplot(1,2,2)
  23. surf(Xi,Yi,Zi)
  24. hold on
  25. plot3(x, y, z, 'or', 'MarkerFaceColor', 'r');
  26. hold off

转载自:https://blog.csdn.net/u012366767/article/details/83650305

展开阅读全文

没有更多推荐了,返回首页