- #1
mikejm
- 40
- 2
Let's say you have two masses on either side of a spring. Mass 1 is connected to the end of a spring. The spring itself has no mass. Mass 2 is free in space. So you have:
So it's more descriptive, I'll name the variables like you might in programming. Let's define each element as follows.
Mass 1:
Mass 2:
Time:
At the initial state, mass 2 is already in contact with the end of the spring (or is just about to contact it) with a given momentum. Mass 1 is traveling with a given momentum as well. The spring has a given amount of initial compression (which could be zero or non-zero).
How do you calculate the final positions and velocities after a certain increment of time (deltaT) for all the elements?
I'm trying to simulate a collision in a program I'm writing just for fun but stuck on this. If it's easier to give the spring some mass that's fine too. Whatever works. Thanks a bunch.
Code:
[M1]-[spring] [M2]
Mass 1:
- m1Mass = mass of M1
- m1PosInit = initial position of M1
- m1PosFinal = final position of M1
- m1VelInit = initial velocity of M1
- m1VelFinal = final velocity of M1
Mass 2:
- m2Mass = mass of M2
- m2PosInit = initial position of M2
- m2PosFinal = final position of M2
- m2VelInit = initial velocity of M2
- m2VelFinal = final velocity of M2
- springLengthAtRest = natural length of spring when not compressed at rest
- springLengthInit = initial length of spring
- springLengthFinal = final length of spring
- springCompressionInit = springLengthAtRest - springLengthInit
- springCompressionFinal = springLengthAtRest - springLengthFinal
- springForce = force of the nonlinear spring based on spring compression (eg. from a simple equation like F(x) = -k x^{c})
Time:
- deltaT = amount of time that passes from initial state to final state
At the initial state, mass 2 is already in contact with the end of the spring (or is just about to contact it) with a given momentum. Mass 1 is traveling with a given momentum as well. The spring has a given amount of initial compression (which could be zero or non-zero).
How do you calculate the final positions and velocities after a certain increment of time (deltaT) for all the elements?
I'm trying to simulate a collision in a program I'm writing just for fun but stuck on this. If it's easier to give the spring some mass that's fine too. Whatever works. Thanks a bunch.
Last edited: