我有一组(拓扑上简单的) x,y,z 点.与它们每个相关联的是一个标量( s ).我想将结果可视化.
I have a set of (topologically simple) x,y,z points. Associated with each one of them is a scalar (s). I would like to visualize the results.
如何确定每个节点的(单位)法线,然后根据 s 进行缩放,或者有没有办法获得空间分布的表面图(与数据点平行绘制)飞机)?
How could I have the (unit) normal of each node determined and then scaled in accordance of s, or is there a way to get a spatially distributed surface plot (plotted parallel to the data points plane)?
这是3D点的示例:
推荐答案
如果未知曲面,则可以使用delaunay三角剖分法使用 delaunay 将曲面拟合到点上.然后,您可以使用 vertexNormal 查找法线向量.
If your surface is unknown, you can use delaunay to fit a surface on points using delaunay triangulation. Then you can find normal vectors using vertexNormal.
%% generating some sample data n = 1000; d = 6; zscale = 1/3; x = rand(n, 1)*d - d/2 ; y = rand(n, 1)*d - d/2; z = peaks(x, y)*zscale; s = 5./(1+(x.^2+y.^2)); %% calculating normal vectors T = delaunay(x,y); % triangulation connectivity matrix TR = triangulation(T,x,y,z); % the triangulation connectivity V = vertexNormal(TR); % normal vectors at triangle vertices
用于绘制以上图形的代码:
The code used to plot above figures:
figure, subplot 121 scatter3(x, y, z) [xg, yg, zg] = peaks(linspace(-d/2, d/2, 50)); zg = zg*zscale; mesh(xg, yg, zg) hold on scatter3(x, y, z, s*100, '.'); colormap jet axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2]) copyobj(get(subplot(121),'Children'),subplot(122)) legend('unknown surface', 'scattered data') axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2]) figure, subplot 121 hold on trisurf(T, x, y, z, 'edgealpha', 0.1) quiver3(x, y, z, ... V(:,1),V(:,2),V(:,3),2); grid on view(3) axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2]) colormap jet copyobj(get(subplot(121),'Children'),subplot(122)) legend('fitted surface', 'normal vectors') axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2]) figure, subplot 121 scatter3(x, y, z, '.') hold on quiver3(x, y, z, ... V(:,1).*s,V(:,2).*s,V(:,3).*s,5); view(3) axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2]) copyobj(get(subplot(121),'Children'),subplot(122)) legend('scattered points', 'scaled normal vectors') axis equal, xlim([-d/2 d/2]), ylim([-d/2 d/2])更多推荐
使用散点确定未知3D曲面的法线向量
发布评论