How can I find the set of vertices of hexagons which are adjacent to a random point?
Ältere Kommentare anzeigen
I have a set of hexagons whose blue coordinates are known:

I have a random red point and I need to know the 4 (in some cases it would be 3) points which are immediately adjacent to it. These points are contained in the black box shown for illustration.
I tried to sort the blue points by measuring distances but I keep getting extra points (shown by black arrows) or missing the required points.
1 Kommentar
Matt J
am 13 Aug. 2024
Please give us the points so we can demonstrate solutions.
Akzeptierte Antwort
Weitere Antworten (1)
Mario Malic
am 10 Aug. 2024
Hi,
here's some code to give you an idea
X = rand(3,3);
Y = rand(3,3);
pts = [X(:), Y(:)];
distance = squareform(pdist(pts)); % symmetric matrix that contains distances between points
% distance between pt3 and all other pts
[~, idx] = sort(distance(:, 3));
closestPts = idx(2:5) % first one is distance between pt3 and pt3 so we ignore that
2 Kommentare
Aravind Varma Dantuluri
am 12 Aug. 2024
Mario Malic
am 12 Aug. 2024
That random point is just an example, it can be arbitrary!
Kategorien
Mehr zu Random Number Generation finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

