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

1 次查看(过去 30 天)
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by