How to connect multiple points in order using the shortest line
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Matt J
am 29 Apr. 2021
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 Kommentare
Weitere Antworten (1)
Matt J
am 29 Apr. 2021
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 Kommentare
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!