How can I connect points with line segments?

3 ビュー (過去 30 日間)
Robert Enright
Robert Enright 2017 年 8 月 14 日
コメント済み: Robert Enright 2017 年 8 月 16 日
I have a list of x and y values. I want to connect all points within a set distance of one another.
In other words, I would like to draw polygons from the vertices. I want to set a threshold above which the points will not be connected.
Next, when I have drawn the polygons, I would like to measure the angles formed between line segments.
Is this possible? Thank you so much.
  5 件のコメント
Image Analyst
Image Analyst 2017 年 8 月 15 日
Are you talking about edge linking? Or something different?
Robert Enright
Robert Enright 2017 年 8 月 15 日
No, I'm not talking about edge linking. I'm not doing image analysis.

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

採用された回答

Guillaume
Guillaume 2017 年 8 月 15 日
As John said, what's the problem? Get the pairwise distance between all points, find the index of the pairs below your threshold, then plot:
x = randi([0 100], 100, 1); %random demo data
y = randi([0 100], 100, 1);
plot(x, y, '.'); %plot all points
distancethreshold = 5;
pairwisedist = hypot(x - x', y - y'); %or use pdist
[p1, p2] = find(tril(pairwisedist <= distancethreshold & pairwisedist > 0))
hold on;
indexpairs = [p1, p2]';
plot(x(indexpairs), y(indexpairs), '-r')
  6 件のコメント
Image Analyst
Image Analyst 2017 年 8 月 15 日
If you use just x and y, then yes, you will get the angles from the axes. However I meant that you'd use delta x and delta y. See Guillaume's code. With that, you get the angle between points, not the angle from the x axis.
Robert Enright
Robert Enright 2017 年 8 月 16 日
Thank you so much.

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

その他の回答 (1 件)

John D'Errico
John D'Errico 2017 年 8 月 14 日
編集済み: John D'Errico 2017 年 8 月 14 日
An alpha shape or delaunay triangulation are both wrong, because you are asking to draw lines between ALL pairs of points that are less than the threshhold apart.
So just ue a tool like pdist (stats toolbox). Take all pairs of points with an inter-point distance less than your threshold, and draw the lines. WTP?
  2 件のコメント
Robert Enright
Robert Enright 2017 年 8 月 15 日
How would I draw the lines after measuring all of the distances with pdist?
Image Analyst
Image Analyst 2017 年 8 月 15 日
With the line() function.

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

カテゴリ

Help Center および File ExchangeComputational Geometry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by