Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to define the point pseudo randomly you can use <a href="http://docs.python.org/2/library/random.html" rel="nofollow noreferrer">random.randrange</a>.</p> <pre><code>from random import randrange as rd from math import sqrt ptBlu=[11,12,13] #example of blu point ptRedx=ptBlu[0]+rd(-10,10,1) #x coordinate of a red point(rd is the function stand for random.randrange) ptRedy=ptBlu[1]+rd(-10,10,1) #y coordinate of a red point ptRedz=ptBlu[2]+rd(-10,10,1) #z coordinate of a red point ptRed=[ptRedx,ptRedy,ptRedz] #list with the x,y,z coordinates </code></pre> <p>If you want to create a series of points with a distance greater than a certain one from a certain point avoiding to create points with the same coordinates. You have to do something more elaborate. This is the example for a 2D plane as your draw. For a 3D example simply add the third coordinate and adjust the formulae.</p> <pre><code>redptlist=[] #inizialize a void lists for red point coordinates xredptlist=[] yredptlist=[] pointcounter=0 #initizlize counter for the while loop mindist=2.5#set the minimum euclidean distance beyond you want to create the points maxdist=12#set the maximum euclidean distance redpoint can have from blu point maxc=int(sqrt((maxdist**2)/2)) #from the euclidean distance formula you can get the max coordinate while True: #create a potentailly infinite loop! pay attention! if pointcounter&lt;20: #set the number of point you want to add (in this case 20) x_RedPtshift=rd(-maxc,maxc,1) #x shift of a red point y_RedPtshift=rd(-maxc,maxc,1) #y shift of a red point if sqrt(x_RedPtshift**2+y_RedPtshift**2)&gt;mindist: #if the point create go beyond the minimum distance ptRedx=ptBlu[0]+ x_RedPtshift#x coordinate of a red point ptRedy=ptBlu[1]+ y_RedPtshift #y coordinate of a red point ptRed=[ptRedx,ptRedy] #list with the x,y,z coordinates if ptRed not in redptlist: #avoid to create red point with the same coordinates redptlist.append(ptRed) # add to a list with this notation [x1,y1],[x2,y2] xredptlist.append(ptRedx) # add to a list with this notation [x1,x2,x3...] for plotting yredptlist.append(ptRedy) # add to a list with this notation [y1,y2,y3...] for plotting pointcounter+=1 #add one to the counter of how many points you have in your list else: #when pointcounter reach the number of points you want the while cicle ends break </code></pre> <p>Try to test it with <a href="/questions/tagged/matplotlib" class="post-tag" title="show questions tagged &#39;matplotlib&#39;" rel="tag">matplotlib</a>:</p> <pre><code>import matplotlib.pyplot as plt plt.plot(ptBlu[0],ptBlu[1],'bo')#plot blu point plt.plot(xredptlist, yredptlist, 'ro')#plot red points minCircle=plt.Circle((ptBlu[0],ptBlu[1],1),mindist,color='b',fill=False)#draw circle with min distance maxCircle=plt.Circle((ptBlu[0],ptBlu[1],1),maxdist,color='r',fill=False) fig = plt.gcf() fig.gca().add_artist(minCircle) fig.gca().add_artist(maxCircle) plt.axis([-3, 25, -1, 25]) plt.axes().set_aspect('equal', 'box') plt.grid(True) plt.show() </code></pre> <p>Here is the result: <img src="https://i.stack.imgur.com/c7Hzn.png" alt="plotting result"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload