使用散点确定未知3D曲面的法线向量 [英] Determine normal vectors of unknown 3D surface using scattered points

查看:140
本文介绍了使用散点确定未知3D曲面的法线向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组(拓扑上简单的) 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曲面的法线向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆