Storing neighboring coordinates within a sphere from a 3D domain.
조회 수: 2 (최근 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'.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/167913/image.png)
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Scatter Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!