Cannot Find Polyline / Shape Trimming Solution?
1 次查看(过去 30 天)
显示 更早的评论
I have the following polyshape, and I'm trying to get a code so that it'll be able to trim those little pieces outside the octagon, although I haven't been able to figure out if it's possible. The polyxpoly command also doesn't seem to be helpful.
It has the following data;
-0.469085968297298 0.313756744184688
-0.440094970502786 0.351396008350866
-0.407106781194909 0.470470623183810
-0.407106781194391 0.375735931293596
NaN NaN
-0.407106781192721 -0.449293596600183
-0.406889216222806 -0.478917063365948
-0.483600245002183 -0.299242467487661
-0.407106781189291 -0.375735931298804
NaN NaN
0.161453149357603 -0.944295861843129
0.175707373187741 -0.957130176681006
0.0289386891641220 -0.907106781194454
0.124264068706609 -0.907106781190604
NaN NaN
0.906666293448427 -0.907106781189538
0.954275060485152 -0.905749749128643
0.810953109152469 -0.971889603332103
0.875735931290109 -0.907106781190404
NaN NaN
1.46920860553500 -0.313634106950630
1.40640611899230 -0.462122697864436
1.40710678119355 -0.405794445824087
1.40710678119181 -0.375735931294404
NaN NaN
1.40710678119011 0.445567003765894
1.43208827956019 0.353126672561366
1.43836851515149 0.344474197336555
1.40710678118691 0.375735931300496
NaN NaN
0.817490374084150 0.965352338403833
0.930267025462621 0.905928057746692
0.913628423657978 0.907106781192067
0.875735931294209 0.907106781191396
NaN NaN
0.0554418305535038 0.907106781191186
0.0697100604909855 0.908422409793296
0.183050860302648 0.965893572774695
0.124264068708509 0.907106781191196
NaN NaN
1.40710678118691 0.375735931300496
1.40710678119181 -0.375735931294404
0.875735931290109 -0.907106781190404
0.124264068706609 -0.907106781190604
-0.407106781189291 -0.375735931298804
-0.407106781194391 0.375735931293596
0.124264068708509 0.907106781191196
0.875735931294209 0.907106781191396
0 个评论
回答(1 个)
Jaynik
2024-3-1
编辑:Jaynik
2024-3-1
Hi Owen,
To get a perfect octagon and trim off the unwanted edges, you might need to manually select the vertices that outline the desired octagon shape and then create a new "polyshape" with just those vertices.
To clean it programmatically, one approach that can be considered is to use convex hull. But this works only when the extra pieces are non-convex while the required octagon is supposed to be convex. Following is the sample code:
[k, v] = convhull(octagonData); % octagonData is the data provided above
convexPolyshape = polyshape(octagonData(k, :));
plot(convexPolyshape)
While this won't produce a perfect octagon, it will trim the unwanted edges and create a smoother outline. Note that you will need to delete the 'nan' values in order to execute the convhull function. You can refer the following documentation to read more about "convhull":
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Elementary Polygons 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!