Thread: problems with elastic collisions

  1. #1
    Registered User
    Join Date
    Nov 2012

    problems with elastic collisions

    I'm trying to replicate the movement of 2 masses, m1 and m2.

    m1 has a free fall movement and will collide with m2, which is attached to a string with constant k. i'm using the euler-cromer method to solve the dif equations. The important part of the code is the following:

      dt = tf/1000;
      for(i=0; tf > i*dt; ++i)
          v1 = v1 - g * dt;
          y1 = y1 + v1 * dt;
          v2 = v2 - (k/m2) * (y2-L0) * dt;
          y2 = y2 + v2 * dt;
    	  //elastic collision
              y1  =  y2 + fabs ( y1 - y2 );
         	  v1 = ((m1-m2) / (m1+m2)) * v1 + ((2*m2) / (m1+m2)) * v2; 
    	  v2 = ((2*m1) / (m1+m2)) * v1 + ((m2-m1) / (m1+m2)) * v2;    
          fprintf(f1, "%10lf   %10lf   %10lf\n", i*dt, y1, y2);  
    However, whenever m1 hits m2 they kind of stick together, being that y1 is always similar to y2, which is not at all the desired outcome. Any thoughts?

  2. #2
    Registered User
    Join Date
    Mar 2012
    the c - side
    ye cannae change the laws of physics Captain.

  3. #3
    Registered User
    Join Date
    Jun 2005
    I haven't bothered to read further, since you haven't given useful information about your problem (context, representative values of variables, etc) but you might want to ask whether this line does what you intend. I will bet it does not.
    If you want a more useful answer, you are better off providing a SMALL but COMPLETE sample of code that illustrates your problem. Also describe inputs and expected outputs.
    Last edited by grumpy; 12-14-2012 at 03:12 PM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL not recognizing collisions
    By bijan311 in forum C++ Programming
    Replies: 4
    Last Post: 05-28-2010, 06:54 PM
  2. Collisions does not take affect on the corners
    By bijan311 in forum C++ Programming
    Replies: 4
    Last Post: 05-21-2010, 08:34 PM
  3. clear collisions
    By Benzakhar in forum Game Programming
    Replies: 4
    Last Post: 01-10-2004, 06:22 AM
  4. Help with collisions.
    By Unregistered in forum Game Programming
    Replies: 2
    Last Post: 06-25-2002, 01:00 PM
  5. Collisions help(PLEASE!!! IT'S NOT HARD!!!)
    By SyntaxBubble in forum Windows Programming
    Replies: 5
    Last Post: 11-28-2001, 06:19 PM