How to connect multiple points in order using the shortest line
조회 수: 5 (최근 30일)
이전 댓글 표시
I have the following discrete points.
The x and y coordinates are the following
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083]
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762]
I want to draw lines that connect these coordinates in a consecutive way using the shortest distance among them. For example the first line is between (-0.5305,3.4667) and (-2.0960, 1.7524). The second is between (-2.0960, 1.7524) and (-1.6192,1.0045) and so on.
I tried the following code, but it gave me weird lines that are not the shortest
for i = 1:length(Xk)-1
for j = i+1:length(Xk)-1
plot([Xk(i) Xk(j)],[Yk(i) Yk(i)])
plot([Xk(j) Xk(j)],[Yk(i) Yk(j)])
pause(0.01)
end
end
댓글 수: 0
채택된 답변
Matt J
2021년 4월 29일
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083];
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762];
line(X,Y)
댓글 수: 0
추가 답변 (1개)
Matt J
2021년 4월 29일
X = [-0.5305 -2.0960 -1.6192 -2.2768 -1.9141 -2.0279 -2.0102 -2.0087 -2.0083 -2.0083 -2.0083];
Y = [3.4667 1.7524 1.0045 1.2514 1.0493 1.1818 1.1733 1.1763 1.1762 1.1762 1.1762];
p=polyshape(X,Y);
plot(p,'FaceColor','none')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!