필터 지우기
필터 지우기

How to extract points from a 3D plot that fall within a particular distance from the center coordinate?

조회 수: 3 (최근 30일)
Hello, I am a novice in matlab programmming. I am working on a computational project where I have a 3dimensional plot with thousands of points. Now I would like to fix one point having coordinate (x,y,z). At a particular distance r as a cutoff from (x,y,z), I would like to extract all the points in the plot that fall within the distance (or radius) r. I am not sure of how i can use euclidean distance formula for this. Please help me out.
Thanks in advance.

채택된 답변

Wan Ji
Wan Ji 2021년 8월 18일
편집: Wan Ji 2021년 8월 18일
If you have Coor is a n by 3 matrix as the coordinates of n points in 3d space and a fixed point (x,y,z). Then the points within the distance r can be obtained by
p = sqrt((Coor(:,1)-x).^2 + (Coor(:,2)-y).^2 + (Coor(:,3)-z).^2)<r;
Coor_withindistance_r = Coor(p,:);
  댓글 수: 4
Wan Ji
Wan Ji 2021년 8월 18일
편집: Wan Ji 2021년 8월 18일
function [coor_num, neighbors_with_r] = Coordinates(X,Y,Z,Coor)
r = 1:10;
coor_num = zeros(length(r),1);
neighbors_with_r = cell(length(r),1);
for i = 1:1:length(r)
p = sqrt((Coor(:,1)-X).^2 + (Coor(:,2)-Y).^2 + (Coor(:,3)-Z).^2)<r(i);
Coor_withindistance_r = Coor(p,:);
coor_num(i) = size(Coor_withindistance_r, 1);
neighbors_with_r{i,1} = Coor_withindistance_r;
end
end
This may work, it returns the numbers of coordinates with different distance r (an array), and returns their coordinates. @sai sai

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

추가 답변 (1개)

Turlough Hughes
Turlough Hughes 2021년 8월 18일
편집: Turlough Hughes 2021년 8월 18일
The points which are within a radius, r, from the origin can be obtained as follows:
index = sum(X.^2,2) < r^2; % X is an n by 3 array of points
Xthresh = X(index,:);
Note, squaring r is more efficient than taking the square root for ALL of the points in X.
For a starting point other than the origin, e.g. p (1 by 3), points in X within a threshold radius r from the point p can be obtained as follows:
index = sum(X.^2 - p,2) < r^2;
Xthresh = X(index,:);

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by