Nathan Nifong
YaBB Newbies
Offline
Posts: 2
Particle repulsion on a toroidial surface
Feb 4th , 2010, 9:46am
I want to simulate a set of particles on a toroidal surface (a donut) this so far it looks like the asteroids game, where if something goes off of one side, it reappears on the other. the particle class has a translate method that takes care of moving the particle and if it goes off of the edge, moving to the other side. so far this works. here is a simplified version of the particle class class Particle{ public float X,Y; public translate(float dx,float dy){ X += dx; Y += dy; if (X < 0){ X = width; } else if (X > width){ X = 0; } if (Y < 0){ Y = height; } else if (Y > height){ Y = 0; } } } Now I want to make all the particles mutually repulsive. I use a double for loop inside draw and calculate the net displacement of each particle, then I displace them all with that translate function like this. float dx,dy,dis,rad,ax,ay; for(int i=0; i<numCells; i++){ mimi[i].sx = 0; mimi[i].sy = 0; for(int j=0; j<numCells; j++){ if (i!=j){ dx = mimi[j].X - mimi[i].X; dy = mimi[j].Y - mimi[i].Y; dis = sqrt(sq(dx)+sq(dy)); rad = atan(dy/dx); ax = (1/dis)*cos(rad); ay = (1/dis)*sin(rad); if (dx > 0) ax *= -1; mimi[i].sx += ax*repulsiveForce; mimi[i].sy += ay*repulsiveForce; } } mimi[i].trans(mdx+mimi[i].sx, mdy+mimi[i].sy); mimi[i].draw(); } Since a torus is a closed surface, they should reach an equilibrium (especially with damping to help) but instead they are pushed to the edges are constantly popping between sides. each pop sends a shock wave through the particles and they never stabilize very well and require way too much damping. Is there some other way I should be calculating the net displacement of each particle, so that equilibrium is reached? I want it to seem like a perfect torus from the particles perspective, without any simulation artifacts. in other words, How the hell does Graviroids work?