我想在 matlab 中为给定的简单多边形(无凸面,无孔)创建一个缓冲区,而不使用 bufferm 函数。
vx = [ 2 4 6 4 2]; % polygon vertices
vy = [ 2 4 3 2 2];
figure;
% axis equal;
plot([vx vx(1)],[vy vy(1)],'r');
hold on;
vx = vx(end:-1:1); % Vertices in cw direction
vy = vy(end:-1:1);
xctr = mean(vx(1:end-1)); % find centroid of polygon
yctr = mean(vy(1:end-1));
sf = 2; % scale factor to extend polygon
rx = vx - xctr; % find radius
ry = vy - yctr;
angle = atand(ry/rx); % find angle
new_vx = xctr + rx * cosd(angle) * sf; % find new vertex at a distance of sf
new_vy = yctr + ry * sind(angle) * sf;
plot([new_vx new_vx(1)],[new_vy new_vy(1)], 'g');
但它绘制错误。任何想法请..