vendredi 23 octobre 2020

Save coordinates of multiples circles in array Python

I have a algorithm that generates random points inside a circumference of radius "r=30", next it checks if the points are inside a box of size 100x100, if they are inside the algorithm gives me the coordinates of that points.


from matplotlib import pyplot as plt
import numpy as np



for i in range(0,5,5):
    #Generate random coordinates for the center of the circumference 
    xr=100*np.random.uniform(0,1)
    yr=100*np.random.uniform(0,1)
    
    #Check if the circle is inside the box
    if 30.<xr<70. and 30.<yr<70.:
        phi = np.random.uniform(0, 2*np.pi, 1000)
        x = xr+30* np.cos(phi)
        y = yr+30 * np.sin(phi)
        #If the circle is not in the box give me another coordinates for the 
        #center
    else:
        xr=100*np.random.uniform(0,1)
        yr=100*np.random.uniform(0,1)
    

        
#Plot of 1 circle
plt.scatter(x, y, s = 4)
plt.show()

I want to calculate the coordinates of 20 circles, however I don't know how to save the coordinates of the every circle without deleting the previous information.

After of having the 20 circumferences I want to put them in the same plot.




Aucun commentaire:

Enregistrer un commentaire