Last active
January 28, 2019 23:33
-
-
Save JoshVarty/3df65dddf5238faf26cab4b981c3b166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def createNonOverlappingPoints(numElements): | |
x = np.zeros((numElements)) + 2 #Place the cirlces offscreen | |
y = np.zeros((numElements)) + 2 #Place the circles offscreen | |
for i in range(0, numElements): | |
foundNewCircle = False | |
#Loop until we find a non-overlapping position for our new circle | |
while not foundNewCircle: | |
randX = random.uniform(-1, 1) | |
randY = random.uniform(-1, 1) | |
distanceFromOtherCircles = np.sqrt(np.square(x - randX) + np.square(y - randY)) | |
# Ensure that this circle is far enough away from all others | |
if np.all(distanceFromOtherCircles > 0.2): | |
break | |
x[i] = randX | |
y[i] = randY | |
return x, y | |
x, y = createNonOverlappingPoints(10) | |
plt.scatter(x,y, s=200) | |
plt.axes().set_aspect('equal', 'datalim') # before `plt.show()` | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment