CodeForge.comFree Open Source Codes Forge and Sharing |
function angles = polyangles(x, y)
%POLYANGLES Computes internal polygon angles.
% ANGLES = POLYANGLES(X, Y) computes the interior angles (in
% degrees) of an arbitrary polygon whose vertices are given in
% [X, Y], ordered in a clockwise manner. The program eliminates
% duplicate adjacent rows in [X Y], except that the first row may
% equal the last, so that the polygon is closed.
% Copyright 2002-2004 R. C. Gonzalez, R. E. Woods, & S. L. Eddins
% Digital Image Processing Using MATLAB, Prentice-Hall, 2004
% $Revision: 1.6 $ $Date: 2003/11/21 14:44:06 $
% Preliminaries.
[x y] = dupgone(x, y); % Eliminate duplicate vertices.
xy = [x(:) y(:)];
if isempty(xy)
% No vertices!
angles = zeros(0, 1);
return;
end
if size(xy, 1) == 1 | ~isequal(xy(1, :), xy(end, :))
% Close the polygon
xy(end + 1, :) = xy(1, :);
end
% Precompute some quantities.
d = diff(xy, 1);
v1 = -d(1:end, :);
v2 = [d(2:end, :); d(1, :)];
v1_dot_v2 = sum(v1 .* v2, 2);
mag_v1 = sqrt(sum(v1.^2, 2));
mag_v2 = sqrt(sum(v2.^2, 2));
% Protect against nearly duplicate vertices; output angle will be 90
% degrees for such cases. The "real" further protects against
% possible small imaginary angle components in those cases.
mag_v1(~mag_v1) = eps;
mag_v2(~mag_v2) = eps;
angles = real(acos(v1_dot_v2 ./ mag_v1 ./ mag_v2) * 180 / pi);
% The first angle computed was for the second vertex, and the
% last was for the first vertex. Scroll one position down to
% make the last vertex be the first.
angles = circshift(angles, [1, 0]);
% Now determine if any vertices are concave and adjust the angles
% accordingly.
sgn = convex_angle_test(xy);
% Any element of sgn that's -1 indicates that the angle is
% concave. The corresponding angles have to be subtracted
% from 360.
I = find(sgn == -1);
angles(I) = 360 - angles(I);
%-------------------------------------------------------------------%
function sgn = convex_angle_test(xy)
% The rows of array xy are ordered vertices of a
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.
| Name | Size | Date |
| 5.00 kB | 16-12-04 13:36 | |
| 1.54 kB | 16-12-04 13:36 | |
| 651.00 B | 16-12-04 13:36 | |
| 2.96 kB | 16-12-04 13:36 | |
| 2.99 kB | 16-12-04 13:36 | |
| 2.42 kB | 16-12-04 13:36 | |
| 2.17 kB | 16-12-04 13:36 | |
| 5.64 kB | 16-12-04 13:36 | |
| 3.87 kB | 16-12-04 13:36 | |
| 592.00 B | 16-12-04 13:36 | |
| 2.30 kB | 16-12-04 13:36 | |
| 2.37 kB | 16-12-04 13:36 | |
| 1.15 kB | 16-12-04 13:36 | |
| 1.02 kB | 16-12-04 13:36 | |
| 5.98 kB | 16-12-04 13:36 | |
| 799.00 B | 16-12-04 13:36 | |
| 977.00 B | 16-12-04 13:36 | |
| 687.00 B | 16-12-04 13:36 | |
| 882.00 B | 16-12-04 13:36 | |
| 736.00 B | 16-12-04 13:36 | |
| 6.47 kB | 16-12-04 13:36 | |
| 874.00 B | 16-12-04 13:36 | |
| 1.00 kB | 16-12-04 13:36 | |
| 8.55 kB | 16-12-04 13:36 | |
| 1.42 kB | 16-12-04 13:36 | |
| 992.00 B | 16-12-04 13:36 | |
| 447.00 B | 16-12-04 13:36 | |
| 2.04 kB | 16-12-04 13:36 | |
| 920.00 B | 16-12-04 13:36 | |
| 2.64 kB | 16-12-04 13:36 | |
| 2.82 kB | 16-12-04 13:36 | |
| 2.65 kB | 16-12-04 13:36 | |
| 1.02 kB | 16-12-04 13:36 | |
| 1.23 kB | 16-12-04 13:36 | |
| 1.94 kB | 16-12-04 13:36 | |
| 2.46 kB | 16-12-04 13:36 | |
| 2.82 kB | 16-12-04 13:36 | |
| 45.71 kB | 16-12-04 13:36 | |
| 26.30 kB | 16-12-04 13:36 | |
| 46.55 kB | 16-12-04 13:36 | |
| 60.11 kB | 13-04-09 20:38 | |
| 1.38 kB | 16-12-04 13:36 | |
| 1.12 kB | 16-12-04 13:36 | |
| 2.90 kB | 16-12-04 13:36 | |
| 3.97 kB | 16-12-04 13:36 | |
| 4.20 kB | 16-12-04 13:36 | |
| 2.12 kB | 16-12-04 13:36 | |
| 791.00 B | 16-12-04 13:36 | |
| 1.30 kB | 16-12-04 13:36 | |
| 1.83 kB | 16-12-04 13:36 | |
| 1.20 kB | 16-12-04 13:36 | |
| 3.25 kB | 16-12-04 13:36 | |
| 3.24 kB | 16-12-04 13:36 | |
| 2.41 kB | 16-12-04 13:36 | |
| 1.90 kB | 16-12-04 13:36 | |
| 1.42 kB | 16-12-04 13:36 | |
| 1.44 kB | 16-12-04 13:36 | |
| 1.97 kB | 16-12-04 13:36 | |
| 1.75 kB | 16-12-04 13:36 | |
| 2.75 kB | 16-12-04 13:36 | |
| 1.28 kB | 16-12-04 13:36 | |
| 7.15 kB | 16-12-04 13:36 | |
| 1.29 kB | 16-12-04 13:36 | |
| 950.00 B | 16-12-04 13:36 | |
| 6.14 kB | 16-12-04 13:36 | |
| 2.88 kB | 16-12-04 13:36 | |
| 1.33 kB | 16-12-04 13:36 | |
| 1.15 kB | 16-12-04 13:36 | |
| 5.30 kB | 16-12-04 13:36 | |
| 1.66 kB | 16-12-04 13:36 | |
| 1.46 kB | 16-12-04 13:36 | |
| 1.98 kB | 16-12-04 13:36 | |
| 4.45 kB | 16-12-04 13:36 | |
| 2.57 kB | 16-12-04 13:36 | |
| 3.78 kB | 16-12-04 13:36 | |
| 4.13 kB | 16-12-04 13:36 | |
| 1.72 kB | 16-12-04 13:36 | |
| 1.55 kB | 16-12-04 13:36 | |
| 1.78 kB | 16-12-04 13:36 | |
| 713.00 B | 16-12-04 13:36 | |
| 1.04 kB | 16-12-04 13:36 | |
| 1.16 kB | 16-12-04 13:36 | |
| 7.00 kB | 16-12-04 13:36 | |
| 967.00 B | 16-12-04 13:36 | |
| 24.00 kB | 16-12-04 13:36 | |
| 18.97 kB | 16-12-04 13:36 | |
| 12.00 kB | 16-12-04 13:36 | |
| 8.68 kB | 16-12-04 13:36 | |
| 2.71 kB | 16-12-04 13:36 | |
| 24.44 kB | 16-12-04 13:36 | |
| 8.54 kB | 16-12-04 13:36 | |
| 1.66 kB | 16-12-04 13:36 | |
| 4.67 kB | 16-12-04 13:36 | |
| 4.52 kB | 16-12-04 13:36 | |
| 940.00 B | 16-12-04 13:36 | |
| 1.06 kB | 16-12-04 13:36 | |
| 4.14 kB | 16-12-04 13:36 | |
| 4.77 kB | 16-12-04 13:36 | |
| 1.04 kB | 16-12-04 13:36 | |
| 3.45 kB | 16-12-04 13:36 | |
| 696.00 B | 16-12-04 13:36 | |
| 3.59 kB | 16-12-04 13:36 | |
| 85.71 kB | 13-04-09 20:39 | |
| 0.00 B | 02-07-09 16:26 | |
| 0.00 B | 02-07-09 16:26 | |
| 0.00 B | 02-07-09 16:26 |