-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathGetAngles.m
More file actions
42 lines (38 loc) · 1.23 KB
/
GetAngles.m
File metadata and controls
42 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%% Calculates the inner angles of all the triangles which make up a
% tesselated surface.
%
% ARGUMENTS:
% vertices -- <description>
% triangles -- <description>
%
% OUTPUT:
% angles -- <description>
%
% USAGE:
%{
<example-commands-to-make-this-function-run>
%}
%
% MODIFICATION HISTORY:
% SAK(12-03-2010) -- Original.
% SAK(08-10-2010) -- Corrected bug in cycle through angles, had been
% calculating angles at vertices 1, 2 and 1 again...
% SAK(Nov 2013) -- Move to git, future modification history is
% there...
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function angles=GetAngles(vertices,triangles)
%%
NumberofTriangles = length(triangles);
%%
angles = zeros(NumberofTriangles,3);
for tt = 1:NumberofTriangles,
ThisTriangle = triangles(tt,:);
for ta = 1:3,
ThisAngle = circshift(ThisTriangle, [0 -(ta-1)]);
v21 = vertices(ThisAngle(2),:) - vertices(ThisAngle(1),:);
v31 = vertices(ThisAngle(3),:) - vertices(ThisAngle(1),:);
angles(tt,ta) = acos(dot(v21 ./ sqrt(sum(v21.^2)), ...
v31 ./ sqrt(sum(v31.^2))))
end
end
end %function GetAngles()