필터 지우기
필터 지우기

Draw polygon around grid points

조회 수: 38 (최근 30일)
Michiel Smit
Michiel Smit 2022년 4월 6일
댓글: Michiel Smit 2022년 4월 8일
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