How can I create an offset of a boundary?

5 ビュー (過去 30 日間)
Sim
Sim 2024 年 8 月 16 日
編集済み: Sim 2024 年 8 月 17 日
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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by