Home > vbmeg > functions > tool_box > dynamics_movie > test_fig > basic_tool > make_cylinder_old.m

make_cylinder_old

PURPOSE ^

Make cylinder around set of points which represent sequential line

SYNOPSIS ^

function [V,F] = make_cylinder(X,dN,dr)

DESCRIPTION ^

 Make cylinder around set of points which represent sequential line
  [V,F] = make_cylinder(X,dN,dr)
 X  : set of points 3D coordinates [N x 3]
 dN : number of points consist cylinder
      = 6 means hexagonal cylinder will be made
 dr : radius of cylinder (same unit with X)

 2014-11-10 Masa-aki Sato

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    [V,F] = make_cylinder(X,dN,dr)
0002 % Make cylinder around set of points which represent sequential line
0003 %  [V,F] = make_cylinder(X,dN,dr)
0004 % X  : set of points 3D coordinates [N x 3]
0005 % dN : number of points consist cylinder
0006 %      = 6 means hexagonal cylinder will be made
0007 % dr : radius of cylinder (same unit with X)
0008 %
0009 % 2014-11-10 Masa-aki Sato
0010 %
0011 % Copyright (C) 2011, ATR All Rights Reserved.
0012 % License : New BSD License(see VBMEG_LICENSE.txt)
0013 
0014 % 各線分に沿って dN 角柱を作り、patchを生成する
0015 
0016 [N, d] = size(X);
0017 if d ~= 3, error('data dimension error'); end
0018 
0019 % dx : line segment direction [N x 3]
0020 dx = diff(X);
0021 dx = [dx; dx(end,:)];
0022 
0023 [dY,dZ] = make_orthogonal_vec_old(dx);
0024 
0025 % incremental angle of cylindrical points
0026 ang = 2*pi/dN;
0027 da  = ang*(0:dN-1);
0028 % [Y,Z] coordinate of cylindrical points
0029 y = cos(da);
0030 z = sin(da);
0031 
0032 % make dN points for each N points
0033 V   = zeros(dN*N,3);
0034 xyz = zeros(N,3,dN);
0035 
0036 % make cylindrical points around X with radius dr
0037 for m=1:dN
0038     xyz(:,:,m) = X + dr*(dY*y(m) + dZ*z(m));
0039 end
0040 
0041 % find nearest point from xyz(n,:,1) to xyz(n+1,:,:)
0042 % which is cylindrical points in next X(n+1,:)
0043 % and reorder the next cylindrical points xyz(n+1,:,:)
0044 for n=1:N-1
0045     xn = xyz(n,:,1);  % current 1st point
0046     xp = xyz(n+1,:,:);% next cylindrical points
0047     xp = reshape(xp,[3,dN]);
0048     
0049     % distance from xyz(n,:,1) to xyz(n+1,:,:)
0050     dp = vb_repadd(xp, -xn(:));
0051     dd = sum(dp.^2,1);
0052     % nearest point index
0053     [tmp, imin] = min(dd);
0054     
0055     % reorder xyz(n+1,:,:)
0056     ind = imin + (0:dN-1);
0057     ind = mod(ind-1,dN) + 1;
0058     xyz(n+1,:,:) = xyz(n+1,:,ind);
0059 end
0060 
0061 % cylindrical points of X(n,:)
0062 % : xyz(n,:,m)
0063 % = V( dN*(n-1) + m, :)
0064 nj = 0:dN:(dN*(N-1));
0065 
0066 for m=1:dN
0067     V(nj + m,:) = xyz(:,:,m);
0068 end
0069 
0070 %--- Example of vertex & patch
0071 %  1  2  3  1
0072 %  |/ |/ |/ |
0073 %  4  5  6  4
0074 %---  n=1, dN=3
0075 %  F = [n n+1 n+dN;
0076 %         n+1 n+dN n+1+dN]
0077 % There are 2*dN patches for pair of consecutive cylindrical points
0078 F  = zeros(2*dN*(N-1),3);
0079 
0080 % make patch index
0081 for i=1:N-1
0082     np = dN*(i-1);  % start point index
0083     nf = 2*dN*(i-1);% start patch index
0084     
0085     for n=1:dN
0086         if n==dN, 
0087             m = 1;
0088         else
0089             m = n+1;
0090         end
0091         
0092         %  F = [n n+1 n+dN;
0093         %         n+1 n+dN n+1+dN]
0094         F(nf+n,:)    = [n   m    n+dN] + np;
0095         F(nf+dN+n,:) = [m   m+dN n+dN] + np;
0096     end
0097 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005