Angles at concave polygon

6 ビュー (過去 30 日間)
Mariana
Mariana 2014 年 4 月 11 日
回答済み: 信实 郑 2022 年 2 月 26 日
Hello, I have a concave polygon you can see in the picture attached. I need to compute all angles between two consecutive vectors. I tried following:
for k = 1 : size(ps, 1) - 2;
point1 = ps(k, :);
vertex = ps(k+1, :);
point2 = ps(k+2, :);
v1 = point1 - vertex;
v2 = point2 - vertex;
theta(k) = dot(v1, v2)/(norm(v1)*norm(v2));
angle(k) = (acos(theta))*180/pi;
end
ps is nx2 matrix containing coordinates of polygon vertices.
In the output angle(k) there are angles allways smaller then 180, but obviously there angles more then 180. I need to somehow distinct which angles are >180 and <180. What do I do wrong? Thank you in advance for your reply

採用された回答

Image Analyst
Image Analyst 2014 年 4 月 11 日
Try atan2d().

その他の回答 (1 件)

信实 郑
信实 郑 2022 年 2 月 26 日
Use function convex to identify convex and concave parts of polygon.As following:
% ps is nx2 matrix containing coordinates of polygon vertices.
c = convex(ps); % Identify convex and concave parts of polygon
for k = 1 : size(ps, 1)-2
point1 = ps(k, :);
vertex = ps(k+1, :);
point2 = ps(k+2, :);
v1 = point1 - vertex;
v2 = point2 - vertex;
theta(k) = dot(v1, v2)/(norm(v1)*norm(v2));
if c(k)>0
angle(k) = (acos(theta(k)))*180/pi;
else
angle(k) = 360 - (acos(theta(k)))*180/pi;
end
end

カテゴリ

Help Center および File ExchangePropagation and Channel Models についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by