In [52]:
from random import random
import numpy as np
import numpy.linalg as linalg
import scipy.spatial.distance as distance
def get_random_point_on_circle(radius=1., center=[0., 0.], constraint_circle_radius=18., constraint_circle_center=[0., 0.]):
angle = random() * np.pi * 2
xr, yr = (np.cos(angle) * radius + center[0], np.sin(angle) * radius + center[1])
if constraint_circle_radius is not None:
while distance.euclidean((xr, yr), tuple(constraint_circle_center)) > constraint_circle_radius:
angle = random() * np.pi * 2
xr, yr = (np.cos(angle) * radius + center[0], np.sin(angle) * radius + center[1])
return xr, yr, angle
In [79]:
import matplotlib.pyplot as plt
points = [get_random_point_on_circle(radius=20, center=[5, -7])[0:2] for _ in range(100)]
xs, ys = np.transpose(points)
plt.scatter(xs, ys)
plt.show()
print(points[0:10])
In [80]:
accepted = [(-13.251246367295806, 1.1787533304453888), (-7.7222205888245874, 8.431950728578931), (0.87374547197568475, 12.569722112742397), (-14.720895407423896, -3.6703927664892539), (12.825414533708608, 11.405512418175761)]
xs, ys = np.transpose(accepted)
plt.scatter(xs, ys)
plt.show()
print(points[0:5])
In [54]:
accepted = [(-13.251246367295806, 1.1787533304453888), (-7.7222205888245874, 8.431950728578931), (-0.93943111587261185, 12.097726514425851), (-14.720895407423896, -3.6703927664892539), (12.825414533708608, 11.405512418175761)]
xs, ys = np.transpose(accepted)
orient_ps = [get_random_point_on_circle(radius=1., center=[x, y], constraint_circle_radius=None) for x, y in accepted]
plt.scatter(xs, ys)
plt.scatter(*np.transpose(orient_ps)[0:2], c='r')
plt.show()
print(points[0:5])
In [59]:
print(np.transpose(orient_ps)[2])
In [82]:
accepted = [(-13.251246367295806, 1.1787533304453888), (-7.7222205888245874, 8.431950728578931), (0.87374547197568475, 12.569722112742397), (-14.720895407423896, -3.6703927664892539), (12.825414533708608, 11.405512418175761)]
xs, ys = np.transpose(accepted)
ax = plt.subplot()
ax.scatter(xs, ys)
ax.scatter(*np.transpose(orient_ps)[0:2], c='r')
ax.scatter([5], [-7], c='k')
import pylab #Imports matplotlib and a host of other useful modules
cir1 = pylab.Circle((0,0), radius=18, alpha=.2, fc='y') #Creates a patch that looks like a circle (fc= face color)
cir2 = pylab.Circle((5,-7), radius=20, alpha =.2, fc='b') #Repeat (alpha=.2 means make it very translucent)
ax.add_patch(cir1) #Grab the current axes, add the patch to it
ax.add_patch(cir2) #Repeat
ax.set_xlim(-20, 20)
ax.set_ylim(-20, 20)
ax.set_aspect('equal')
ax.axhline(y=0, color='k')
ax.axvline(x=0, color='k')
plt.show()
In [ ]: