Skip to content

Instantly share code, notes, and snippets.

Last active January 28, 2019 23:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JoshVarty/3df65dddf5238faf26cab4b981c3b166 to your computer and use it in GitHub Desktop.
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):
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 ``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment