Magic commands:
In [ ]:
%matplotlib notebook
Draw background:
In [ ]:
import numpy as np
import numpy.linalg as la
import matplotlib.pyplot as plt
from matplotlib.patches import Arc
alpha = 60.
alp = alpha * np.pi/180.
x0 = np.sin(alp)
y0 = np.cos(alp)
fig = plt.figure(1)
ax = fig.gca()
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_xlim(-1.25, 1.25)
ax.set_ylim(-1.25, 1.25)
ax.set_aspect('equal')
ax.scatter(-x0, -y0)
ax.scatter(x0, -y0)
ax.plot([-x0, x0], [-y0, -y0])
Find (x_data, y_data)
so that alpha_data
is equal to alpha
:
In [ ]:
def onclick(event):
delta = 5 * np.pi/180.
x_data = event.xdata
y_data = event.ydata
r_data = np.sqrt(x_data**2+y_data**2)
phi_data = np.arctan2(y_data, x_data)
alp_data = (x_data+x0)*(x_data-x0) + (y_data+y0)**2
alp_data /= np.sqrt((x_data+x0)**2+(y_data+y0)**2)
alp_data /= np.sqrt((x_data-x0)**2+(y_data+y0)**2)
alp_data = np.arccos(alp_data)
print 'alpha = {}'.format(alp_data*180./np.pi)
if alp_data > alp-delta and alp_data < alp+delta:
plt.scatter(x_data, y_data, c='g')
x = [-x0, x_data]
y = [-y0, y_data]
plt.plot(x, y, 'g')
x = [x0, x_data]
y = [-y0, y_data]
plt.plot(x, y, 'g')
cid = fig.canvas.mpl_connect('button_press_event', onclick)
Solution:
In [ ]:
ax.scatter(0., 0.)
x = [-x0, 0.]
y = [-y0, 0.]
ax.plot(x, y, 'b')
x = [x0, 0.]
y = [-y0, 0.]
ax.plot(x, y, 'b')
arc = Arc((0., 0.), 2., 2., 0., alpha-90., 270.-alpha, color='k', fill=False)
ax.add_artist(arc)
Comments:
In [ ]: