Graviquarium 09

attraction when SAME direction (not opposite)

What?

function collision(SquareNum){
   ......
   for (j=0; j<NumberOfSquares; j++){
      if(j!=SquareNum){
         ......
         if ( ( Math.abs(x1+w1/2-(x2+w2/2)) < hardshell * (w2+w1)/2 ) && ( Math.abs(y1+h1/2-(y2+h2/2)) < hardshell * (h2+h1)/2 ) )
         {
         ......
         }
         else {
             if ((gravX[SquareNum] == gravX[j]) && (gravY[SquareNum] == gravY[j])) {
                distanceSquare=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
                m1=mass[SquareNum]; m2=mass[j]; 
                attractiveForce=m1*m2*attraction/distanceSquare;
                distance=Math.sqrt(distanceSquare);
                xspeed[SquareNum]+= - attractiveForce/m1 * (x1-x2)/distance;
                yspeed[SquareNum]+= - attractiveForce/m1 * (y1-y2)/distance;
                xspeed[j] += - attractiveForce/m2 * (x2-x1)/distance;
                yspeed[j] += - attractiveForce/m2 * (y2-y1)/distance;
             }
         }
      }
   }
 
}

How?

repulsion when opposite 

What's next??

 
© 2003 AndreasKrueger.de (Impressum) letzte Änderung am: 03.09.2003 (AK v01)  http://www.AndreasKrueger.de/javascript