Find all neighbors near the specified Point(x,y,z,) in 3D matrix

11 views (last 30 days)
I want to find all neighbors who are near the specified point(x,y,z) or find all objects who are in k distance from specified point(x,y,z).
For example I want to find all objects near the point(1,1,1) or they are in k distance from point(1,1,1).
I try to use from rangesearch function, but I can't use it.
  13 Comments
Walter Roberson
Walter Roberson on 6 Oct 2017
Unless the point cloud has special properties, the 27 nearest neighbours will include points that are not at "adjacent" coordinates. Do you have reason to expect that the points will form a cubic grid that is aligned with the axes? If so then the problem reduces to one of examining the min() and max() of the coordinates to figure out where the ranges begin and end, and determine the coordinate spacing, after which everything else is pre-determined by the properties of a cuboid with appropriate size.
Image Analyst
Image Analyst on 7 Oct 2017
You could also use meshgrid() to create a list of coordinates:
middleRow = 100; % Whatever - wherever it is for this cube.
middleCol = 1000; % Whatever - wherever it is for this cube.
middlePlane = 10; % Whatever - wherever it is for this cube.
[rows, columns, planes] = meshgrid(1:3, 1:3, 1:3)
% Make 1-D arrays
rows = rows(:) + middleRow
columns = columns(:) + middleCol
planes = planes(:) + middlePlane
% Get rid of center voxel so we have only neighbors
rows(14) = []; % Delete middle one
columns(14) = []; % Delete middle one
planes(14) = []; % Delete middle one

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 12 Sep 2014
Then just mask the array
withinSphere = array3D .* sphereVoxels; % Voxel values.
After that I don't know what you want because all you say is you want to "detect all objects" but "detect" is such a vague, imprecise term that I don't know what sort of numerical data to return to you. Please define "detect".

More Answers (0)

Community Treasure Hunt

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

Start Hunting!