random points

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
Thanks
My program is:
clear all
x = zeros(10,1);
y = zeros(10,1);
x(1,1)= 10*rand;
y(1,1)= 10*rand;
radius = 0.5;
m=1;
n=0;
for i=1:10
n=n+1;
for k=1:2
m=m+1;
theta = rand*2*pi;
x(m,1) = x(n,1) + radius*cos(theta);
y(m,1) = y(n,1) + radius*sin(theta);
end
end
plot(x,y,'.');
hold on
axis equal;

2 Commenti

Jan
Jan il 27 Feb 2011
What does "until area is filled" mean? If you speak of random DOUBLE variables, you need > 2^53 iterations. There I assume, you want something, which is not explained in your question.
niko kauppinen
niko kauppinen il 27 Feb 2011
My area is 10x10 in this case
And I would like to generate circles at each point and check does their circumference line overlap with "box" or other circles
Thanks

Accedi per commentare.

Risposte (2)

bym
bym il 27 Feb 2011

0 voti

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
clc;clear;close all
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

4 Commenti

niko kauppinen
niko kauppinen il 27 Feb 2011
Thanks for the answer,
if you run my program step by step you understand
but I want to know how i check after each loop that my value is not same as before generated?
Thanks
Jan
Jan il 27 Feb 2011
The chance to get two equal random DOUBLE numbers is very very tiny. If you really need to be sure, that the values are distinct, create a single random vector at first and check the values with UNIQUE.
niko kauppinen
niko kauppinen il 27 Feb 2011
I would like to generate circles at each point and check does their circumference line overlap with other circles.
Thanks
bym
bym il 27 Feb 2011
That is clearer, thanks, you might want to have a look at voronoi(x,y)

Accedi per commentare.

Walter Roberson
Walter Roberson il 27 Feb 2011

0 voti

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.

6 Commenti

niko kauppinen
niko kauppinen il 28 Feb 2011
r= distance from previous point, not a radius of circle.
I have 10x10 max for x and y and first point is randomly generated.
How I can check if my circles overlap with the previously generated circles.
You are right I don't have circles yet, but I would like to know how I check if I have generated circles in my points?
I am thinking something like this:
x1-x2=X,y1-y2=Y
radius of circle R
sgrt(X^2+Y^2)-R1-R2 to get distance R1=radius of other circle R2=radius other circle
Then I get distance between circles if that more than 0 there is no overlap.
How I can check like this to each point I have generated previously?
Thanks
niko kauppinen
niko kauppinen il 28 Feb 2011
How I can include image or drawing of my question?
Paulo Silva
Paulo Silva il 28 Feb 2011
http://www.mathworks.com/matlabcentral/answers/help/markup
niko kauppinen
niko kauppinen il 28 Feb 2011
where i can save my drawing?
do I need to have own web page?
Oleg Komarov
Oleg Komarov il 28 Feb 2011
upload it on tinypic and paste the link as <<http://....>>
Walter Roberson
Walter Roberson il 28 Feb 2011
To do the check on each point that you have generated previously, vectorize the calculation.
You will need to generate an infinite number of circles of varying radii to fill the 10 x 10 area, under the usual definition of "fill".
Would I be correct in my suspicion that you intend to use a truncated power law distribution for your circle radii? If so, then you will not be able to do that and "fill" the area -- not unless you define quite different stopping criteria for the area being "filled". I have previously written a proof that a truncated power law cannot hold in a bounded area unless the circles are permitted to extend beyond the boundaries.

Accedi per commentare.

Categorie

Richiesto:

il 26 Feb 2011

Community Treasure Hunt

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

Start Hunting!

Translated by