用单独的颜色绘制法线(箭)

时间:2016-04-29 10:50:19

标签: matlab matlab-figure

我在 N 的相应位置有一个法线矩阵 L ,例如由函数 pcnormals计算。我现在可以使用 quiver3 函数在其位置绘制法线。这一切都很好,但如果我想根据它们与其他矢量的角度对法线(即它们各自绘制的箭头)进行着色会怎样呢?

我没有发现使用 quiver3 功能这样做的可能性。我错过了什么,或者我能用另一个功能实现我的目标吗?

示例:

load('object3d.mat');
normals = pcnormals(ptCloud);
x = ptCloud.Location(1:10:end,1:10:end,1);
y = ptCloud.Location(1:10:end,1:10:end,2);
z = ptCloud.Location(1:10:end,1:10:end,3);
u = normals(1:10:end,1:10:end,1);
v = normals(1:10:end,1:10:end,2);
w = normals(1:10:end,1:10:end,3);
quiver3(x,y,z,u,v,w);   % this plots the normals with one color
% calculate the angle to some other vector
sensorCenter = [0,0,0];
angles = zeros(numel(x),1);
for k = 1 : numel(x)
   p1 = sensorCenter - [x(k),y(k),z(k)];
   p2 = [u(k),v(k),w(k)];
   % Flip the normal vector if it is not pointing towards the sensor.
   angle = atan2(norm(cross(p1,p2)),p1*p2');
   if angle > pi/2 || angle < -pi/2
       u(k) = -u(k);
       v(k) = -v(k);
       w(k) = -w(k);
       if angle > pi/2, angle = angle - pi/2; end
       if angle < -pi/2, angle = angle + pi/2; end
   end
   angles(k) = angle;
end
% know we have a vector of angles containing values between 0 and pi/2
% TODO: color quivers according to value in angles

0 个答案:

没有答案