在构建点云之后,我想得到每个点的法线,我使用了内置的matlab函数surfnorm但是它需要大量的处理时间。所以如果有人能帮助我做一个更好,更有效的方式。
答案 0 :(得分:3)
我想知道以下代码是否会对您有所帮助。这里有三个步骤。
sinc
函数的相应值z(表面的高度)TriScatteredInterp
函数重新取样随机点 - 这允许我在均匀采样的网格上获得与初始表面“大致对应”的点我使用的代码如下:
randomX = rand(1,500);
randomY = rand(1,500);
r = 5*sqrt(randomX.^2 + randomY.^2);
randomZ = sin(r) ./ r;
% resample the data:
[xx yy] = meshgrid(linspace(0,1,640), linspace(0,1,480));
F = TriScatteredInterp(randomX(:), randomY(:), randomZ(:));
zz = F(xx, yy);
%% at each point, the normal is cross product of vectors to neighbors
xyz=reshape([xx yy zz],[size(xx) 3]);
xv = 10:30:479; yv = 10:30:639; % points at which to compute normals
dx = xyz(xv, yv+1, :) - xyz(xv, yv, :);
dy = xyz(xv+1, yv, :) - xyz(xv, yv, :);
normVecs = cross(dx, dy); % here we compute the normals.
normVecs = normVecs ./ repmat(sqrt(sum(normVecs.^2, 3)), [1 1 3]);
figure;
quiver3(xx(xv, yv), yy(xv, yv), zz(xv, yv), ...
normVecs(:,:,1), normVecs(:,:,2), normVecs(:,:,3));
axis equal
view([56 22]);
由此产生的情节: