Hello,
I am currently working on something where I have a large number of three dimensional points (8.9e7 points) expressed in a matrix like X=[x;y;z] where x, y, and z are row vectors containing the Cartesian coordinates of each point.
I need to search these points and pull out sets of points that fall on a given plane with a tolerance and store these points to a new matrix like X2=[x2;y2;z2] where x2, y2, and z2 are points from X that fall on the defined plane.
I have tried something like this:
n=8937*10000;
L=sqrt(n*pi());
k=1:n;
z=ones(size(k))-(2*k-ones(size(k)))./n;
phi=acos(z);
theta=L*phi;
x=sin(phi).*cos(theta);
y=sin(phi).*sin(theta);
rbody=1737; alt=50;
X=[x*rbody;y*rbody;z*rbody];
ns=[1,1,1];
planeloc=rbody^2/(alt+rbody);
X2=X(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001);
max(max(X2))
but it does not perform what I want. When I use the logical index
X(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001)
because the index returns values for each element of the matrix. Is there some way that I can use logical indices to select the columns of X that satisfy
(ns*(X-planeloc*ns'*ones(1,length(x)))>=-0.0001 & ns*(X-planeloc*ns'*ones(1,length(x)))<=0.0001)
without running a for loop (which would obviously take forever due to the huge number of points).
Thanks, Andrew