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:
Code:
dt = tf/1000;
for(i=0; tf > i*dt; ++i)
{
//corpo1
v1 = v1 - g * dt;
y1 = y1 + v1 * dt;
//corpo2
v2 = v2 - (k/m2) * (y2-L0) * dt;
y2 = y2 + v2 * dt;
if(fabs(y1<y2))
{
//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?