To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
I want to generate points around area without overlaps. Every point generated i want to generate 2 new ones with random angle and continue until area is filled.
I don't know how to check previously generated points and see is there any overlap
My program is:
x = zeros(10,1);
y = zeros(10,1);
radius = 0.5;
theta = rand*2*pi;
x(m,1) = x(n,1) + radius*cos(theta);
y(m,1) = y(n,1) + radius*sin(theta);
No products are associated with this question.
I would be less concerned about checking overlap. I don't know what you are trying to do, but perhaps this may be of some help
s = rand(10000,2).*.5; s = [s,bsxfun(@hypot,s(:,1),s(:,2))];
in = s(s(:,3)<.5,1:2); out = s(s(:,3)>=.5,1:2);
plot(in(:,1),in(:,2),'g.') hold plot(out(:,1),out(:,2),'r.') axis square
In your original problem statement, you said that you wanted to continue until the area was filled. The code outline you presented had no area boundaries, and thus unless you put a maximum on the number of points, will continue onward towards +/- infinity in the X and Y direction until you run out of memory.
Each circle you generate with have an area of pi*r^2 . Your r is 1/2, so the area will be pi/4 . Given any fixed x and y boundaries (rectangular), the available area will be
(max(x) - min(x)) * (max(y) - min(y))
If the bounds are the same length, say L, then the area would be L^2. You could only fill up the area if L^2 = N * pi/4 where N is the number of circles placed. The number of circles needed would thus be (2*L)^2/pi . This will not be an integer unless L is exactly divisible by sqrt(pi)/2. However, pi is an irrational number and so its square root must be irrational as well. No irrational number is exactly representable in IEEE 754 binary floating point, so it is not possible to fill any area with fixed-radius circles in Matlab (or any computer system with finite precision in any fixed or mixed integer base).
Your problem is thus not possible to solve in the form stated.