Sort coordinates based on closest connectivity?

12 ビュー (過去 30 日間)
Eric Chadwick
Eric Chadwick 2018 年 2 月 20 日
コメント済み: Walter Roberson 2018 年 8 月 29 日
Hello,
I have an nx3 array representing x,y,z coordinates in space. These coordinates are all connected and represent a tortuous line. I would like to calculate the length of this line, however the coordinates I have are not in order of connectivity. Is it possible to reorder them such that I can simply calculate the length by doing a for loop like:
length = 0;
for i = 1:length(array)-1
length = norm([coords(i,1)-coords(i+1,1),coords(i,2)-coords(i+1,2),coords(i,3)-coords(i+1,3)]);
end
I have tried just finding the neighbours of each coordinate and reordering that way, but this gets very convoluted quickly and requires that I "walk" through the line. For the total dataset I am trying to analyze I will literally have millions of these lines, so I am trying to avoid slow solutions like that.
Edit: The lines I'm working with are in an image, and the points on the line must have a max distance from each consecutive point of (1,1,1). That is, 1 pixel in x,y, and z.

採用された回答

Image Analyst
Image Analyst 2018 年 2 月 20 日
  7 件のコメント
Image Analyst
Image Analyst 2018 年 8 月 28 日
I don't see any rationale for how you're connecting the points in the figure
in that order, [1-2-3-4-1-3-6-7]. How is that order decided? If it's just arbitrary, then you can still do
outputArray = inputArray(Order);
with whatever order you want.
Walter Roberson
Walter Roberson 2018 年 8 月 29 日
Asyran Abdullah comments to Image Analyst
Thanks it's good

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by