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 & HelpOther Libraries › Vector3D and collision detection
Page Index Toggle Pages: 1
Vector3D and collision detection (Read 279 times)
Vector3D and collision detection
Jan 15th, 2009, 2:23pm
 
HI all,
I am absolutely new to Processing but it hooked me so much i can't stop thinking how to draw things ;-D.
Recently i started playing with the (excellent) Vector3D library (i know there is PVector) but the question i'm going to ask you is:
How do i make two balls with a constant gravitational pull among each other stop attracting so that the edges of the balls are tangent to each other?
This is my first attempt:
http://www.openprocessing.org/visuals/?visualID=802
simply swapping the velocities vectors do the effect but the particles (balls, whatever) keep attracting them to the center.

This is my test to see if the distance between the balls is more than the sum of the two radii. If so, apply grafforce.
else, swap the veloc. vectors.

But i can't go further; could you please help me on this?
Already tried the Hacks section but could't find anything more than i already discovered.

this is the collision code:

if(Vector3D.distance(p[i].l, p[j].l) >= p[i].getRadius()+p[j].getRadius()){
             Vector3D f = p[i].calcGravForce(p[j], 0.8f);  
             p[i].add_force(f);      
           }
           
           else
           //if impact  
           {  
         
             // swap vectors
             Vector3D vi = new Vector3D();  
             Vector3D vj = new Vector3D();  
               
             vi = p[i].v;  
             vj = p[j].v;  
     
             p[i].v = vj;  
             p[j].v = vi;  
}
Page Index Toggle Pages: 1