How can I create an offset of a boundary?

5 visualizaciones (últimos 30 días)
Sim
Sim el 16 de Ag. de 2024
Editada: Sim el 17 de Ag. de 2024
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:

Respuesta aceptada

Sim
Sim el 16 de Ag. de 2024
Editada: Sim el 17 de Ag. de 2024
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])

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by