scatter random points on a circle with a minimum distance and some constraints added

4 views (last 30 days)
Hi Matlab users,
Following my previous question:
Now I want to add a new feature to the code. After finding the selected set of points using the code above, I want to randomly choose one of the points and move it in a random direction on the big circle. Lets name the distance that I want to move "d". "d" should not be bigger than 0.005*R. so I guess it can be "d = rand*(0.005*R);"
Also again, this little move should not make the point to be closer than 0.005*R to any other point on the circle, and also should not go out of the circle. I would highly appreciate if you could guide me to fix it.
Best,
Argu

Answers (1)

Image Analyst
Image Analyst on 4 Apr 2019
  4 Comments
Argumanh
Argumanh on 4 Apr 2019
Edited: Argumanh on 4 Apr 2019
Yes I mean within the cirlce. So this is the condition I am trying to code:
so after the code give us 70 random points in the cirlce of radius 70 with minimum distance required of 5, I choose one random point(I call it MP) then I define x1,y1 for the new one. then I choose the selected point to move 150 in a random direction.
% Now we choose a random point and move it:(it is the "PM" indice)
PM = randi(70);
x1 = x;
y1 = y;
for K = 1 : 100 * P % P=70 number of points in the cirlce
d = (150); % I want it to move 150 steps
theta = rand()*(360);
x1(PM) = x(PM) + d*cos(theta); % New x-coordinate
y1(PM) = y(PM) + d*sin(theta); % New y-coordinate
% Then I enforce two conditions
% 1)Distance of the new point must be less than 5:
for i=1:P
ResDistances(i) = sqrt((x1(i)-x1(PM)) .^ 2 + (y1(i) - y1(PM)) .^ 2);
if ResDistances(i)>0 && ResDistances(i)<= 5
break;
end
end
% 2)The new point must be inside the circle: (R=70)
if sqrt((x1(PM)).^2 + (y1(PM)).^2) <= R
break;
end
end
However this is not working, any help with that is much appreciated.
Best,
Argu

Sign in to comment.

Categories

Find more on Performance and Memory in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!