Skip to content

Instantly share code, notes, and snippets.

@JoshVarty

JoshVarty/counting_0.py

Last active Jan 28, 2019
Embed
What would you like to do?
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
You can’t perform that action at this time.