Is there a function to turn ?x2 matrix of coordinates of vertices of a polygon into a ?x4 matrix of coordinates of line segments of that polygon?
1 view (last 30 days)
Show older comments
Bartlomiej Krol
on 4 Dec 2019
Commented: Bartlomiej Krol
on 4 Dec 2019
Is there a function to turn a matrix of vertices of a polygon like this [2, 4; 5, 6; 6, 6; 8,5] into a matrix of line segments of that polygon like this [2, 4, 5, 6; 5, 6, 6, 6; 6, 6, 8, 5; 8, 5, 2, 4]?
0 Comments
Accepted Answer
Stephan
on 4 Dec 2019
Yes,
circshift will do the job:
A = [2, 4; 5, 6; 6, 6; 8,5]
B = [2, 4, 5, 6; 5, 6, 6, 6; 6, 6, 8, 5; 8, 5, 2, 4]
% The solution:
C = [A circshift(A,-1)]
% The test:
A =
2 4
5 6
6 6
8 5
B =
2 4 5 6
5 6 6 6
6 6 8 5
8 5 2 4
C =
2 4 5 6
5 6 6 6
6 6 8 5
8 5 2 4
More Answers (0)
See Also
Categories
Find more on Elementary Polygons in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!