0001
0002 clear
0003
0004 FV = sphere_tri('ico',2);
0005
0006 facecolor = [.7 .7 .7];
0007 figure
0008 Hp = patch('faces',FV.faces,'vertices',FV.vertices,...
0009 'facecolor',facecolor,'facealpha',1,'edgecolor',[.8 .8 .8]);
0010 camlight('headlight','infinite'); daspect([1 1 1]); axis vis3d; axis off
0011 material dull; rotate3d
0012 hold on
0013
0014 f = 25;
0015 vertex_index1 = FV.faces(f,1);
0016 vertex_index2 = FV.faces(f,2);
0017 vertex_index3 = FV.faces(f,3);
0018 vertex1 = FV.vertices(vertex_index1,:);
0019 vertex2 = FV.vertices(vertex_index2,:);
0020 vertex3 = FV.vertices(vertex_index3,:);
0021
0022 plot3(vertex1(1),vertex1(2),vertex1(3),'ro')
0023 plot3(vertex2(1),vertex2(2),vertex2(3),'go')
0024 plot3(vertex3(1),vertex3(2),vertex3(3),'bo')
0025
0026 vertNormals = get(Hp,'vertexnormals');
0027 quiver3(vertex1(1),vertex1(2),vertex1(3),...
0028 vertNormals(vertex_index1,1),vertNormals(vertex_index1,2),vertNormals(vertex_index1,3),0);
0029
0030 [faceNormals,faceNormalsUnit,centroids] = mesh_face_normals(FV);
0031 quiver3(centroids(f,1),centroids(f,2),centroids(f,3),...
0032 faceNormals(f,1),faceNormals(f,2),faceNormals(f,3),0);
0033
0034 [MYvertNormals,MYvertNormalsUnit] = mesh_vertex_normals(FV);
0035 MYvertNormalsMag = vector_magnitude(MYvertNormals);
0036 quiver3(vertex1(1),vertex1(2),vertex1(3),...
0037 MYvertNormals(vertex_index1,1),MYvertNormals(vertex_index1,2),MYvertNormals(vertex_index1,3),0);
0038
0039 view(3)
0040 rotate3d
0041
0042
0043 vertNormalsMag = vector_magnitude(vertNormals);
0044 vertNormalsUnit = vertNormals ./ repmat(vertNormalsMag,1,3);
0045
0046
0047
0048
0049 for v = 1:size(FV.vertices,1),
0050 dotprod(v,1) = dot( vertNormalsUnit(v,:), MYvertNormalsUnit(v,:) );
0051 end
0052
0053 for v = 1:size(FV.vertices,1),
0054 crossprod(v,:) = cross( vertNormalsUnit(v,:), MYvertNormalsUnit(v,:) );
0055 end