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
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@inrae.fr 0027 % Created: 2005-11-30 0028 % Copyright 2005-2024 INRA - CEPIA Nantes - MIAJ (Jouy-en-Josas) 0029 0030 % number of points 0031 np = size(points, 1); 0032 0033 % number of angles to compute 0034 nv = length(ind); 0035 0036 theta = zeros(nv, 1); 0037 0038 for i=1:nv 0039 p0 = points(ind(i), :); 0040 0041 if ind(i)==1 0042 p1 = points(np, :); 0043 else 0044 p1 = points(ind(i)-1, :); 0045 end 0046 0047 if ind(i)==np 0048 p2 = points(1, :); 0049 else 0050 p2 = points(ind(i)+1, :); 0051 end 0052 0053 theta(i) = pi - anglePoints3d(p1, p0, p2); 0054 end