Re: [Numpy-discussion] how to do scoring of random point to avoid overlapping in python

2013-10-18 Thread Hanno Klemm
On 18.10.2013 12:33, Pooja Gupta wrote:
 I have generated random point around a object and then evaluate each
 random point on certain criteria. But problem is that every time I am
 getting new point. How i can resolve this problem so that my result
 should be uniform. Is any way to evaluate the position of random
 point.
 
 for arang in range(1000): # generate 1000 random point around object
  arang = arang + 1
  x,y,z = 9.251, 24.410, 64.133 # coordinates of objects (i have 500
 object coordinates)
 
  x1,y1,z1 =
 (uniform(x-3.5,x+3.5),uniform(y-3.5,y+3.5),uniform(z-3.5,z+3.5))
 #randompoint
  pacord = [x1,y1,z1] #random point coordinates
  dist_pap = euDist(uacoord, pacord) # check distance between object
 and random points
 
  if (dist_pap  2.5): # if the random point far from obect
  dist_pap1 = dist_pap
 vecpw = euvector(uacoord, pacord) # generate vectors b/w objject and
 random point
 
 # angle between angle between object and random point
 num1 = np.dot (vect1, vecpw)
 denom1 = np.linalg.norm(vect1) * np.linalg.norm(vecpw)
 ang1 = rad2deg(np.arccos(num1/denom1))
 
 if 140  ang1 100: # check angle
  ang2= ang1
 print pacord
 
 Queries
 every time i am getting new result (new positions of the random
 point). How to fix it.
 on above basis I want to score each random point and the two random
 point should be 2.5 distance apart from each other. How I can avoid
 overlapping of the random points.
 

I am not sure if i understand the question correctly but if you always 
want to get the same random number, every time you run the script, you 
can fix the random seed by using np.random.seed(). Regarding your second 
question, when I understand correctly, you somehow want to find two 
points that have a distance of 2.5. If you already have one of them, I 
would generate the second one using spherical coordinates and specifying 
the distance a priori. something like:

def pt2(pt1, distance=2.5):
 theta = np.random.rand()*np.pi
 phi = np.random.rand()*2*np.pi
 r = distance
 x = r*np.sin(theta)*np.cos(phi)
 y = r*np.sin(theta)*np.sin(phi)
 z = r*np.cos(theta)
 return pt1 + np.array((x,y,z))


In [367]: pt1 = np.array([0,0,0])

In [368]: pt2(pt1)
Out[368]: a = array([-2.29954368, -0.57223342,  0.79664785])

In [369]: np.linalg.norm(a)
Out[369]: 2.5

Hope this helps,
Hanno

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] how to do scoring of random point to avoid overlapping in python

2013-10-18 Thread Pooja Gupta
Thanks Hanno
I got some idea.
How about the bin(grid)??



On Fri, Oct 18, 2013 at 8:21 PM, Hanno Klemm kl...@phys.ethz.ch wrote:

 On 18.10.2013 12:33, Pooja Gupta wrote:
  I have generated random point around a object and then evaluate each
  random point on certain criteria. But problem is that every time I am
  getting new point. How i can resolve this problem so that my result
  should be uniform. Is any way to evaluate the position of random
  point.
 
  for arang in range(1000): # generate 1000 random point around object
   arang = arang + 1
   x,y,z = 9.251, 24.410, 64.133 # coordinates of objects (i have 500
  object coordinates)
 
   x1,y1,z1 =
  (uniform(x-3.5,x+3.5),uniform(y-3.5,y+3.5),uniform(z-3.5,z+3.5))
  #randompoint
   pacord = [x1,y1,z1] #random point coordinates
   dist_pap = euDist(uacoord, pacord) # check distance between object
  and random points
 
   if (dist_pap  2.5): # if the random point far from obect
   dist_pap1 = dist_pap
  vecpw = euvector(uacoord, pacord) # generate vectors b/w objject and
  random point
 
  # angle between angle between object and random point
  num1 = np.dot (vect1, vecpw)
  denom1 = np.linalg.norm(vect1) * np.linalg.norm(vecpw)
  ang1 = rad2deg(np.arccos(num1/denom1))
 
  if 140  ang1 100: # check angle
   ang2= ang1
  print pacord
 
  Queries
  every time i am getting new result (new positions of the random
  point). How to fix it.
  on above basis I want to score each random point and the two random
  point should be 2.5 distance apart from each other. How I can avoid
  overlapping of the random points.
 

 I am not sure if i understand the question correctly but if you always
 want to get the same random number, every time you run the script, you
 can fix the random seed by using np.random.seed(). Regarding your second
 question, when I understand correctly, you somehow want to find two
 points that have a distance of 2.5. If you already have one of them, I
 would generate the second one using spherical coordinates and specifying
 the distance a priori. something like:

 def pt2(pt1, distance=2.5):
  theta = np.random.rand()*np.pi
  phi = np.random.rand()*2*np.pi
  r = distance
  x = r*np.sin(theta)*np.cos(phi)
  y = r*np.sin(theta)*np.sin(phi)
  z = r*np.cos(theta)
  return pt1 + np.array((x,y,z))


 In [367]: pt1 = np.array([0,0,0])

 In [368]: pt2(pt1)
 Out[368]: a = array([-2.29954368, -0.57223342,  0.79664785])

 In [369]: np.linalg.norm(a)
 Out[369]: 2.5

 Hope this helps,
 Hanno

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion




-- 
पूजा गुप्ता, पीएचडी
राष्ट्रीय कोशिका विज्ञान केंद्र

जीवन को खुल कर मुस्कुराने दो, खोल दो बाहे अवसर आने दो ।
पग बढाओ हर पथ तुम्हारा है, पथ कंटक मंजिलो का इशारा है।।
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion