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 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