Draw polygon around grid points

30 views (last 30 days)
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 Comments
Matt J
Matt J on 6 Apr 2022
In what form is the input data given?
Michiel Smit
Michiel Smit on 6 Apr 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!

Sign in to comment.

Accepted Answer

Matt J
Matt J on 7 Apr 2022
Edited: Matt J on 7 Apr 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 Comment
Michiel Smit
Michiel Smit on 8 Apr 2022
Thank you so much. This really does the trick. Never heard of AlphaShape() and boundaryFacets() before, it it works really well.

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!