Draw polygon around grid points

30 visualizaciones (últimos 30 días)
Michiel Smit
Michiel Smit el 6 de Abr. de 2022
Comentada: Michiel Smit el 8 de Abr. de 2022
Dear reader,
I want to draw polygon around a set of grid points. For clarity I have added a figure below
I need to draw a polygon around the edges of the smaller red dots in such a way that the larger orange dots are within the polygon. Preferably, all angles of the polygon are 90 degrees. So basically the polygon with the minimum surface area to include all orange points, if that makes sense
My question is whether this is possible, and if so, how to do this?
Many thanks in advance!
  2 comentarios
Matt J
Matt J el 6 de Abr. de 2022
In what form is the input data given?
Michiel Smit
Michiel Smit el 6 de Abr. de 2022
Dear Matt,
Data is given in matrix form, where 1st column are the X-coordinates and 2nd column are the Y-coordinates. I have added the specific data below.
The smaller red dots are given by:
small_dots = [2.1250 52.6250
2.1250 52.8750
2.1250 53.1250
2.3750 52.3750
2.3750 52.6250
2.3750 52.8750
2.3750 53.1250
2.6250 52.3750
2.6250 52.6250
2.6250 52.8750
2.6250 53.1250
2.6250 53.3750
2.8750 52.3750
2.8750 52.6250
2.8750 52.8750
2.8750 53.1250
2.8750 53.3750
3.1250 52.3750
3.1250 52.6250
3.1250 52.8750
3.1250 53.1250
3.3750 52.3750
3.3750 52.6250
3.3750 52.8750
3.3750 53.1250
3.6250 52.3750
3.6250 52.6250
3.6250 52.8750
3.8750 52.3750
3.8750 52.6250
3.8750 52.8750
4.1250 52.3750
4.1250 52.6250
4.1250 52.8750];
The larger orange dots are given by:
large_dots = [2.2500 53.0000
2.2500 52.7500
2.5000 53.0000
2.5000 52.7500
2.5000 52.5000
2.7500 53.2500
2.7500 53.0000
2.7500 52.7500
3.0000 53.0000
3.0000 52.7500
3.0000 52.5000
3.2500 53.0000
3.2500 52.7500
3.2500 52.5000
3.5000 52.7500
3.5000 52.5000
3.7500 52.7500
3.7500 52.5000
4.0000 52.7500
4.0000 52.5000];
I hope this is clear enough.
Many thanks in advance!

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 7 de Abr. de 2022
Editada: Matt J el 7 de Abr. de 2022
small_dots = [2.1250 52.6250
2.1250 52.8750
2.1250 53.1250
2.3750 52.3750
2.3750 52.6250
2.3750 52.8750
2.3750 53.1250
2.6250 52.3750
2.6250 52.6250
2.6250 52.8750
2.6250 53.1250
2.6250 53.3750
2.8750 52.3750
2.8750 52.6250
2.8750 52.8750
2.8750 53.1250
2.8750 53.3750
3.1250 52.3750
3.1250 52.6250
3.1250 52.8750
3.1250 53.1250
3.3750 52.3750
3.3750 52.6250
3.3750 52.8750
3.3750 53.1250
3.6250 52.3750
3.6250 52.6250
3.6250 52.8750
3.8750 52.3750
3.8750 52.6250
3.8750 52.8750
4.1250 52.3750
4.1250 52.6250
4.1250 52.8750];
large_dots = [2.2500 53.0000
2.2500 52.7500
2.5000 53.0000
2.5000 52.7500
2.5000 52.5000
2.7500 53.2500
2.7500 53.0000
2.7500 52.7500
3.0000 53.0000
3.0000 52.7500
3.0000 52.5000
3.2500 53.0000
3.2500 52.7500
3.2500 52.5000
3.5000 52.7500
3.5000 52.5000
3.7500 52.7500
3.7500 52.5000
4.0000 52.7500
4.0000 52.5000];
alldots= [small_dots;large_dots];
shp=alphaShape(alldots,0.13);
[~,V]=boundaryFacets(shp);
shp=polyshape(V,'Simplify',false);
plot(alldots(:,1),alldots(:,2),'o');
hold on; shp.plot; hold off; axis equal
  1 comentario
Michiel Smit
Michiel Smit el 8 de Abr. de 2022
Thank you so much. This really does the trick. Never heard of AlphaShape() and boundaryFacets() before, it it works really well.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by