import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['text.usetex'] = True
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.size'] = 12
# Set up the figure and axes
fig, ax = plt.subplots(figsize=(7, 5))
ax.set_aspect('equal', adjustable='box')
ax.set_xlim(-1, 5)
ax.set_ylim(-1, 5)
ax.axis('off')
# Define points
A = np.array([0, 0])
B = np.array([4, 0])
e_minus1 = np.array([3.5, 3.5])
e_minus2 = np.array([-0.2, 2.8])
S = np.array([2, 0])
# Draw particles and labels
ax.plot(A[0], A[1], 'o', color='red', markersize=15, zorder=1)
ax.text(A[0] - 0.2, A[1] + 0.2, 'A', ha='right', va='bottom', fontsize=12)
#ax.text(A[0] - 0.2, A[1] - 0.2, '$e^+$', ha='right', va='top', fontsize=12)
ax.plot(B[0], B[1], 'o', color='red', markersize=15, zorder=1)
ax.text(B[0] + 0.2, B[1] + 0.2, 'B', ha='left', va='bottom', fontsize=12)
#ax.text(B[0] + 0.2, B[1] - 0.3, '$e^+$', ha='left', va='top', fontsize=12)
ax.plot(e_minus1[0], e_minus1[1], 'o', color='green', markersize=10, zorder=1)
ax.text(e_minus1[0] + 0.2, e_minus1[1]+0.2, '$e^{-}_1$', ha='left', va='center', fontsize=12)
ax.plot(e_minus2[0], e_minus2[1], 'o', color='green', markersize=10, zorder=1)
ax.text(e_minus2[0] - 0.1, e_minus2[1]+0.3, '$e^{-}_2$', ha='left', va='center', fontsize=12)
ax.plot(S[0], S[1], 'x', color='black', markersize=10, zorder=2)
ax.text(S[0], S[1] - 0.2, 'O', ha='center', va='top', fontsize=12)
# Draw lines and arrows
#ax.plot([A[0], B[0]], [A[1], B[1]], 'k-', zorder=1)
#ax.plot([A[0], e_minus1[0]], [A[1], e_minus1[1]], 'k-', zorder=1)
#ax.plot([B[0], e_minus1[0]], [B[1], e_minus1[1]], 'k-', zorder=1)
#ax.plot([A[0], e_minus2[0]], [A[1], e_minus2[1]], 'k-', zorder=1)
#ax.plot([B[0], e_minus2[0]], [B[1], e_minus2[1]], 'k-', zorder=1)
#ax.plot([S[0], e_minus1[0]], [S[1], e_minus1[1]], 'k-', zorder=1)
#ax.plot([B[0], B[0]], [B[1], e_minus1[1]], 'k', linestyle=':', zorder=1)
# Annotate vectors with arrows and text
# R_A vector
ax.annotate('', xy=(S[0], S[1]), xytext=(A[0], A[1]),
arrowprops={'arrowstyle': '<-', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=3)
ax.text(1, -0.2, r'$\vec{R}_A$', ha='center', va='top', fontsize=12)
# R_B vector
ax.annotate('', xy=(B[0], B[1]), xytext=(S[0], S[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=3)
ax.text(3, -0.2, r'$\vec{R}_B$', ha='center', va='top', fontsize=12)
# R vector
ax.annotate('', xy=(A[0], A[1] - 0.7), xytext=(B[0], B[1] - 0.7),
arrowprops={'arrowstyle': '<->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(2, -0.9, r'$\vec{R}$', ha='center', va='top', fontsize=12)
# r_A1 vector
ax.annotate('', xy=(e_minus1[0], e_minus1[1]), xytext=(A[0], A[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(2.1, 2.4, r'$\vec{r}_{A1}$', ha='center', va='bottom', fontsize=12)
# r_B1 vector
ax.annotate('', xy=(e_minus1[0], e_minus1[1]), xytext=(B[0], B[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(4, 1.7, r'$\vec{r}_{B1}$', ha='center', va='bottom', fontsize=12)
# r_A2 vector
ax.annotate('', xy=(e_minus2[0], e_minus2[1]), xytext=(A[0], A[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(-0.4, 1.7, r'$\vec{r}_{A2}$', ha='center', va='bottom', fontsize=12)
# r_B2 vector
ax.annotate('', xy=(e_minus2[0], e_minus2[1]), xytext=(B[0], B[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(0.9, 2.3, r'$\vec{r}_{B2}$', ha='center', va='bottom', fontsize=12)
# r12 vector
ax.annotate('', xy=(e_minus2[0], e_minus2[1]), xytext=(e_minus1[0], e_minus1[1]),
arrowprops={'arrowstyle': '->', 'lw': 1.5, 'color': 'black', 'shrinkA': 0, 'shrinkB': 0}, zorder=1)
ax.text(1.8, 3.3, r'$\vec{r}_{12}$', ha='center', va='bottom', fontsize=12)
# Show the plot
plt.show()