如何在圆柱面上生成随机点后在圆柱面上创建网格

时间:2014-01-29 08:14:58

标签: matlab 3d triangulation point-clouds delaunay

现在我可以在圆柱面上生成随机点。 但我无法通过使用生成的点在圆柱面上正确创建网格。 当我使用这个代码时,由delaunay三角剖分创建的三角形网格变得垂直长。 所以我想解决这个问题。

我在这里显示我的代码。 我不想更改除点数之外的参数

     clear all
     close all
     clc

     n =1000;          % Number of points

     % Radius
     c = 3.0*10^8;      % Speed of lgiht
     f = 5.2*10^9;      % Frequency
     lambda = c/f;      % Wavelength
     r = 3*lambda;      % Radius of circular cylinder
     theta = rand(1,n)*(2*pi); 


     % Equation
     x = r.*cos(theta);
     y = r.*sin(theta);
     z = 2*rand(n,1)-1;

     % Plot
     figure(1)
     scatter3(x(:), y(:), z(:),'.')

     % axis equal
     xlabel('x-length','Fontname','Times New Roman','fontsize',25)
     ylabel('y-length','Fontname','Times New Roman','fontsize',25)
     zlabel('z-length','Fontname','Times New Roman','fontsize',25)
     title('Randomly distributed point cloud on surface of cylinder','Fontname','Times New Roman','fontsize',25)

     % Plot range
       xlim([-1 1])     % Plot range of x-axis
       ylim([-1 1])     % Plot range of y-axis
       zlim([-1 1])     % Plot range of z-axis
       set(gca,'Fontname','Times New Roman','fontsize',20)

     % Create mesh
     figure(2)
     dt = delaunayTriangulation(x(:),y(:),z(:));
    [tri, Xb] = freeBoundary(dt);
     tr = TriRep(tri, Xb);
     P = incenters(tr);
     fn = faceNormals(tr);
     trisurf(tri,Xb(:,1),Xb(:,2),Xb(:,3), ...
 'FaceColor', 'g', 'faceAlpha', 0.8);
     axis equal;
     hold on;
     quiver3(P(:,1),P(:,2),P(:,3), ...
  fn(:,1),fn(:,2),fn(:,3),0.5, 'color','r');
     hold off;
     xlabel('x-length','Fontname','Times New Roman','fontsize',25)
     ylabel('y-length','Fontname','Times New Roman','fontsize',25)
     zlabel('z-length','Fontname','Times New Roman','fontsize',25)
     title('Randamly distributed point cloud on surface of cylinder','Fontname','Times New Roman','fontsize',25)
   % Plot range
     xlim([-1 1])     % Plot range of x-axis
     ylim([-1 1])     % Plot range of y-axis
     zlim([-1 1])     % Plot range of z-axis
     set(gca,'Fontname','Times New Roman','fontsize',20)

请告诉我网格垂直变长的原因。

0 个答案:

没有答案
相关问题