将 3D 转换为点云
Transform 3D to PointCloud
我正在使用 Persistent Homology,我需要常见 3D 形状的云点才能测试我的方法。
问题是我是一名 Java 程序员并且 Java 不提供此类工具,但我很确定 Matlab 提供...我尝试在这里阅读:
http://www.mathworks.com/help/vision/ref/pcfitsphere.html
http://www.mathworks.com/help/matlab/ref/sphere.html
http://www.mathworks.com/help/vision/ref/pcshow.html#inputarg_ptCloud
这些链接提供了关于 Spheres 和 PointClouds 的信息,但我从来没有在 matlab 上编程过,所以我什至不能推荐代码。
有没有办法获取 3d 形状,获取它的点云并在控制台上打印点云?
喜欢:
x0, y0, z0
x1, y1, z1
x2, y2, z2
...
我正在做的是创建一个 Java class 来打印基于函数的随机点,所以例如我会给我的程序一个球体的函数......但是当我我正在尝试创建金字塔或三环面的功能。
这里是 points inside a sphere 的 MATLAB 例子:
% random points in spherical coordinates
N = 1000;
theta = 2*pi*rand(N,1);
phi = asin(2*rand(N,1)-1);
radii = 3*(rand(N,1).^(1/3));
% convert to cartesian
[x,y,z] = sph2cart(theta, phi, radii);
% plot
scatter3(x, y, z, 10, 'filled')
axis vis3d equal, grid on, box on
xlabel X, ylabel Y, zlabel Z
参考this。
编辑
这是另一个在金字塔内生成点的示例。
这次我采用蛮力方法,简单地在 [0,1] 立方体中生成大量随机 3d 点,然后通过 testing which points are inside the pyramid convex polyhedron 过滤它们(使用 Delaunay 三角剖分)。
% random points
N = 3000;
XYZ = rand(N,3);
% unit pyramid in [0,1]
V = [0 0 0 ;
1 0 0 ;
1 1 0 ;
0 1 0 ;
0.5 0.5 0 ;
0.5 0.5 sqrt(2)/2];
% delaunay triangulation
DT = delaunayn(V);
% determine points within
in = ~isnan(tsearchn(V, DT, XYZ));
% plot
scatter3(XYZ(in,1), XYZ(in,2), XYZ(in,3), 8, 'filled')
view(3), axis vis3d equal, grid on, box on
axis([0 1 0 1 0 1])
xlabel X, ylabel Y, zlabel Z
% overlay pyramid
hold on
h = tetramesh(DT, V);
set(h, 'FaceAlpha',0.1, 'EdgeColor','m', 'FaceColor','m')
hold off
我正在使用 Persistent Homology,我需要常见 3D 形状的云点才能测试我的方法。
问题是我是一名 Java 程序员并且 Java 不提供此类工具,但我很确定 Matlab 提供...我尝试在这里阅读:
http://www.mathworks.com/help/vision/ref/pcfitsphere.html
http://www.mathworks.com/help/matlab/ref/sphere.html
http://www.mathworks.com/help/vision/ref/pcshow.html#inputarg_ptCloud
这些链接提供了关于 Spheres 和 PointClouds 的信息,但我从来没有在 matlab 上编程过,所以我什至不能推荐代码。
有没有办法获取 3d 形状,获取它的点云并在控制台上打印点云? 喜欢:
x0, y0, z0
x1, y1, z1
x2, y2, z2
... 我正在做的是创建一个 Java class 来打印基于函数的随机点,所以例如我会给我的程序一个球体的函数......但是当我我正在尝试创建金字塔或三环面的功能。
这里是 points inside a sphere 的 MATLAB 例子:
% random points in spherical coordinates
N = 1000;
theta = 2*pi*rand(N,1);
phi = asin(2*rand(N,1)-1);
radii = 3*(rand(N,1).^(1/3));
% convert to cartesian
[x,y,z] = sph2cart(theta, phi, radii);
% plot
scatter3(x, y, z, 10, 'filled')
axis vis3d equal, grid on, box on
xlabel X, ylabel Y, zlabel Z
参考this。
编辑
这是另一个在金字塔内生成点的示例。
这次我采用蛮力方法,简单地在 [0,1] 立方体中生成大量随机 3d 点,然后通过 testing which points are inside the pyramid convex polyhedron 过滤它们(使用 Delaunay 三角剖分)。
% random points
N = 3000;
XYZ = rand(N,3);
% unit pyramid in [0,1]
V = [0 0 0 ;
1 0 0 ;
1 1 0 ;
0 1 0 ;
0.5 0.5 0 ;
0.5 0.5 sqrt(2)/2];
% delaunay triangulation
DT = delaunayn(V);
% determine points within
in = ~isnan(tsearchn(V, DT, XYZ));
% plot
scatter3(XYZ(in,1), XYZ(in,2), XYZ(in,3), 8, 'filled')
view(3), axis vis3d equal, grid on, box on
axis([0 1 0 1 0 1])
xlabel X, ylabel Y, zlabel Z
% overlay pyramid
hold on
h = tetramesh(DT, V);
set(h, 'FaceAlpha',0.1, 'EdgeColor','m', 'FaceColor','m')
hold off