buffer zone for polygon in matlab -


i create buffer zone given simple polygon (no convex, no holes) in matlab without using bufferm function.

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 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 @ distance of sf new_vy = yctr + ry * sind(angle) * sf; plot([new_vx new_vx(1)],[new_vy new_vy(1)], 'g'); 

but plots wrongly. ideas pls..

change angle to

angle = atan2(ry,rx); 

new_vx to

new_vx = xctr + abs(rx) .* cos(angle) * sf; 

and new_vy either

new_vy = yctr + abs(ry) .* sin(angle) * sf; 

or

new_vy = yctr + ry * sf; 

depending on how want look.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -