generating a matrix of coordinates without certain values
Show older comments
Hello,
I am building a code to generate a large number of points (80000) inside a sphere where the columns are the x,y,z coordinates, and they are randomly generated like so, using this function in a loop:
function [x,y,z] = generate_coordinate(R)
rng('shuffle');
phi = 2*pi*rand(1,1);
costheta = -1 + 2*rand(1,1);
u = rand(1,1);
theta = acos(costheta);
r = R * nthroot(u,3);
x = r * sin(theta) * cos(phi);
y = r * sin(theta) * sin(phi);
z = r * cos(theta);
end
Problem is I need the point to be at a minimum distance of dist_r_min (I check that by clustering in KDTree and using rangesearch if the points are in range).
So basically I want to know how is it possible to ask MATLAB to generate a point where this condition is applied? to pick a random point in this space yet not choosing a point that doesn't satisfy the condition?
For now I tried to solve this by generating the point again in a loop if it doesn't satisfy the condition, it takes too much time.
Edit: By points being at a minmum distance of dist_r_min, I meant from each other, point 1 and point 2 can't have their centers in a distance smaller than dist_r_min, not from the center of the sphere. Sorry for any confusion
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!