1
$\begingroup$

Hello I am trying to shift points which have been previously generated in the square area. I am having a trouble with some additional conditions how they should have been shifted.

xt=x(j)+2*rand()*shift - shift
yt=y(j)+2*rand()*shift - shift

Also I have more conditions to apply:

a) xt<0
b)xt>a
c)yt<0
d)yt>a
d) the distance (x(i)-xt)**2+(y(i)-yt)**2 <1 for i=1,2,...n; i/=j

where x(i) is a randomly generated number and shift is a parameter in the interval [0.1,1].x(j) is the randomly generated number again from the x(i) array. y(j) and y(i) is the same as x

I would like to know if the conditions are not being executed should I go back to the generating xt and yt positions or what would be other way to carry out with this problem?

$\endgroup$
  • $\begingroup$ Is this some sort of monte-carlo simulation? I don't really understand what you are trying to do. $\endgroup$ – Kbzon Jul 14 '15 at 14:12
1
$\begingroup$

In order to apply the last condition, I suggest you displace the points like so:

REAL, PARAMETER :: PI = 3.1415927
...
rt=shift*sqrt(rand())
tt=2.d0*PI*rand()
xt=x(j)+rt*cos(tt)
yt=y(j)+rt*sin(tt)

see here.

The easiest and quickest solution to constrain the new points to the interval $[0,a]^2$ is to impose some form of boundary condition. For example, periodic boundary conditions:

if(xt<0) xt=xt+a
else if(xt>a) xt=xt-a
same for yt...

Or you could reflect the points back across the boundary:

if(xt<0) xt=-xt
else if(xt>a) xt=2*a-xt
same for yt...
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.