Putting points into groups of three to find their centers

4 ビュー (過去 30 日間)
Jonathan Soucy
Jonathan Soucy 2022 年 3 月 15 日
編集済み: Image Analyst 2022 年 3 月 15 日
For example, if I have points A, B, C, D, how would I be able to find the centers of circle ABC, ACD, ABD, and BCD?
But I do not know how to find all the combinations of three points from my data set. I thought the nchoosek function might work, but I have my data set includes both x and y values for each point and they are not intergers. Would appricate any suggestions!
  2 件のコメント
Jan
Jan 2022 年 3 月 15 日
Please post some code which defines the inputs. "points A,B,C,D" does not tell us, in which format you save the coordinates: [1 x 2], [2 x 1], fields "x" and "y" of a struct, etc.
Jonathan Soucy
Jonathan Soucy 2022 年 3 月 15 日
Hey Jan, here is a sampling of the inputs I am working with
XYgroups = [3897.8, 835.0;
3896.6, 875.1;
2562.4, 979.4;
2526.8, 975.1
2500.1, 944.2]
These arrays can be >100 in length

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

採用された回答

Jan
Jan 2022 年 3 月 15 日
編集済み: Jan 2022 年 3 月 15 日
Guessing, that the "points" are [1x2] vectors:
A = [1, 12];
B = [2, 10];
C = [3, 17];
D = [4, 9];
P = cat(1, A, B, C, D); % Much better than a set of variables!
% Now you can usen an index:
Groups = nchoosek(1:4, 3);
Pairs = 4×3
1 2 3 1 2 4 1 3 4 2 3 4
for k = 1:size(Gropus, 1)
aGroup = Gropus(k, :);
ThreeP = P(aGroup, :); % Coordinates of 3 points as [3 x 2] matrix
... Do what you want with them
end
Idea: Do not create a set of variables, but store them in a matrix directly. Then it is trivial to access them using an index.
  2 件のコメント
Jonathan Soucy
Jonathan Soucy 2022 年 3 月 15 日
thank you! Worked perfect! Here's my final code
XYvals = [cell_VXYZ(:,2),cell_VXYZ(:,3)];
groupindex = nchoosek(1:length(XYvals),3);
Centers = [];
for k = 1:size(groupindex, 1)
tempgroup = groupindex(k, :);
tempXYvals = XYvals(tempgroup, :);
[~,tempCenters] = fitcircle3(tempXYvals);
Centers = [Centers; tempCenters'];
end
Image Analyst
Image Analyst 2022 年 3 月 15 日
編集済み: Image Analyst 2022 年 3 月 15 日
Why do just a subset of the numbers? Why not do them all? A hundred or more is not very large. Even a million wouldn't be. If you have tens of millions though, it might take a bit of time.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by