当前位置:网站首页>Matlab: find the inner angle of n-sided concave polygon

Matlab: find the inner angle of n-sided concave polygon

2022-06-13 02:30:00 weixin_ forty-five million six hundred and thirty-three thousan

Find the inner angle of a concave polygon

Most of our common polygons are convex , That is, each inner corner θ Less than 180° The polygon of . And some inner corners of a concave polygon θ Greater than 180°. stay Matlab When finding the inner angle of a polygon , The known condition is usually the coordinates of all vertices of a polygon . If it is a general convex polygon , We can use the coordinates of three adjacent points , Think of it as the three vertices of a triangle , Find the included angle on both sides , That is, the interior angle of the polygon vertex . The formula is as follows :
 Please add a picture description
Or think of these three points as two vectors , Calculate the angle between vectors by dot product and norm . The formula is as follows :
 Please add a picture description
When using manual calculation , For the interior angle of a concave polygon , Just find the corresponding inner corner , Use 360°-θ that will do . However ,Matlab When calculating with the above formula , It is not possible to identify which inner corner is concave or convex , The results are all convex interior angles , Less than 180°. therefore , It is necessary to judge the concave convex property of the internal angle through other function functions , To correctly calculate the inner angle of a concave polygon .
Matlab There are already big men in the community Are Mjaavatten Write a function to judge the concave convex property of the inner corner :convex, Can be in matlab Log in to the official website and download it directly to call .
stay Matlab Community File Exchange Many excellent function functions contributed by big guys can be found in , It is recommended to find some convenient extension functions .

% ps Containing the coordinates of a polygon nx2 matrix 
c = convex(ps); % convex The function determines whether the interior angle of the corresponding vertex is greater than 180°
for k = 1 : size(ps, 1)-2
    point1 = ps(k, :);
    vertex = ps(k+1, :);
    point2 = ps(k+2, :);
    v1 = point1 - vertex;
    v2 = point2 - vertex;   
    %  Use dot product and norm to find angle , Need to use c Value to determine whether the internal angle is greater than 180°
    theta(k) = dot(v1, v2)/(norm(v1)*norm(v2));  % dot Point product function ,norm Norm modular function 
    if c(k)>0  
        angle(k) = (acos(theta(k)))*180/pi;
    else
        angle(k) = 360 - (acos(theta(k)))*180/pi;
    end
end

Complete code

Matlab: Get the shape edge contour , Set the outline figure n Equal division , And find out n Inside corner of a concave polygon

原网站

版权声明
本文为[weixin_ forty-five million six hundred and thirty-three thousan]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280542334406.html