We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Particle repulsion on a toroidial surface
Page Index Toggle Pages: 1
Particle repulsion on a toroidial surface (Read 433 times)
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?
Re: Particle repulsion on a toroidial surface
Reply #1 - Feb 4th, 2010, 10:23am
 
When calculating the distance between 2 particles you need to consider the minimum distance between them. If you have 2 particles both near opposite edges then the minimum distance is the "wrap over edge" distance not "across the surface" distance your code appears to do the latter so when a particle crosses over then it suddenly has a large effect on the other particle.
Page Index Toggle Pages: 1