필터 지우기
필터 지우기

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by