mardi 31 juillet 2018

Generate random point positons on a torus

I'm working on a code to simulate propagation of particles on a torus surface. Initially, particles are gather on a "local" space, as shown on the following pic :

Initial particles on torus

Blue points are initial particles. The problem is, when I zoom in, particles don't seem to be spread randomly :

Zoom in

First, I see they form like raws. Moreover, I'm working with N = 5 particles, but there seems to be 25 particles here (5 raws of 5). I suppose it comes from meshgrid() since 25 = 5^2, but I don't really understand how this function works to be honest.

Here is my code :

Creating the red torus :

angle = np.linspace(0, 2*np.pi, 32)
theta, phi = np.meshgrid(angle, angle)
X = (R + r * np.cos(phi)) * np.cos(theta)
Y = (R + r * np.cos(phi)) * np.sin(theta)  
Z = r * np.sin(phi)

Placing initial points :

thetaInit = ((np.random.rand(N)-0.5)*np.pi/16)
phiInit = ((np.random.rand(N)-0.5)*np.pi/32)
theta2, phi2 = np.meshgrid(phiInit, thetaInit)
Xinit = (R + r * np.cos(phi2)) * np.cos(theta2)
Yinit = (R + r * np.cos(phi2)) * np.sin(theta2) 
Zinit = r *  np.sin(phi2)

Where N is the number of particles, and r, R are respectively minor and major radius of the torus.




Aucun commentaire:

Enregistrer un commentaire