Home > functions > common > boundary > vb_out_normal_vect.m

vb_out_normal_vect

PURPOSE ^

normal vector

SYNOPSIS ^

function [xxn ,F] = vb_out_normal_vect(V,F)

DESCRIPTION ^

 normal vector
  [xxn ,F] = vb_out_normal_vect(V,F)
 --- Input
 V : vertex of surface
 F : patch index
 --- Output
 xxn : normal vector
 F : patch index


 Ver 1.0  by M. Sato  2004-2-10

 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    [xxn ,F] = vb_out_normal_vect(V,F)
0002 % normal vector
0003 %  [xxn ,F] = vb_out_normal_vect(V,F)
0004 % --- Input
0005 % V : vertex of surface
0006 % F : patch index
0007 % --- Output
0008 % xxn : normal vector
0009 % F : patch index
0010 %
0011 %
0012 % Ver 1.0  by M. Sato  2004-2-10
0013 %
0014 % Copyright (C) 2011, ATR All Rights Reserved.
0015 % License : New BSD License(see VBMEG_LICENSE.txt)
0016 
0017 %
0018 %------  三角面の法線計算 -------
0019 %
0020 Nnew = size(V,1);
0021 
0022 % 三角面の法線計算
0023 xxf  = vb_triangle_normal(V,F);
0024 % 頂点の法線計算
0025 xxn  = vb_vertex_normal(V,F,xxf);
0026 
0027 % 全点の重心を中心にした時の外向きベクトル
0028 Vsum = sum(V ,1)/Nnew;
0029 Vc     = V-Vsum(ones(Nnew,1),:);
0030 % 全点の重心を中心にした時の各三角面の重心
0031 Vxx  = (Vc(F(:,1),:) + Vc(F(:,2),:) + Vc(F(:,3),:))/3;
0032 
0033 % 外向きベクトルと同じ向きの法線の数
0034 Nsum = sum( sum(xxf.*Vxx ,2) > 0 );
0035 
0036 % 三角面数
0037 Npatch = size(F,1);      
0038 
0039 % 法線の向きが外向きと逆の場合は法線の向きを逆にする
0040 if Nsum < (Npatch/2),
0041     xxn    = - xxn;
0042     F2       = F(:,2);
0043     F(:,2) = F(:,3);
0044     F(:,3) = F2;
0045 end;
0046 
0047 return

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005