フィルターのクリア

Storing neighboring coordinates within a sphere from a 3D domain.

2 ビュー (過去 30 日間)
Samuel Thompson
Samuel Thompson 2017 年 10 月 5 日
コメント済み: Cedric 2017 年 10 月 5 日
Hi,
I wish to be able to form connections between nodes that are within a specified distance apart in 3D space.
~
So far I have created a script that generates coordinates for random nodes within a 3D domain. The coordinates are stored in an N x 3 array, where (:,1) refers to the x axis, (:,2) refers to the y axis, (:,3) refers to the z axis and N refers to the number of nodes.
I wish to take node 40 for example (see below), and identify all of the other nodes that are within a sphere (of radius r) that surrounds it. It can be seen that, to name a few, nodes 5, 7, 10, 15 and 51 lie within this region.
My ideal output would be an array with 2 columns that stores the node number of each of these nodes. For the given example, the desired output would be X = [40, 5; 40, 7; 40, 10; 40, 15; 40, 51 ...]
Any help would be appreciated, please find the code attached.
Sam
I have generated the sphere using the method suggested by 'Image Analyst'.

採用された回答

Cedric
Cedric 2017 年 10 月 5 日
編集済み: Cedric 2017 年 10 月 5 日
Use PDIST2 and get points within a distance smaller (or equal) to the center (node) than the radius.
EDIT : here is a quick example, where we have 4 nodes and we are interested in building a cell array of nodes (IDs) that are within in radius 2 of two centers:
>> dNodes2Centers = pdist2( [1,0,0; 0,2,0; 0,0,3; 1,1,0], [0,0,0; 0,1,0] )
dNodes2Centers =
1.0000 1.4142
2.0000 1.0000
3.0000 3.1623
1.4142 1.0000
>> [r, c] = find( dNodes2Centers < 2 ) ; % R = 2, exclude boundary (<).
>> nodeIdsPerCenter = accumarray( c, r, [], @(x){x} ) ; % Group per center.
which builds:
>> celldisp( nodeIdsPerCenter )
nodeIdsPerCenter{1} =
1
4
nodeIdsPerCenter{2} =
1
2
4
  2 件のコメント
Samuel Thompson
Samuel Thompson 2017 年 10 月 5 日
Hi Cedric,
Thanks for your help, this method will definitely work and is much more straight forward than what I was trying to do!
Thanks for your time,
Sam
Cedric
Cedric 2017 年 10 月 5 日
My pleasure!

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by