POLYGON3DNORMALANGLE Normal angle at a vertex of the 3D polygon. THETA = polygon3DNormalAngle(POLYGON, IND) where POLYGON is a set of points, and IND is index of a point in polygon. The function compute the angle of the normal cone localized at this vertex. If IND is a vector of indices, normal angle is computed for each vertex specified by IND. Example % create an equilateral triangle in space poly3d = [1 1 0;-1 0 1;0 -1 -1]; % compute each normal angle theta = polygon3dNormalAngle(poly3d, 1:size(poly3d, 1)); % sum of normal angles must be equal to 2*PI for simple polygons sum(theta) IMPORTANT NOTE: works only for convex angles ! ! ! ! See also polygons3d, faceNormalAngle ------ Author: David Legland e-mail: david.legland@grignon.inra.fr Created: 2005-11-30 Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas).
0001 function theta = polygon3dNormalAngle(points, ind) 0002 %POLYGON3DNORMALANGLE Normal angle at a vertex of the 3D polygon. 0003 % 0004 % THETA = polygon3DNormalAngle(POLYGON, IND) 0005 % where POLYGON is a set of points, and IND is index of a point in 0006 % polygon. The function compute the angle of the normal cone localized at 0007 % this vertex. 0008 % If IND is a vector of indices, normal angle is computed for each vertex 0009 % specified by IND. 0010 % 0011 % Example 0012 % % create an equilateral triangle in space 0013 % poly3d = [1 1 0;-1 0 1;0 -1 -1]; 0014 % % compute each normal angle 0015 % theta = polygon3dNormalAngle(poly3d, 1:size(poly3d, 1)); 0016 % % sum of normal angles must be equal to 2*PI for simple polygons 0017 % sum(theta) 0018 % 0019 % IMPORTANT NOTE: works only for convex angles ! ! ! ! 0020 % 0021 % See also 0022 % polygons3d, faceNormalAngle 0023 % 0024 % ------ 0025 % Author: David Legland 0026 % e-mail: david.legland@grignon.inra.fr 0027 % Created: 2005-11-30 0028 % Copyright 2005 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas). 0029 0030 0031 % number of points 0032 np = size(points, 1); 0033 0034 % number of angles to compute 0035 nv = length(ind); 0036 0037 theta = zeros(nv, 1); 0038 0039 for i=1:nv 0040 p0 = points(ind(i), :); 0041 0042 if ind(i)==1 0043 p1 = points(np, :); 0044 else 0045 p1 = points(ind(i)-1, :); 0046 end 0047 0048 if ind(i)==np 0049 p2 = points(1, :); 0050 else 0051 p2 = points(ind(i)+1, :); 0052 end 0053 0054 theta(i) = pi - anglePoints3d(p1, p0, p2); 0055 end