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)
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]?

Accepted Answer

Stephan
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)

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!