I am new to Monte Carlo integration and have been tasked with using MC integration in order to calculate the volume of a torus with inner radius 5cm and outer radius 10cm. Below is the code I have used to plot a 3d torus, however what I need to do now is plot an array of random 3d points within the figure window and determine how many lie within the volume of the torus in order to calculate its approximate volume.
Below is the code I have written so far:
def plot_torus(N, c, a):
U = np.linspace(0, 2*np.pi, N)
V = np.linspace(0, 2*np.pi, N)
U, V = np.meshgrid(U, V)
X = (c+a*np.cos(V))*np.cos(U)
Y = (c+a*np.cos(V))*np.sin(U)
Z = a*np.sin(V)
return X, Y, Z
x, y, z = plot_torus(100, 10, 2.5)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_surface(x, y, z, antialiased=True, color='pink')
ax.set_xlabel('$x$', fontsize=14)
ax.set_ylabel('$y$', fontsize=14)
ax.set_zlabel('$z$', fontsize=14)
ax.set_xlim(-10, 10)
ax.set_ylim(-10, 10)
ax.set_zlim(-10, 10)
plt.show()
I have been able to do this for a simpler 2d plot with only 2 variables to worry about, but now I am not so sure as to how to plot these 3d points and how to count them. Can anyone point me in the right direction as to how to plot these random points? Any help would be highly appreciated!