How can I create an offset of a boundary?

5 次查看(过去 30 天)
How can I create an offset of a boundary?
rng('default')
x = rand(30,1);
y = rand(30,1);
plot(x,y,'.')
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y);
hold on;
plot(x(k),y(k));
My desired output:

采纳的回答

Sim
Sim 2024-8-16
编辑:Sim 2024-8-17
Maybe I found it.... :-)
External offset
rng('default')
x = rand(30,1);
y = rand(30,1);
k = boundary(x,y);
polyout1 = polybuffer([x(k),y(k)],'lines',0.05);
a = find(isnan(polyout1.Vertices(:,1)));
% for the external offset you need "polyout1.Vertices(1:a,:)"
figure
hold on
plot(x,y,'.')
plot(x(k),y(k),'Color','r','Linewidth',2);
plot(polyout1.Vertices(1:a,1),polyout1.Vertices(1:a,2),'Color','b','Linewidth',2);
xlim([-0.2 1.2])
ylim([-0.2 1.2])
Internal offset
rng('default')
x = rand(30,1);
y = rand(30,1);
k = boundary(x,y);
polyout1 = polybuffer([x(k),y(k)],'lines',0.05);
a = find(isnan(polyout1.Vertices(:,1)));
% for the internal offset you need both plots, i.e. with "polyout1.Vertices(a:end,:)" and
% with "polyout1.Vertices([a+1, end],:)"
figure
hold on
plot(x,y,'.')
plot(x(k),y(k),'Color','r','Linewidth',2);
plot(polyout1.Vertices(a:end,1),polyout1.Vertices(a:end,2),'Color','g','Linewidth',2);
plot(polyout1.Vertices([a+1, end],1),polyout1.Vertices([a+1, end],2),'Color','g','Linewidth',2);
xlim([-0.2 1.2])
ylim([-0.2 1.2])

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by