Draw polygon around grid points

36 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2022-4-6
In what form is the input data given?
Michiel Smit
Michiel Smit 2022-4-6
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!

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2022-4-7
编辑:Matt J 2022-4-7
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 个评论
Michiel Smit
Michiel Smit 2022-4-8
Thank you so much. This really does the trick. Never heard of AlphaShape() and boundaryFacets() before, it it works really well.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Elementary Polygons 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by